How can I build my C++ project to include all the Lua files in just one executable? I don't want people being able to edit the Lua files and alter the game.
Is it possible, and is it ethical?
How can I build my C++ project to include all the Lua files in just one executable? I don't want people being able to edit the Lua files and alter the game.
Is it possible, and is it ethical?
Use "embedded bytecode" feature of LuaJIT:
To statically embed the bytecode of a module in your application, generate an object file and just link it with your application.
require() tries to load embedded bytecode data from exported symbols (in *.exe or lua51.dll on Windows) and from shared libraries in package.cpath.
Example:
luajit -b test.lua test.obj # Generate object file
# Link test.obj with your application and load it with require("test")
Well, you want to put all Lua sources into your executable, so you need this:
A means of mapping file-names to the Lua files:
char lua_files[]={
"filename1\0filecontents1",
"filename2\0filecontents2",
0,
};
This can be created automatically, by a script reading your directory of Lua files when building.
Optionally, it might even pre-compile the files, so you can remove the parser from your embeddded Lua library.
load
and a string encompassing the found filecontents as a Lua string.package.searchers
.If you later want to allow loading custom scripts somehow, retain the old searchers and make sure you somehow require files not in your sources.