LUA语言
记录Lua语言基本使用方法
45°的阳光
虽然你变秃了,但是你变强了
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LUA——IO
一、简单模式 file = io.open("IO.lua","r") --默认的输入文件为test.lua io.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 · 259 阅读 · 0 评论 -
LUA——协同coroutine
--创建coroutine,参数是一个函数,返回一个coroutine co = 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 · 115 阅读 · 0 评论 -
LUA——元表
print("-------------------------__index方法--------------------------") mytable = setmetatable({key1 = "value1"},{ __index = function(mytable,key) if key == "key2" then return "metatablevalue" else return nil end end }) print(mytable.key1,mytable.key.原创 2020-11-20 13:21:43 · 135 阅读 · 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 · 129 阅读 · 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替换为time print("寻找a中的world的位置:",string.find(a,"world",1)) print("反转",string.reverse(a)) print原创 2020-11-19 13:30:06 · 1002 阅读 · 0 评论 -
Lua——环境搭建
一、Linux下环境搭建 1.下载:下载地址http://www.lua.org/ftp/lua-5.3.0.tar.gz 2.解压:tar zxf lua-5.3.0.tar.gz 3.编译安装:>1make linux test >2make install 二、编写第一个lua程序 1.vim helloworld.lua print("hello world!") 运行结果: ...原创 2020-10-22 13:47:36 · 270 阅读 · 0 评论
分享