How can I build and link the Lua core and multiple Lua modules in a single .exe file

I need to make a portable application that will work on Windows, Linux, MacOS and does not require installation. It should be one executable file and other library files (.dll, .so ...). I will use ANSI C and recompile the project for each platform. I want to use Lua scripts, so I have to embed a Lua interpreter in my code. I need a network and some other modules for writing, but now that Lua already has modules for this purpose, so I will use them instead of writing my own. How can I link all this together, Lua interpreter, Lua modules (LuaSocks ie) in one executable file that will load the .lua script. Lua has a โ€œrequiredโ€ system that expects .dll to find, so I wonder what I have to do, is it enough to just call functions without a โ€œrequireโ€ statement.

+7
source share
2 answers

You can certainly do this (and this is not so!), Although this is not trivial. The Lua core is built for implementation, so you can simply include Lua sources in your own project, and it "just works" :).

The deal is slightly different from the modules - not many of them are suitable for direct embedding. For example, this has been successfully tested for LuaSocket before and here . The main idea is to embed the MODULE sources in your project and insert the luaopen_MODULE function in package.preload['MODULE'] so that require can pick it up later.

One way is to look at the sources of projects that are already implementing Lua and other libraries such as Lร–VE , MurgaLua and Scrupp .

If the goal of not having one executable file without external libraries is impossible, you can get a little loose and go to a portable application - an application that carries all its dependencies with it in the same directory, regardless of the system. This is what LuaDist was designed for - you use it like LuaRocks to install Lua packages. The difference is that these packages can be installed / deployed in a separate directory, where all the necessary dependencies are also installed. This directory ("dist") is completely independent, that is, you can move it to another location, and it will work anyway.

Also, I donโ€™t like the idea of โ€‹โ€‹an application that needs to be installed (since it puts files all over my system) - deleting should just be deleting the directory :)

+8
source

I believe that you cannot do this (and I think it is wrong to do this). An executable file is an operating system and a specific machine (on some systems, such as MacOSX, there are fat binary executables, which are a combination of various machine-specific options for the same operating system.).

The only way to have a program independent of the system and the machine is, in essence, to aim it at some one common "virtual machine" (in the broadest sense). In your case, this virtual machine is a Lua virtual machine (it could be a Java VM for others, etc.). But you must assume that your user has it, or provide one that is a machine and a system.

And I personally would not like the idea of โ€‹โ€‹an application that cannot be installed (because then it is not easy to remove).

0
source

All Articles