lua-users home
lua-l archive

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


David Manura writes:
> Let load.lua contain this:
>   function f() error'fail' end; f()
> Running any of these produces an error and traceback:
>   lua load.lua
>   lua -e 'require "load.lua"'
> But running this produces an error with no traceback:
>   lua -lload
> 
> This occurs because dolibrary in lua.c does not install traceback.
> It could do so if the pcall is replaced with a docall as in dofile
> and dostring.
> 
> Is this behavior intentional?

Something further odd about this is that LUA_INIT even install traceback, but
LUA_INIT is processed before '-l'.

  LUA_INIT='require "load"' lua   # error with traceback

Here's the proposed patch:

--- lua-5.1.2/src/lua.c 2007-09-01 20:48:42.734375000 -0400
+++ lua-5.1.2-dofile/src/lua.c  2007-09-01 21:51:53.718750000 -0400
@@ -144,7 +144,7 @@
 static int dolibrary (lua_State *L, const char *name) {
   lua_getglobal(L, "require");
   lua_pushstring(L, name);
-  return report(L, lua_pcall(L, 1, 0, 0));
+  return report(L, docall(L, 1, 1));
 }

If this is not a logic error, it is an omission in the source comments.