Search code examples
dlllualuasocketzerobrane

How to use ZeroBrane Studio IDE debugger when lua is compiled as c++


I have compiled Lua 5.3 as a 32 bit c++ DLL and exe. The DLL contains all the lua code except for lua.cpp and luac.cpp. The exe compiles lua.cpp and uses the DLL to run the lua interpreter. This works fine when running on its own from the command line. I wish to be able to run from the IDE using this DLL and exe.

If I replace /ZeroBraneStudio/bin/lua53.dll and lua53.exe with my own versions, I can run scripts (clicking the two green arrows). However, debugging does not work, giving the following error:

The procedure entry point luaL_addlstring could not be located in the dynamic link library lua53.dll.

I can see that this is happening because the debugger is making use of luasocket. \ZeroBraneStudio\bin\clibs53\socket\core.dll is dependent on lua53.dll, and is expecting it to contain lua compiled as c.

So, what is the correct solution to this - is it to compile luasocket as c++ as well?

(And, if so, does anybody have instructions/guidance for doing so? I have been unable to find anything on this.)

Thanks.


Solution

  • Okay, I was able to get it working. The solution was to compile luasocket as c++. I won't give full instructions on how to do this here, but some points to hopefully help anybody else with the same issue:

    • Got luasocket from here: https://github.com/diegonehab/luasocket
    • Renamed all *.c files to *.cpp
    • Renamed Lua52.props to Lua.props (I am using lua 5.3 but seems like it is compatible?)
    • Placed lua headers and lib in appropriate folders
    • Opened solution in Visual Studio 2012
    • Fixed up minor issues with project files, like the renaming of the files.
    • Added 'extern "C"' to declaration of luaopen_socket_core and luaopen_mime_core functions (necessary for lua to be able to load libraries).
    • Built solution
    • Copied new dlls into clibs53/socket and clibs53/mime folders.

    I used Dependency Walker to help with this. If anybody wants further details in the future please leave a comment.