希望多多加强一下表的理解和学习
- function ToStringEx(value)
- if type(value)=='table' then
- return TableToStr(value)
- elseif type(value)=='string' then
- return value
- else
- return tostring(value)
- end
- end
- function TableToStr(t)
- if t == nil then return "" end
- local retstr= ""
- local i = 1
- for key,value in pairs(t) do
- local signal = ","
- if i==1 then
- signal = ""
- end
- if key == i then
- retstr = retstr..signal..ToStringEx(value)
- else
- retstr = retstr..signal..ToStringEx(key)..ToStringEx(value)
- end
- i = i+1
- end
- retstr = retstr..""
- return retstr
- end
- local a={c=7,b=8,d=9}
- print(a)
- s=TableToStr(a)
- print(s)
复制代码- [2021:08:17-09:58:55:727] 开始打包脚本,请稍等...
- [2021:08:17-09:58:55:758] 打包脚本完成
- [2021:08:17-09:58:55:758] 开始发送到客户端并运行,请稍等...
- [2021:08:17-09:58:55:986] [论坛群友问题解答.lua 行号:153] {
- c ==> 7,
- d ==> 9,
- b ==> 8,
- }
- [2021:08:17-09:58:55:990] [论坛群友问题解答.lua 行号:157] c7,d9,b8
- [2021:08:17-09:58:55:993] 脚本退出
复制代码
|