[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: calling class functions from lua
 
- From: "Peter Shook" <pshook@...>
 
- Date: Sun, 18 May 2003 14:16:28 -0400
 
Lava_Monkey wrote:
can anyone help ?
I'll try, but I don't think I can convey all the concepts in one email.
I assume you want obj:Load('it') to call the 'Load' method in
class 'Foo', and 'obj' is a userdata with a pointer to an object of Class 
'Foo'.
obj:Load'it'
is the same as obj:Load('it')
is the same as obj.Load(obj, 'it')
is the same as local method = obj.Load; method(obj, 'it')
The get and call are separate.
The get part is easy if your __index is a table, the method is just found in 
the table.
If __index is a function, then during the get, the index event will call the 
index metamethod with two things on the stack.
1) the userdata in 'obj'
2) the index which is the string "Load"
The get should return 1 object off the top of the stack.  The get should 
return either a Lua function, a C closure, or a table which has a call 
metamethod, or a userdata which has a call metamethod.  Anything else will 
cause the second part  -- method(obj, 'it') -- to fail.
During the call, if the method is a function, the stack will have the 
userdata followed by the arguments.  In this case:
1) the userdata in 'obj'
2) the string "it"
You'll need to think about this before we continue.
Try some of this stuff out in a Lua script with simple tables before you try 
it in C with userdata.
- Peter Shook
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*  
http://join.msn.com/?page=features/virus