lua-users home
lua-l archive

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

I have a question I kept on my mind since someone mentioned this flag as
necessary to avoid memory leaks.

The stand-alone Lua executable has the -c option, to "call lua_close after
running all arguments".
For me, I have to put this option systematically.
So why is this an option? In which cases it can be unnecessary, or even
troublesome, to use it?

I am making a thin wrapper around a foreign API (in a DLL) in order to make
scripts to test the behavior of this library. Basically, I duplicated lua.c
(from 4.1-work4), just to add a call to my library, keeping the standard ones.
I just changed the main function:
int main (int argc, char *argv[]) {
  int status;
  int toclose = 0;
  (void)argc;  /* to avoid warnings */
  L = lua_open();  /* create state */
  LUA_USERINIT(L);  /* open libraries */

  /* Open non-standard libraries */

  register_getargs(argv);  /* create `getargs' function */
  status = handle_argv(argv+1, &toclose);

  /* Close non-standard libraries */

  if (toclose)
  return status;

I added the lua_otherlibclose to call a clean up routine and to release the
If the -c option is almost mandatory, I think I will remove the "if
(toclose)" line too.

BTW, I started a Win32 library, tested the same way, and it works fine for
the functions I implemented.
I used the same base for the program above, but it seems the parser fails,
error: unexpected symbol;
  last token read: `-' at line 1 in file `Test.lua'
ie. it cannot read the initial comment... The Test.lua code is intentionaly
pure standard Lua.
Sometime, in debug run, I have also an exception.
I am not sure how (if) this is related to my library (the Lua program isn't
even interpreted), to DLL loading/unloading, etc. It seems to be a parser
problem, but I use the same than my previous project which works.
I know I am vague, I am mentioning this mostly in case it strikes a familiar
ring in someone's mind... I will try and debug myself, but the Lua internals
are quite intimidating.


Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist

GMX - Die Kommunikationsplattform im Internet.