module inheritance example?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

module inheritance example?

jomclaughlin
Does anyone have a good example of a module inheriting from another module? A limited google on my part didn't turn up anything good, making me think it might not be considered good practice. I saw a couple of examples passing extra functions to the module function, but the manual is extremely thin on this matter. It seems that these functions accept the module table as a param, and then can add and remove table entries before it is returned by require. Another option would be to set the metatable of the derived module to a table with __index pointing to the base module. Any advice on why one would be chosen over the other?

Thanks,
Jim
Reply | Threaded
Open this post in threaded view
|

Re: module inheritance example?

Timm S. Mueller
On Mon, 22 Mar 2010 16:38:49 -0500
James McLaughlin <[hidden email]> wrote:

> Does anyone have a good example of a module inheriting from another module?

What turned out advantageous for me was to distinguish between new()
and newClass(), and to use the super class as a second argument to the
module function. This made it a fool-proof workhorse even for large and
complex class libraries, at least for my needs.

You can check out my approach at http://tekui.teklib.org/ . The base
class is tek/class.lua - see also
http://hg.teklib.org/tekui/file/a5823c144f8f/tek/class.lua#l .
Documentation is here: http://tekui.teklib.org/manual.html#tek.class

- Timm

--
Timm S. Mueller <[hidden email]>
Schulze & Mueller GbR, Gryphiusstr. 2, 10245 Berlin,
Gesellschafter: Franciska Schulze, Timm S. Mueller,
Tel. +49 30 93624410, http://www.schulze-mueller.de/
Reply | Threaded
Open this post in threaded view
|

Re: module inheritance example?

jomclaughlin
Brilliant -- why choose when you can do both! Thanks

On Mon, Mar 22, 2010 at 4:53 PM, Timm S. Mueller <[hidden email]> wrote:
On Mon, 22 Mar 2010 16:38:49 -0500
James McLaughlin <[hidden email]> wrote:

> Does anyone have a good example of a module inheriting from another module?

What turned out advantageous for me was to distinguish between new()
and newClass(), and to use the super class as a second argument to the
module function. This made it a fool-proof workhorse even for large and
complex class libraries, at least for my needs.

You can check out my approach at http://tekui.teklib.org/ . The base
class is tek/class.lua - see also
http://hg.teklib.org/tekui/file/a5823c144f8f/tek/class.lua#l .
Documentation is here: http://tekui.teklib.org/manual.html#tek.class

- Timm

--
Timm S. Mueller <[hidden email]>
Schulze & Mueller GbR, Gryphiusstr. 2, 10245 Berlin,
Gesellschafter: Franciska Schulze, Timm S. Mueller,
Tel. +49 30 93624410, http://www.schulze-mueller.de/