[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Enumerating class objects
- From: Rici Lake <lua@...>
- Date: Fri, 28 Oct 2005 06:03:53 -0500
On 28-Oct-05, at 4:24 AM, Zulfiqar Malik wrote:
Last time I posted it on the list, someone told me that this was not
possible since LUA is not a type safe language and you cannot enumerate
structures and classes registered from C++ as such, but obviously LUA
does
it somehow. E.g. an expression a = object:var1 + object:var2 works and
it
properly calculates the offset of var1 and var2 w.r.t. the base
object, and
its hard for me to believe that someone from the application side
can't do
it!
object:var1 is not really an "offset" (and actually that doesn't work,
it
would need to either be object.var1 or object:var1()) -- but in any
case it
will end up being a lookup, possibly recursive.
There are many times when you can "look things up" without being able
to enumerate them. The activities are quite different. In Lua, the
looking a key up in a table can cause an arbitrary function to execute
(a metamethod) and the key will be deemed to exist if and only if the
function returns a non-nil value. Since Lua is turing-complete, being
able to enumerate the possible keys in such a table is equivalent to
the halting problem which is well known to be unsolvable.