[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: back to basics: calling a method with arguments
- From: Matthew Metnetsky <met@...>
- Date: Tue, 30 Dec 2008 18:09:42 -0500
Hi all,
I have what I'm hoping is a ridiculously easy question. The following code
works, but no arguments are being passed into the method. Clearly I'm missing something
fundamental.
lua_State *L;
int class; // table with functions
char *cmd; // string representing a method on a class
char *args; // string to be passed to cmd
....
....
lua_rawgeti(L, LUA_REGISTRYINDEX, class);
g_assert(lua_type(L, -1) == LUA_TTABLE);
lua_getfield(L, -1, cmd);
g_assert(lua_type(L, -1) == LUA_TFUNCTION);
lua_pushstring(L, args);
g_assert(lua_type(L, -1) == LUA_TSTRING);
if (0 != lua_pcall(L, 1, 1, 0)) { // pass 1 argument, get 1 value...
...
}
The pseudo lua code looks like....
class = MyClass()
class:cmd(args)
The method call of 'cmd' on 'class' works, but I cannot seem to get args to be
passed in. The following code looks similar to the lua method:
function class:cmd(args)
print("type " .. type(args)) -- prints 'type nil'
end
Does anyone know what I'm missing in order to get a string passed into
class:cmd(...)?
Thanks!
~ Matthew
Attachment:
signature.asc
Description: Digital signature