[q2x] OT: Lua questions

Nick Trout nick at rockstarvancouver.com
Thu Jan 22 13:16:43 EST 2004




> Oh great and mystical Lua gods, wtf am I doing wrong here?
> 
> It's crashing out when I call the update function from C, but if I
> comment out the 'for', it's fine:
> 
> clients = {}
> 
> function update(cx)
> 	-- iterate over all active clients and do the right thing
> 	for a,b in clients do
> 	end
> end
> 
> Now, "clients" might be empty, but I thought it would handle that
> correctly, no?  Am I missing something horribly obvious?
> 
> Is there any fucking way to get Lua to tell me WHY it's dying either
> during compilation or execution?!

At compile time loadstring/dostring and loadfile/dofile return an error
number.

At runtime you're probably using lua_pcall to call update? E.g.

lua_pushliteral(L, "update");
lua_gettable(L, LUA_GLOBALSINDEX);
// push context?
ret = lua_pcall(L, 1,0, 0);

ret is error value, 0 for none. In the event of a none 0 value there
will be an error message on the stack:

if (ret!=0)
	printf("Error! %s", lua_tostring(L, -1));


Alternatively you can define an error handling function which you insert
as the 3rd argument in pcall.

Nick




More information about the q2x mailing list