下载地址:
https://luabinaries.sourceforge.net/download.html
安装环境变量
检查一下是否安装成功,有版本号,打印一句话,如下表示成功
idea 安装插件,方便编写lua脚本
配置一下idea
运行测试
local function main()--单行注释--[[多行注释多行注释]]print("hello lua")--定义变量a = 5 -- 全局变量local b = 5 -- 局部变量name, age, phone = "lsj", 16, "12345678901"print(name, age, phone)-- 创建一个数组local myArray = { "ldj", 20, true, 40, 50 }-- 创建table (map)local cat = { name = "喵咪", age = 2 }print(cat.name .. " " .. cat.age)-- 访问数组元素print(myArray[1]) -- 输出 10-- 计算数组长度print(#myArray)--操作字符串b = "hello" .. " " .. "world" --字符串拼接print(b)--循环操作while (a < 10)doa = a + 1print("你好呀!")endfor i = 1, 2doprint("很高兴见到你!")end--操作数组for i, v in ipairs(myArray)doprint(i, v)end--分支语句if a > 0 and a < 6 thenprint("上小学" .. a)elseif a < 0 thenprint("学前班" .. a)elseprint("小学毕业了" .. a)endendmain()