【Hello World】第一个Lua程序将遵循传统做法,打印一句“Hello World”:
print("Hello World")
【阶乘】下面的程序用于输出输入值对应的阶乘:
-- 定义一个阶乘函数 function fact (n) if n == 0 then return 1 else return n * fact(n-1) end end print("enter a number:") a = io.read("*number") -- 读取一个数字 print(fact(a))