How to execute lua bytecode generated by luac on linux
I have a simple lua hello.lua source code
print('Hello Lua')
I have executed this file for bytecode on a RedHat Linux machine using Lua5.3.4 like this:
luac -o hello.luac hello.lua
chmod +x hello.luac
./hello.luac
bash: ./hello.luac: cannot execute binary file
The architecture should be good, I think. I cannot figure out what is wrong.
+3
source to share
2 answers
Since his answer @lhf says that Lua bytecode is executed using the Lua interpreter, and as manual suggests:
To allow Lua to be used as a script interpreter on Unix systems, a standalone interpreter skips the first line of a snippet if it starts with C #. Therefore, Lua scripts can be made into executable programs using the forms
chmod +x
and#!
.
Add a shebang as the first line of your script:
#!/usr/bin/env lua
print('Hello Lua')
0
source to share