kran
kran

Reputation: 259

How to compile *.lua files as resource library?

In original, I collect *.lua files in a folder , then load them in *.c files

Now I want to hide them(*.lua) and let them in a xx.so or xx.dll

if this can be done ?

if can , then how to load them in c files ?

Upvotes: 2

Views: 1256

Answers (1)

Mario
Mario

Reputation: 36517

I wouldn't use Lua if you've got code to hide (as it's always possible to decompile it), but you could simply do the following:

  • Compile the script files using luac. This will give you output files with precompiled object code (not machine code) in them. (This step is optional but it makes it harder to read/find the actual code in the compiled file.)
  • Write a simply tool to read those files putting them into character arrays.

The resulting code should look a bit like this:

const char firstlua_lua[] = {0x11,0x12,0x13,0x14,...};

It will use the actual bytes found in the compile lua script obviously. You'll then be able to simply run these "strings" like any script source loaded.

Upvotes: 2

Related Questions