上代码
function decode( cmd, model ) if cjson == nil then cjson = (require \'JSON\') return cjson:decode(cmd) else return cjson.decode(cmd) end end
实在看不懂这个lua函数意思,不知道谁能解释????
lua没学过,尝试从字面理解:解析cmd字符串到json对象,model参数没用到
function decode( cmd, model ) // 定义一个函数 if cjson == nil then // 条件判断 cjson = (require 'JSON') // 加载json模块 return cjson:decode(cmd) //:与.的区别是: 给函数添加隐藏的第一个参数self;调用函数时,默认把当前调用者作为第一个参数传递进去。
else
return cjson.decode(cmd) end end
decode的具体作用及用法可以参考 json中decode的用法,其作用是对JSON 格式的字符串进行解码。
你这里用的是Lua 写的 JSON 解析器吧,这个就不会了。
看看这里吧