How to execute lua bytecode genrated by luac on linux

Viewed 1925

I have a simple lua source code called hello.lua

print('Hello Lua')

I complied this file to bytecode on a RedHat Linux machine , using Lua5.3.4 as follows:

luac -o hello.luac  hello.lua
chmod +x hello.luac
./hello.luac 
bash: ./hello.luac: cannot execute binary file

The architecture should be fine I guess. I cant figure what is wrong.

3 Answers

The shebang is removed by luac even if the lua source file has it. In some case when it's necessary to run the compiled binary without any parameter, e.g. CGI, you can add the shebang manually at the top of the luac file:

luac -o hello.luac hello.lua
echo '#!/usr/bin/env lua' > shebang
cat shebang hello.luac > hello.luac2
mv hello.luac2 hello.luac
chmod +x hello.luac
./hello.luac
Related