lua-users home
lua-l archive

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


Petr Stetiar wrote:
The problem happens in my C lua_get_function(), which calls lua_getfield()
about 200 times per minute.
int lua_get_function(char *function)
{
	... snip ...
	lua_getfield(L, LUA_GLOBALSINDEX, function);
	... snip ...
}

Do you check to make sure that there was a hook with that name? It's hard to tell from your snipped code.

You should be doing something like:

  lua_getfield(L, LUA_GLOBALSINDEX, function);
  if (!lua_isnil(L, -1)) { ... call the function ... }
  else return 0;  /* Or something to indicate there was no function */

Also, you might want to use lua_pcall when you call the function. (Or make sure that the function call is within a protected call.)