lua-users home
lua-l archive

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


Am 08.10.2015 um 09:12 schröbte Dirk Laurie:
2015-10-08 0:36 GMT+02:00 Elie Michel <elie.michel@exppad.com>:
I have at the beginning something like this:

     if (luaL_loadfile(L, "test.lua") || lua_pcall(L, 0, 0, 0)) {
         cout << "Error: " << lua_tostring(L, -1) << endl;
     }
...
if (lua_pcall(L, 1, 0, 0)) {
        cout << "Error: " << lua_tostring(L, -1) << endl;
   }

The error code for luaL_loadfile can only be 2,4 or 6 and for lua_pcall
2,4 or 6 so 13 does not come from here.

Find other places in your code with "Error:"

If I interpret the subject (unprotected error in call to Lua API) correctly, the error happens *outside* of every `pcall`. So it's the `panic` function in `lauxlib.c` (`lib_aux.c` in case of LuaJIT) which is printing the error message, not the OP. The good news is that you can put a debugger break point on `panic` (or `exit`) and see in the backtrace where the error is thrown. "13" is a strange error message though, so I suspect that the Lua stack gets messed up somehow in the loop. Maybe a Lua(JIT) library with API checks enabled (`-DLUA_USE_APICHECK`) can shed some light ...

Anyway, unprotected errors smell bad, so I recommend putting (almost) all interaction with the Lua API into a `lua_CFunction` that is called via `lua_cpcall`. See the source code of the Lua interpreter (`lua.c`) for an example.

HTH,
Philipp