Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can bytecode produced by luac be used on computers with no Lua library?

Tags:

lua

luac

If I compile a regular .lua file with luac, can the result be ran without the Lua library or interpreter installed?

like image 948
user1309306 Avatar asked Apr 03 '12 00:04

user1309306


2 Answers

No. You can run it on a version of Lua that was built without the compiler, but you still need the Lua interpreter to execute the code.

Incidentally, the compiled Lua bytecode is also machine-specific; i.e. you can't compile on one architecture and then run that output on another architecture unless you understand the subtleties (endianness, sizes of types, etc.).

like image 54
John Calsbeek Avatar answered Oct 10 '22 23:10

John Calsbeek


If your code doesn't use any dynamic load-based facility (that's loadstring, loadfile, require, etc.) you can strip Lua library to just a VM, because what compiler emits is code to be run on this virtual machine. This can easily cut Lua already small footprint to 1/3 fraction of original.

However, since this is NOT a native binary code for any currently existing architecture, you still CAN'T run it directly without assistance of VM.

like image 35
Oleg V. Volkov Avatar answered Oct 10 '22 23:10

Oleg V. Volkov