[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Object oriented Lua scope? (again)
- From: Andre de Leiradella <leiradella@...>
- Date: Mon, 16 Jun 2003 09:39:48 -0300
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
self.xxx 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)
...
end
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)
end
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
vice-versa.
Does anybody have ideas on this subject?
Regards,
Andre de Leiradella
http://www.geocities.com/andre_leiradella/