Debugging Lua 5.2.2 Inline Code

How can I debug Lua 5.2.2 code embedded inside my C ++ application?

I have already addressed this issue, and all the IDEs provided in it deal with 5.1 and below, and when I try to use them with 5.2.2, they crash.

+6
source share
2 answers

You should be able to debug your application using ZeroBrane Studio , following the instructions for debugging Lua 5.2 . Note that you will need to build luasocket against Lua5.2. (The probability of failure is probably due to the fact that your application loads luasocket, which is compiled against Lua5.1, which, in turn, loads the Lua5.1 DLL or does not find the required characters.)

If you do not want to compile luasocket, you can get binaries for Windows / OSX / Linux from this folder and its subfolders ; just make sure these libraries are in LUA_CPATH in front of any folders that may have luasocket compiled with Lua5.1.

[Updated based on chat discussion] The reason you might get a few problems with VM is because your application is probably statically compiling a Lua interpreter. Then you download luasocket (directly or via mobdebug), which is compiled against lua52.dll, which loads another copy of the interpreter. To avoid this, you have two options: (1) compile luasocket into your application in the same way as the lua interpreter itself; you will not need anything but one mobdebug.lua file to debug your application, or (2) use a dll proxy; it will look like lua52.dll, but actually proxies your calls to your statically compiled lua library, avoiding problems with multiple virtual machines. dll proxy for Lua 5.1, but you can configure the script to work for Lua 5.2.

(If your interpreter is not statically compiled, you can still get two interpreters if the LLLL library you load is called differently from lua52.dll.)

+5
source

In response to a request with OP comments, here is how you should open the standard lua "base" library 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); } 

Please note that you can immediately open all standard libraries by replacing:

 luaL_requiref(L, "base", luaopen_base, 0); 

with

 luaL_openlibs(L); 

The Lua 5.2 reference guide in section 6 provides more information about this.

+3
source

Source: https://habr.com/ru/post/953411/


All Articles