[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Calling a function in a table from C++ without loosing 'self'
- From: "Framework Studios: Hugo" <hugo@...>
- Date: Wed, 8 Jun 2005 12:33:12 +0200
On Jun 8, 2005, at 8:58 PM,
Framework Studios: Hugo wrote:
I'm trying to call a
function called 'init' in a table from C++. Currently this is what I've got:/smaller>/fontfamily>
int
cGameObject::start(lua_State *VM)/smaller>/fontfamily>
{/smaller>/fontfamily>
//
first get the table/smaller>/fontfamily>
lua_pushstring(VM,
m_TableName); // m_TableName
= "GameObject" in this example/smaller>/fontfamily>
lua_gettable(VM,
LUA_GLOBALSINDEX);/smaller>/fontfamily>
//
get the 'init' function from the table/smaller>/fontfamily>
lua_pushstring(VM,
"init");/smaller>/fontfamily>
lua_gettable(VM,
-2);/smaller>/fontfamily>
//
call the function/smaller>/fontfamily>
lua_call(VM,
0, 0);/smaller>/fontfamily>
return
0;/smaller>/fontfamily>
}/smaller>/fontfamily>
Try
using
lua_call(VM, 1, 0)
since you have 1 argument to pass (self is the
first argument).
Note t:f() is semantically the same as
t.f(t)
Hope that helps,
Russ