lua-users home
lua-l archive

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

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:
int cGameObject::start(lua_State *VM)
// first get the table
 lua_pushstring(VM, m_TableName);        // m_TableName = "GameObject" in this example
 lua_gettable(VM, LUA_GLOBALSINDEX);
// get the 'init' function from the table
 lua_pushstring(VM, "init");
 lua_gettable(VM, -2);
// call the function
 lua_call(VM, 0, 0);
return 0;

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,