1

I'm trying to load a dll into my lua script and call the function. When I create the dll using GCC (under cygwin) and lua (5.2.4) I'm able to load the library & execute it without a problem. However, when I create run the same script from SciTE, using Lua 5.1, the dll loads successfully. However, it does not execute. In the dll I'm trying to simply write two integers into a file.

t = package.loadlib("mylibrary.dll","myfunc")
t(23,45)

There are two questions here: 1. What format should the 'mylibrary.dll' be, for lua to understand and execute without problems - ELF or COFF. 2. Can I run dll (built under windows, obviously) under lua running on linux?

Keshavan
  • 27
  • 2
  • You probably have to compile your dll using Lua 5.1 headers and libraries. – lhf Dec 11 '15 at 10:58
  • Do I need to consider the Lua version even if my dll functionality does not do any Lua operation? In the DLL I'm simply writing the values I receive from Lua into a file. – Keshavan Dec 11 '15 at 11:19
  • 1
    There is no ABI compatibility between 5.1 and 5.2 though you may be lucky if you use a small subset of the Lua API. – lhf Dec 11 '15 at 12:01
  • Lua uses the standard shared library functions (ex. `dlopen`, `dlsym`) for loading shared libraries, so it supports whatever they support. I don't think trying to load a Windows DLL on a Linux process will work. – Colonel Thirty Two Dec 11 '15 at 13:26
  • To further this experiment - I built a dll using VisualStuido. This was to ensure that I'm using the native compiler. Wanted to be clear that the dll is good-to-go on the windows platform. The dll was compiled with lua 5.1 headers and libraries. Still the lua 5.1 loadlib() results in an error "specified procedure could not be found". Any thoughts??? I'm following the guidelines mentioned in http://www.lua.org/pil/26.2.html – Keshavan Dec 24 '15 at 07:18
  • Finally got it working. The issue was exporting the function. In the VisualStudio world the function to be exported needs to be proceeded with __declspec(dllexport). With this the error "specified procedure could not be found" issue was resolved and the dll is getting loaded properly. I'm able to call the functionality from the DLL. – Keshavan Dec 30 '15 at 14:36

1 Answers1

1

The question in your title seems to be very different from the cause of the problem you describe.

On the one hand, the format for dynamic libraries loaded by Lua is the format for the platform that the Lua code is running on. Just as you can't take a compiled Win32 executable and expect it to run on Linux, you can't take a compiled Win32 dll and expect it to load it on Linux. Obviously emulation tools like Wine exist, but those work by emulating Windows. You could run them within the emulator, but not outside of it.

But on the other hand, that is not the source of your problem. Your problem is that you're using a dynamic library that was built for one version of Lua with an application that was built for another version of Lua. That doesn't work; Lua does not retain compatibility between "minor" versions, only between revisions (Lua 5.1.3 vs. 5.1.4).

ELF or COFF, that isn't going to work.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982