Lua ![]() |
http://www.tecgraf.puc-rio.br/lua/ |
Description: | "Lua is a powerful, light-weight programming language designed for extending applications. Lua is also frequently used as a general-purpose, stand-alone language." "Lua combines simple procedural syntax (similar to Pascal) with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, interpreted from bytecodes, and has automatic memory management, making it ideal for configuration, scripting, and rapid prototyping." Lua has a very small footprint and let's itself very easy embed into other languages. |
Factorial | Michael Neumann |
function fac(n) if n < 2 then return 1 else return n * fac(n-1) end end print(fac(6)) |
Calculates the factorial. Results
720 . |
Hello World | Michael Neumann |
-- Hello World in Lua print("Hello World\n") |
Prints "Hello World" onto the
screen. |
Squares (1) | Michael Neumann |
-- for var = from, to [, step] do block end for i = 1, 10, 1 do print(i*i) end |
Outputs the squares from 1 to
10. |
Squares (2) | Michael Neumann |
function range(from, to) arr, inx = {}, 0 for i = from, to do arr[inx] = i inx = inx + 1 end return arr end for index, value in range(1, 10) do print(index .. "^2 = " .. value) end |
Outputs the squares from 1 to
10. |