lua 初级的代码规范

mac2022-06-30  29

本文目的:

最近工作的需要使用了lua语言 ,暂时记录了学习lua中的一些基本语法和相关的小问题。

 

lua 中的 基本类型:

number

string

table

备注 lua 中 没有 list 和 python(dict) 的类型 ,这些都是 table的类型。

例如:

list: local data = {1,2,3,4,5}

dict:local data = {name="liukang",age="23"}

1. 在lua 中如何判断是list 还是 dict 可以简答的通过 data[1] ~= nil 判断。

2 lua 中的类型转换需要的如下:

string to number  tonumber()

number to string data..""

 

3. lua 的 for 循环 语句:

 

for k,v in pairs(data) do

  print(k)

  print(v)

end

 

4. lua 中的字符串切割,这个是网络看到的 demo

function mysplit(inputstr, sep)if sep == nil then sep = "%s" end t = {};i = 1 for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do t[i] = str i = i + 1 end return tend5. 时间转换为时间戳 如果不指定 时分秒 那么默认的就是 中午十二点。

 

转载于:https://www.cnblogs.com/fenghanye/p/9465613.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)