Using Programming in Lua (4th Edition)
Setup (Arch Linux):
$ sudo pacman -S lua luarocksInteractive:
$ lua
> print("Hello, Lua!")Script file (examples/hello.lua):
#!/usr/bin/env lua
print("Hello, Lua!")Running the script file:
$ lua examples/hello.lua
$ chmod +x examples/hello.lua
$ examples/hello.luaLoading the script file from an interactive session:
$ lua
> dofile("examples/hello.lua")Run interactive session after executing a script:
$ lua -i examples/hello.lua
>Example library script (examples/hypot.lua):
function hypot(a, b)
return math.sqrt(a ^ 2 + b ^ 2)
endLoad library and execute an expression:
$ lua -l examples/hypot -e 'print(hypot(3, 4))'
5.0