lua-users home
lua-l archive

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

Hi All,

I'm a big Lua fan and also a big OOP fan. While Lua provides the methods
necessary to implement classes and objects through metatables, it is
difficult to actually write OO programs in Lua because of repetitive use of and self:xxx() to access instance properties and methods. Peter
Shook posted a version of lauxlib that changes luaL_loadfile and
luaL_loadbuffer to provide a syntactical sugar for those cases through the
use of @ to access instances members, but some cases are yet to be handled:

. explicitly calling inherited methods;
. static properties;
. static methods.

I'm thinking of creating versions of luaL_loadfile and luaL_loadbuffer that
could be tuned to work with any particular class system to implement the
first case using @@:

First = class()

function First:doSomething(a, b, c)

Second = class(First)

function Second:doSomething(a, b, c)
        -- would make a recursive call
        -- @doSomething(a, b, c)

        -- will call First:doSomething() using something like
        -- findInheritedMethod(self, 'doSomething')(self, a, b, c)
        @@doSomething(a, b, c)

but cases 2 and 3 are more difficult to handle using Peter's "pre-processor"
approach because there's no way to mark properties and methods as static so
it's easy to make mistakes and call static methods as instance methods and

Does anybody have ideas on this subject?


Andre de Leiradella