Skip to content

Instantly share code, notes, and snippets.

@terryoy
Last active August 29, 2015 14:08
Show Gist options
  • Save terryoy/4a31df448932868284d5 to your computer and use it in GitHub Desktop.
Save terryoy/4a31df448932868284d5 to your computer and use it in GitHub Desktop.
lua study notes
# execute a program
$ lua hello.lua
# import a file and then into interactive mode
$ lua -i lib.lua
# execute some line
$ lua -e "print(math.sin(12))"
# execute with library "a" (using "-l")
$ lua -i -l a -e "x = 10"
# execute with parameters ("p1 p2 p3")
$ lua script.lua p1 p2 p3
--[[ now this is a comment ]]--
--[[
function useless_func()
end
]]--
function norm(x, y)
return (x^2+y^2)^0.5
end
function twice(x)
return 2*x
end
print("Hello, world!")

This gist is some study notes for Lua language.

--[[ a uninitialized global variable ]]--
print('this would be nil: b = ', b)
b = 10
print('this would be 10: b = ', b)
--[[ an environment variable (using "lua>" as a prompt ]]--
_PROMPT = "lua>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment