lua-users home
lua-l archive

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


Petr Stetiar wrote:
Rici Lake <lua@ricilake.net> [2007-03-25 23:36:16]:

It's something like this:

int lua_get_function(char *function)
{
	lua_getfield(L, LUA_GLOBALSINDEX, function);
	if (!lua_isfunction(L, -1)) {
		return FALSE;
	}

	return TRUE;
}
int lua_event_generic(char *event_name, char *event_text, int param)
{
	int ret = 0;
	char fnc[MAX_PATH] = {0};
	char err[MAX_PATH] = {0};

	_snprintf(fnc, MAX_PATH-1, "gabenie_event_%s", event_name);
	_snprintf(err, MAX_PATH-1, "error gabenie_event_%s()", event_name);

	if (!lua_get_function(fnc)) {
		return ret;
	}

Looks like you're letting the nil's pile up on the stack. If you were to call that function 30 times, and there were no hooks to call, you'd have pushed 30 nils on the stack, which is more that LUA_MINSTACK.

See lua_checkstack(). (But the short answer is to pop the stack if you're not going to call the function.)