lua-users home
lua-l archive

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


On Sat, Feb 03, 2001 at 01:47:46PM -0600, Joshua Ritter wrote:
> 

{snip}

> I have run into a small snag however.. 
> All function tags callback to the same static int luacallback(lua_State* ls)
> function I have defined... what I need to get from here is:
> 
> A) the "class" of the table
> B) the _name_ of the field (function)
> 
> so a table of "type" cpClass with a function called setName.. called from
> Lua as:
> 
> class = cpClass:new()
> class:setName("whewp")
> 
> would end up in the callback static int luacallback(lua_State* ls)
> 
> How do I get the cpClass and the setName here so I can match the arguments
> and call the appropriate function?

You could use lua closures when you "register" your class and methods. When
those methods are called, the closure values that you assigned to them get pushed
on the stack. In your luacallback you pop and inspect the closure values to
determine what function to call.  I use a vector array of pointer to my
member functions, the indices of the array are my closure values. In my
callback I simply pop the closure value and index my vector array for the
function pointer.

-Lenny