加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua table操作实例详解

发布时间:2020-12-14 22:21:10 所属栏目:大数据 来源:网络整理
导读:lua_gettable lua_getglobal(L,"mytable") == push mytable lua_pushnumber(L,1)??????? == push key 1 lua_gettable(L,-2)???????? == pop key 1,push mytable[1] lua_settable lua_getglobal(L,1)??????? == push key 1 lua_pushstring(L,"abc")??? == pus
lua_gettable
lua_getglobal(L,"mytable") <== push mytable
lua_pushnumber(L,1)??????? <== push key 1
lua_gettable(L,-2)???????? <== pop key 1,push mytable[1]

lua_settable
lua_getglobal(L,1)??????? <== push key 1
lua_pushstring(L,"abc")??? <== push value "abc"
lua_settable(L,-3)???????? <== mytable[1] = "abc",pop key & value

lua_rawget:
用法同lua_gettable,但更快(因为当key不存在时不用访问元方法__index)

lua_rawset
:
用法同lua_settable,但更快(因为当key不存在时不用访问元方法__newindex)


lua_rawgeti必须为数值键
lua_getglobal(L,"mytable") <== push mytable
lua_rawgeti(L,-1,?1)?????? <==?
push mytable[1],作用同下面两行调用
--lua_pushnumber(L,1)????? <== push key 1
--lua_
rawget
(L,-2)????????? <== pop key 1,push mytable[1]

lua_rawseti必须为数值键

lua_getglobal(L,"mytable") <== push mytable
lua_pushstring(L,"abc")??? <== push value "abc"
lua_rawseti(L,-2,1)?????? <== mytable[1] = "abc",pop value "abc"

lua_getfield必须为字符串键
lua_getglobal(L,"mytable") <== push mytable
lua_getfield(L,?"x")??? <==?
push mytable["x"],作用同下面两行调用
--lua_pushstring(L,"x")??? <== push key "x"
--lua_
gettable(L,-2)??????? <== pop key "x",push mytable["x"]


lua_setfield必须为字符串键
lua_getglobal(L,"abc")??? <== push value "abc"
lua_setfield(L,"x")??? <== mytable["x"] = "abc",pop value "abc"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读