lua-users home
lua-l archive

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


Thanks for the quick reply!
 
If I change it to lua_call(VM, 1, 0) the interpreter goes into error and stops executing my script.
 
So if I do:
 
msg("Will show")
GameObject:start()
msg("Won't show")
...the second message won't show. (note: 'msg' is a function to simply show a message box).
 
Shouldn't I somehow push 'self' onto the stack before doing the call? Is this the same as pushing the metatable onto the stack? (just guessing here :)
 
    Thanks again,
        Hugo
 
 
 -----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Russell Y.Webb
Sent: woensdag 8 juni 2005 12:09
To: Lua list
Subject: Re: Calling a function in a table from C++ without loosing 'self'

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,
Russ