lua-users home
lua-l archive

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


Hi, list!

While re-reading lua.c today, I've noted peculiar usage of lua_gc().
It is used in two places:

1. In pmain() function garbage collector is stopped before
luaL_openlibs() call, and restarted afterwards:

  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);

2. In docall() function garbage collecgtion is forced on pcall error:

  /* force a complete garbage collection in case of errors */
  if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);

Quick googling up didn't bring the answer, so, the question is:

What is the motivation for each of these cases, and when should I do
the same? :-)

TIA,
Alexander.