Hi.
We're working on multiple computers, executing a program coded in c/c++ and using lua api, and each one of them get crashed with different errors. It's usually either a segmentation fault, whose backtrace leads us to a call made bu liblua, or one that is usually given when trying to call a nil value as if it was a function.
The weird thing is, it works just fine until we reach a number of states (no, we absolutely need multiple states, only one won't be enough). They might refer to the same file -again, which works fine until less than a number of states are opened- or not.
Here's how they're opened, get registered and closed, in case there's something wrong when using multiple states :
lua_State *state=lua_open();
luaL_openlibs(state)
luaL_loadfile(filename.c_str());
...
lua_register(state,"function",function); //dozens of them
...
lua_close(state);
No other state is created until all the registers are done, whether it's closed or not depends on where the state is used.
Here's what I get during the segmentation fault :
#0 0x0013fe79 in ?? () from /usr/lib/liblua5.1.so.0
#1 0x0013325b in lua_pushlstring () from /usr/lib/liblua5.1.so.0
#2 0x001442ba in ?? () from /usr/lib/liblua5.1.so.0
#3 0x00144b61 in luaL_pushresult () from /usr/lib/liblua5.1.so.0
#4 0x00144de5 in luaL_gsub () from /usr/lib/liblua5.1.so.0
#5 0x0014fb52 in ?? () from /usr/lib/liblua5.1.so.0
#6 0x0014ffb7 in ?? () from /usr/lib/liblua5.1.so.0
#7 0x0013839a in ?? () from /usr/lib/liblua5.1.so.0
#8 0x00138834 in ?? () from /usr/lib/liblua5.1.so.0
#9 0x001337a5 in lua_call () from /usr/lib/liblua5.1.so.0
#10 0x0014f3ea in ?? () from /usr/lib/liblua5.1.so.0
#11 0x0013839a in ?? () from /usr/lib/liblua5.1.so.0
#12 0x00138834 in ?? () from /usr/lib/liblua5.1.so.0
#13 0x00133761 in ?? () from /usr/lib/liblua5.1.so.0
#14 0x00137ea3 in ?? () from /usr/lib/liblua5.1.so.0
#15 0x00137f05 in ?? () from /usr/lib/liblua5.1.so.0
#16 0x00133588 in lua_pcall () from /usr/lib/liblua5.1.so.0
And the related code :
lua_getglobal(L,"require");
lua_pushstring(L,"function");
if(!lua_pcall(L,1,0,0))
{
...
The string given as the function isn't wrong, it works fine with less than a number of states opened.
When it outputs the "nil value" error, it implies that we didn't use the related lua_register call from inside the program, but it's the same for all other states and again, they work without any problem whatsoever.
I thought it might be due to some memory leak, which I really don't get why since all states are closed.
Is this related to lua api itself (like having a predeterminded number of states might be opened at a time, maybe) ? I know I didn't give too much details, but this is really almost all of the code that is related to lua.
Edit : I forgot including the "require" statement (which I call to push a module), but it was already in the code (thus, not the reason it doesn't work) , sorry about that.
The program is single-threaded. Some objects have lua states as their attributes, hence, multiple states.
The error message indicates it can't find the file it should use... which is actually there and again, can be used without any problem with less states opened.