lua-users home
lua-l archive

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

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

	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()

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'

Does anyone know what I'm missing in order to get a string passed into


~ Matthew

Attachment: signature.asc
Description: Digital signature