How can I debug Lua 5.2.2 code that is embedded inside of my C++ application?
I have already taken a look at this question and all the IDEs provided in it deal with 5.1 and lower and when I try to use them with 5.2.2 they crash.
How can I debug Lua 5.2.2 code that is embedded inside of my C++ application?
I have already taken a look at this question and all the IDEs provided in it deal with 5.1 and lower and when I try to use them with 5.2.2 they crash.
You should be able to debug your application using ZeroBrane Studio by following instructions for Lua 5.2 debugging. Note that you'll need to have luasocket compiled against Lua5.2. (The crash you see is likely because your application loads luasocket that is compiled against Lua5.1, which in turn loads Lua5.1 DLL or fails to find required symbols.)
If you don't want to compile luasocket, you can get binaries for Windows/OSX/Linux from this folder and its subfolders; just make sure that these libraries are in LUA_CPATH before any folders that may have luasocket compiled against Lua5.1.
[Updated based on chat discussion] The reason you may be getting multiple VM issue is that your app is probably statically compiles Lua interpreter. You then load luasocket (directly or through mobdebug), which is compiled against lua52.dll, which loads another copy of the interpreter. To avoid this you have two choices: (1) compile luasocket into your app the same way you include lua interpreter itself; you won't need anything else except one mobdebug.lua file to debug your app, or (2) use proxy dll; it will look like lua52.dll, but will actually proxy your calls to your statically compiled lua library, avoiding problems with multiple VMs. The proxy dll is for Lua 5.1, but you can tweak the script to make it work for Lua 5.2.
(If your interpreter is not statically compiled, you may still get two interpreters if the Lua DLL you load is named differently from lua52.dll.)
attempt to index global 'package' (a nil value)
: so, what happened to the package
global in your environment? –
Dormancy ...clibs52/mime/?.dll
as it may be loaded from socket.lua
and you want to make sure that it's loaded from clibs52
. It may be more convenient to switch the troubleshooting discussion to ZeroBrane Studio maillist. –
Dormancy package.path = package.path .. ";../?.lua"
ends up crashing it with the same error. I think there is a step I'm missing. –
Adrial package
table to nil or erased it? Or perhaps a change in the running _ENV
from sandboxed code? When an uncaught lua error is allowed to propogate into C space, that's what happens -- it PANICS. –
Biafra int main () { lua_State* lua = luaL_newstate(); luaopen_base ( lua ); int error = luaL_loadfile(lua, mainLua); lua_call(lua,0,0); }
–
Adrial luaopen_base
like that. You have to call it like a lua C funct -- using lua_call
or lua_pcall
for example. –
Biafra In response to OP's commented request, here's how you should open the lua standard library "base" from C++:
#include "lua.hpp"
//...
int main ()
{
lua_State* L = luaL_newstate();
luaL_requiref(L, "base", luaopen_base, 0);
// ...
int error = luaL_loadfile(L, mainLua);
lua_call(L, 0, 0);
lua_close(L);
}
Note that you can open all the standard libraries at once by replacing:
luaL_requiref(L, "base", luaopen_base, 0);
with
luaL_openlibs(L);
The Lua 5.2 reference manual Section 6 has more info about this.
PANIC: unprotected error in call to Lua API (error loading module 'socket.core' from file 'C:/ZeroBraneStudio/bin/clibs52/socket\core.dll': The specified module could not be found. )
I have looked into that location and I can tell you that it is there through copy and paste. –
Adrial © 2022 - 2024 — McMap. All rights reserved.
package.path = package.path .. "C:/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua" package.cpath = package.cpath .. "C:/ZeroBraneStudio/bin/clibs52/socket/?.dll" require('mobdebug').start()
and the error I get isPANIC: unprotected error in call to Lua API (main.lua:3: attempt to index global 'package' (a nil value))
– Adrial