简体   繁体   English

调试嵌入式Lua 5.2.2代码

[英]Debugging embedded Lua 5.2.2 code

How can I debug Lua 5.2.2 code that is embedded inside of my C++ application? 如何调试嵌入在C ++应用程序中的Lua 5.2.2代码?

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. 我已经看过这个问题 ,其中提供的所有IDE都处理5.1和更低版本,当我尝试在5.2.2中使用它们时它们会崩溃。

You should be able to debug your application using ZeroBrane Studio by following instructions for Lua 5.2 debugging . 您应该能够使用ZeroBrane Studio按照Lua 5.2调试的说明调试应用程序。 Note that you'll need to have luasocket compiled against Lua5.2. 请注意,您需要根据Lua5.2编译luasocket。 (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.) (您看到的崩溃可能是因为您的应用程序加载了针对Lua5.1编译的luasocket,后者又加载了Lua5.1 DLL或无法找到所需的符号。)

If you don't want to compile luasocket, you can get binaries for Windows/OSX/Linux from this folder and its subfolders ; 如果您不想编译luasocket,可以从该文件夹及其子文件夹中获取Windows / OSX / Linux的二进制文件 ; just make sure that these libraries are in LUA_CPATH before any folders that may have luasocket compiled against Lua5.1. 只需确保这些库在任何可能具有针对Lua5.1编译的luasocket的文件夹之前都在LUA_CPATH中。

[Updated based on chat discussion] The reason you may be getting multiple VM issue is that your app is probably statically compiles Lua interpreter. [基于聊天讨论更新]您可能遇到多个VM问题的原因是您的应用程序可能静态编译Lua解释器。 You then load luasocket (directly or through mobdebug), which is compiled against lua52.dll, which loads another copy of the interpreter. 然后加载luasocket(直接或通过mobdebug),它是针对lua52.dll编译的,后者加载了另一个解释器副本。 To avoid this you have two choices: (1) compile luasocket into your app the same way you include lua interpreter itself; 为避免这种情况,您有两种选择:(1)将luasocket编译到您的应用程序中的方式与包含lua解释器本身的方式相同; you won't need anything else except one mobdebug.lua file to debug your app, or (2) use proxy dll; 除了一个mobdebug.lua文件来调试你的应用程序,你不需要任何其他东西,或者(2)使用代理dll; it will look like lua52.dll, but will actually proxy your calls to your statically compiled lua library, avoiding problems with multiple VMs. 它看起来像lua52.dll,但实际上会代理您对静态编译的lua库的调用,避免多个VM出现问题。 The proxy dll is for Lua 5.1, but you can tweak the script to make it work for Lua 5.2. 代理dll适用于Lua 5.1,但您可以调整脚本以使其适用于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.) (如果你的解释器没有静态编译,如果你加载的Lua DLL命名与lua52.dll不同,你仍然可以得到两个解释器。)

In response to OP's commented request, here's how you should open the lua standard library "base" from C++: 为了回应OP的评论请求,以下是如何从C ++打开lua标准库“base”:

#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. Lua 5.2参考手册第6节提供了有关此内容的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM