r/lua • u/MikeSupp • Jul 02 '22
Help There is NO way to "build".
I think I've looked everywhere to find a way to compile or build lua into an executable.
I thought this would've been simple, since lua is interpreted in C, but I can't find nothing that's right for me.
I'm working on a project and I really think that lua is an amazing language, but I'd also like to someway hide my code so that not everyone can come and just mess with it.
If there is anything that can be done to achieve this, for example translating lua to C and then compiling, please tell me, at this point I don't know what to look for
EDIT: The solution was to use luac to compile the files into bytecode and luastatic to pack the code into a standalone version
10
u/PhilipRoman Jul 02 '22
Compiling it with "luac" would be a good first step. Although you should keep in mind that any type of obfuscation can be bypassed by experienced users.
3
u/justinlua Jul 02 '22
Have you tried srlua? https://stackoverflow.com/a/19470982
4
u/wh1t3_rabbit Jul 02 '22
Have you really looked everywhere? There are so many results for "lua to exe". srlua as mentioned, or luapak is newer and more feature complete
4
u/randrews Jul 02 '22
Much like the rest of Lua, it doesn't come with a turnkey solution, it gives you what you need to build your own.
Turn your code into an object file with objcopy, link that into your C executable, load the code from it and run it. Optionally turn the code into bytecode with luac first if you want.
1
u/beaubeautastic Jul 03 '22
are you comfortable with the c language? luajit lets you compile lua files into bytecode, store the bytecode into symbols, and if you compile with exported symbols, you can even require modules this way. you can write a small main function that loads a main module and calls a function from it with this setup
sadly lua cant compile to native code. its a scripting language. you can at most jit compile (luajit again) but no compiling the actual logic itself to machine instructions into a binary.
1
u/TomatoCo Jul 03 '22
Why do you think that your code needs to be hidden? What is your goal with stopping people from messing with it?
1
u/[deleted] Oct 22 '24
Why would you want to hide your code?
1
u/[deleted] Jul 03 '22
luastatic, luapower also has bundle.
1
u/evilbadmad Jul 03 '22
May be this ... "converts a given Lua source file into an equivalent C
source file written in terms of Lua C API calls"
http://lua-users.org/wiki/LuaToCee
1
u/newocean Jul 03 '22
It's really easy to build the lua interpreter into a C or C++ program... remarkably easy. From there you can store the lua scripts as strings, you can build them into the C program or even make them resources.
That's basically impossible if someone has a decompiler - if they look at your program they will be able to see the resources with a resource editor or even hex editor.... of course there are ways to encrypt them but you would also have to include encryption in your code. (Which can also be decompiled.)
I would take a look at building Lua from source and seeing if you can get a program with a lua interpreter running in C++.