7

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

RBerteig
  • 41,948
  • 7
  • 88
  • 128
  • I've tried to improve the question with my (admittedly heavy) edit to reflect what I believe the OP was really asking. If I'm wrong, please feel free to boldly correct me! In any case, I think this question does reflect an occasional confusion seen by new users of Lua, and is worth preserving. – RBerteig Apr 03 '12 at 22:45

2 Answers2

8

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.).

John Calsbeek
  • 35,947
  • 7
  • 94
  • 101
  • Please discard my pending edit! I was totally incorrect. Turns out that Lua bytecode portability is questionable - something that I found with only little research. My apologies. – Deco Apr 03 '12 at 09:06
2

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.

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68