lua-users home
lua-l archive

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



My last issue was with a class() function that create a class from
functions.

This might interest you:

http://metalua.luaforge.net/samples/olua.lua.html

It's a Metalua module that adds a class syntax. It can be significantly simplified, and the implementation model of the classes can be changed as suits you best. It currently allows to write things like:

---------------------------------------------
-- Import the syntax extension
-{ dofile "olua.luac" }  -{ olua_init }

class root
    field x = 0
    method init (n) -- constructors are all called "init"
        if n then self.x = n end
    end
    method f ()
        self.x = self.x + 1
        print (self.x)
    end
end

class leaf < root
    field x, y = 100, 42
end

-- Simple test for constructors and basic inheritance
function test()
    r = root(10)
    for i=1, 10 do
        r:f()
    end
    l = leaf()
    for i=1, 10 do
        l:f()
    end
end 
---------------------------------------------

A much simpler and better designed version will hopefully ship with Metalua alpha 0.2