lua-users home
lua-l archive

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


Matthew Metnetsky wrote:
	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 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(...)?

Matthew, you must push the object itself - the implicit 'self' argument - on the stack before the args string. That is, switch the order of the 'class' and 'cmd'. Your way is the OOPsy way, but in Lua it is just a function call with syntactic sugar.

Doug