
LUA语言
记录Lua语言基本使用方法
45°的阳光
虽然你变秃了,但是你变强了
展开
-
LUA——IO
一、简单模式file = io.open("IO.lua","r")--默认的输入文件为test.luaio.input(file)--输出文件的第一行print(io.read())--关闭打开的文件io.close(file)--以只写方式打开file = io.open("IO.lua","a")--设置默认输出文件io.output(file)--最后一行添加如下内容io.write(" --hello lua!-------------------------原创 2020-11-20 16:05:53 · 202 阅读 · 0 评论 -
LUA——协同coroutine
--创建coroutine,参数是一个函数,返回一个coroutineco = coroutine.create( function(i) print(i) end)print("\n----------重启coroutine----------------------")coroutine.resume(co,"coroutine") print("\n----------查看coroutine状态------------------")print(coroutine.statu原创 2020-11-20 14:34:26 · 75 阅读 · 0 评论 -
LUA——元表
print("-------------------------__index方法--------------------------")mytable = setmetatable({key1 = "value1"},{__index = function(mytable,key) if key == "key2" then return "metatablevalue" else return nil endend})print(mytable.key1,mytable.key.原创 2020-11-20 13:21:43 · 97 阅读 · 0 评论 -
LUA——table
fruits = {"banana","orange","apple"}print("-------------------------拼接-----------------------------")print("拼接字符 ",table.concat(fruits))print("连接后的字符串,以“-”分隔",table.concat(fruits,"-"))print("拼接2,3之间的字符 ",table.concat(fruits,"--",原创 2020-11-20 10:16:39 · 91 阅读 · 0 评论 -
Lua——字符
Lua字符相关基本函数a = "hello world"print("a is :",a)print("转换为大写:",string.upper(a))print("转换为小写:",string.lower(a))print(string.gsub(a,"world","time",1)) --将world替换为timeprint("寻找a中的world的位置:",string.find(a,"world",1))print("反转",string.reverse(a))print原创 2020-11-19 13:30:06 · 917 阅读 · 0 评论 -
Lua——环境搭建
一、Linux下环境搭建1.下载:下载地址http://www.lua.org/ftp/lua-5.3.0.tar.gz2.解压:tar zxf lua-5.3.0.tar.gz3.编译安装:>1make linux test >2make install二、编写第一个lua程序1.vim helloworld.luaprint("hello world!")运行结果:...原创 2020-10-22 13:47:36 · 193 阅读 · 0 评论