Reputation: 331
I have a program (a small game) written in C++ that gets its configuration from Lua files (they are basically modules for the program). For instance, the program gets its name, version and what it is and isnt allowed to do and what the player can do from the Lua files. The problem is when I start distributing this small game to a few people they can configure the Lua files which I dont want to happen so I have thought of encrypting them and then decrypting them when the program starts but I just cannot grasp the concept of how to actually do it and in what way. All in all, is this a rather simple task as I imagine it to be?
How I see it is like this: Encrypt the lua files with some program in a certain encryption method. The write C++ code into the program that first decrypts the Lua files and then starts reading them. Is this concept correct? The encryption itself could be as weak as possible, as long as it works.
Upvotes: 6
Views: 3471
Reputation: 331
By using luac I was finally able to make it all work.
I used this phrase to compile it with luac
(in there, tester.lua
is name of output file and test.lua
is the file that is compiled):
luac -o tester.lua test.lua
It all works automatically, whether its compiled or not. Now the problem is, anyone could place the compiled lua file with a noncompiled version and it would still work because dofile reads both, normal and compiled lua. What would you fellas suggest as the solution so that dofile would only read compiled lua files and not uncompiled ones?
Upvotes: 5
Reputation: 72312
Distributing precompiled Lua files instead of source will probably suffice for your purposes. See luac
.
Upvotes: 3
Reputation: 2122
Yes, that's basically it.
Assuming at the moment you have something like
runLuaFromFile("config.lua");
you'd want to do
runLuaFromMemory(myString);
obviously the runLuaFromFile
and runLuaFromMemory
aren't real functions, they're just placeholders for whatever Lua system you're using
Upvotes: 4