Hi @TechDojo,
Sorry, long time away from the forum…
So, yes, it is possible, and we are doing that, it is a little involved, so here goes:
You need to download and install the 32 and 64 bit versions of Lua to your Mac
I then have a shell script that lists all the .lua files in the correct compilation order (you could probably generate this from plist) and then calls the 32 and 64 bit luac executable on those files to generate a 32 and 64 bit version of lua bytecode in the .codea directory.
I then move all the .lua files out of the .codea directory to a safe area except the two bytecode files…
I then create a Main.lua that looks like:
-- Bootstrap
function setup()
local status, error = loadBytecode()
if(status == 0) then
-- setup() now points to 'real' setup(), invoke it!
setup()
else
print(\"Failed to load bytecode: status:\", status, \", error:\", error)
end
end
Then in the common AddOn .mm file I register a static function called loadBytecode that reads in the files like:
NSString* nsPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"InfestedMars.codea"];
NSString* nsFileName = [NSString stringWithFormat:@"InfestedMars%s.obf", ARCH];
nsPath = [nsPath stringByAppendingPathComponent:nsFileName];
where ARCH is a constant based on:
#if __LP64__
const char* ARCH = "_64.bc";
#else
const char* ARCH = "_32.bc";
#endif
then you read that file into an NSData object and do:
int status = luaL_loadbuffer(state, data.bytes, data.length, ARCH);
if(status == 0) {
lua_pcall(state,0,0,0);
}
const char* error = lua_tostring(state,-1);
lua_pushinteger(state, status);
lua_pushstring(state, error);
return 2;
}
Sorry, i couldnt paste my exact code, but the above basically loads the bytecode file into the Lua VM based on the architecture when you call the loadBytecode function, which then overrides the setup() function etc. with the Lua VM so when you call setup() again the whole shebang uses the bytecode…
Hope that makes sense…
I actually encrypt the bytecode and then decrypt on the fly so no plaintext source is bundles with the app…
There is actually another way I’m looking at which is to use the bin2c executable in the Lua bin dir which will convert the Lu code into C arrays which can then be loaded…
Let me know if you need more info…
Brookesi