Using LuaBinaries
LuaBinaries can be used in a variety of ways, depending on your needs. You can use the standalone interpreter to run Lua scripts and load external modules, you can use LuaBinaries to embed Lua in your application or to dinamically load Lua/C modules to your application.
Using the Standalone Extended Interpreter
The provided standalone Lua interpreter can load dynamic libraries using the Lua function loadlib.
In Windows your library must be linked with a stub library. A stub library is a library with only the function declarations that will bind your DLL with the Lua DLL.
Your module DLL must link with the stub library made for Visual C++ 8 (Visual Studio 2005) and distributed in the "dll8" package for 32 bits or in the "dll8_64" package for 64 bits. The distribution package of the standalone interpreter already include the MSVCR80.DLL. If you have problems using this DLL you can download the "Microsoft Visual C++ 2005 Redistributable Package" for 32 bits or for 64 bits, but you will need administrative privileges to install the package.
If you want to use another compiler then you could rebuild the stand alone interpreter using the respective library. Or if it is another version of Visual C++ you may mix run time libraries, this is safe if you do not use structures across different run times, see the MSDN article "Potential Errors Passing CRT Objects Across DLL Boundaries".
Notice that MingW can generate DLLs with different MSVCR*.DLL dependencies. To generate an import library for MingW just run (you will need the source code for the .def file):
dlltool -d lua5.1.def -D lua5.1.dll -l liblua5.1.a
The dll packages also have a dll proxy called "lua51.dll". It can be used to replace other "lua51.dll" released by other distributions. It will simply forward calls to the "lua5.1.dll". There is no compiled source code involved in the forwarding.
In UNIX the executable already contains the necessary code to resolve the symbols needed by your shared library.
Here is an example on how to use the loadlib function:
-- In Windows (the DLL can be in the PATH or in the current directory)
luaopen_mymodule = loadlib("mymodule.dll", "luaopen_mymodule")
-- In UNIX using the LD_LIBRARYPATH environment variable
luaopen_mymodule = loadlib("libmymodule.so", "luaopen_mymodule")
-- In UNIX using the complete path
luaopen_mymodule = loadlib("\home\user\mymodule\libmymodule.so", "luaopen_mymodule")
-- Call the initialization function from C
luaopen_mymodule()
-- Call the myfunc function from Lua
mymodule.myfunc("Hello.")
Building a Standalone Interpreter for Lua or Embedding Lua in an Application
In this case you can choose to use the static libraries, the dynamic libraries or build your own version of the Lua library.
Using Lua as an External Module of an Existing Application
External modules or components are implemented using dynamic libraries. In this case the simplest solution is to make your module depend on the LuaBinaries dynamic library.
In UNIX you can build a module that contains the LuaBinaries static library or you can load the LuaBinaries
dynamic library using a loadlib C equivalent, usually based on the dlfcn interface.