lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 14 Jan 2009, at 11:01, Michael Bauroth wrote:

Thank you for the quick response. Unfortunately I only want to use plain lua without the use of third party modules :(
That's why I mentioned the previous link to the wiki.


Actually, I was not suggesting you to use other implementation, I was just pointing that the same discussion there may apply to you case/ implementation (you asked for hints ;-).

What I mean is that you should bind the method implementation (i.e. 'create') to its class or superclass somehow to be able to get the inherited implementation. For example.

function inheritsFrom( baseClass )
    local new_class = {}
    local class_mt = { __index = new_class }

    function new_class:create()
local newinst = baseClass:create() -- function now has an upvalue with the superclass
        setmetatable( newinst, class_mt )
        return newinst
    end

    if baseClass then
        setmetatable( new_class, { __index = baseClass } )
    end

    return new_class
end

A similar discussion applies to other overridden methods that may access the original/inherited implementation as presented in the link I mentioned previously. By the way, LOOP is plain Lua, so you can borrow some ideas from there if they fit you.


--
Renato Maia
PhD student at PUC-Rio
__________________________
http://www.inf.puc-rio.br/~maia/