Running Lua Bytecode

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Running Lua Bytecode

Post by khamarr3524 » Mon Apr 03, 2017 6:44 pm

I'm using version 0.10.1 and cannot find the appropriate way to compile to byte code. Ive tried luac -o, and luajit -b for luajit version 2.0.5 as well as string.dump(love.filesystem.read(file)). None of these work. What's the full process for running and compiling Löve2D code to byte code?

User avatar
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: Running Lua Bytecode

Post by drunken_munki » Mon Apr 03, 2017 7:16 pm

luajit -b should work but I'm pretty sure you have to supply both the input file-name and the output filename otherwise you get nothing.

luajit -b main.lua main2.lua

should work, however you can also overwrite the file with

luajit -b main.lua main.lua

in which case you would lose the original source.

I've used this method in a batch file (win7) after I have copied the entire source folder to a secondary location, then apply the byte-code compiler to the files I need to, leaving the raw source folder completely untouched (because bad things will happen!).

How to run the file? Assuming the files have the same name as the raw source files, then Love2d/Luajit will just read it automatically regardless if it is plain source or byte-code, so you don't have to do anything else.

Therefore compiling to byte-code is completely unnecessary and not recommended unless you are doing so for specific reasons.
Last edited by drunken_munki on Mon Apr 03, 2017 9:09 pm, edited 1 time in total.

khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Running Lua Bytecode

Post by khamarr3524 » Mon Apr 03, 2017 8:50 pm

It's mostly for performance. I did what you said before and it's telling me the byte code is incompatible. Or its saying '=' expected near char(23)

User avatar
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: Running Lua Bytecode

Post by drunken_munki » Mon Apr 03, 2017 9:06 pm

Did you try luajit v2.0?

That version should be 100% compatible with lua 5.1 (that Love 0.10.x uses).

Otherwise I'm not sure

User avatar
raidho36
Party member
Posts: 2031
Joined: Mon Jun 17, 2013 12:00 pm

Re: Running Lua Bytecode

Post by raidho36 » Mon Apr 03, 2017 9:27 pm

Performance does not improves with using bytecode - the whole "improvement" is a one-time minuscule fraction of a second boost when the script is loaded (because it doesn't need to be compiled into bytecode first), then there's no difference. LuaJIT bytecode is not machine code, when you load it Lua will execute it just the same and the JIT will compile it into native assembly instructions all over again anyway. Bytecode is much larger in file size all by itself and is less compressible than source code text, further increasing file size. Finally, the one valid reason to use bytecode being obfuscation (not performance), defeated by the fact that "disassembling" Lua bytecode into almost source-identical text is trivial - a minor inconvenience to would-be hacker, no obstacle.

khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Running Lua Bytecode

Post by khamarr3524 » Mon Apr 03, 2017 11:51 pm

I just built and tested with LuaJIT 2.0, same thing: "Incompatible byte code"


Post Reply

Who is online

Users browsing this forum: Google [Bot] and 95 guests