0

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.

2 Answers2

0

I'm not sure how exactly the DLL was compiled, but the error message likely indicates that the luaL_addlstring and other functions are not exported by it. If the symbols are exported correctly, you should be able to load luasocket and get the debugging working. See this thread for the related discussion.

Also, you don't need to replace lua53 library and executable, as you can configure the IDE to use your own copy of it using path.lua53 configuration setting as described in the documentation.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • Hi Paul, I believe that the error message is indicating that the function could not be located because the DLL is exporting a mangled c++ function name. Name mangling means that function names are exported differently between C and C++. So the luasocket core.dll is looking for the C name 'luaL_addlstring' but only the mangled names are present. I am confident that the symbols are exported correctly because the Lua interpreter exe is able to load the DLL and run. Thanks for the information about the configuration setting. – Will Stavely Nov 16 '17 at 04:17
0

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.