lua table操作实例详解 lua_gettable
来源:互联网 发布:遇上网络诈骗怎么办 编辑:程序博客网 时间:2024/05/22 10:52
lua table操作实例详解
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, "mytable") <== push mytable
lua_pushnumber(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, -1, "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, "mytable") <== push mytable
lua_pushstring(L, "abc") <== push value "abc"
lua_setfield(L, -2, "x") <== mytable["x"] = "abc", pop value "abc"
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, "mytable") <== push mytable
lua_pushnumber(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, -1, "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, "mytable") <== push mytable
lua_pushstring(L, "abc") <== push value "abc"
lua_setfield(L, -2, "x") <== mytable["x"] = "abc", pop value "abc"
0 0
- lua table操作实例详解 lua_gettable
- lua table操作实例详解
- lua table操作实例详解
- lua table操作实例详解
- lua table操作实例详解
- lua 中 lua_gettable的使用 C++ 调用lua 读取table
- lua table操作详解
- lua_gettable详解
- 【Lua】Lua中的Table操作
- lua table操作
- Lua table 详解
- LUA loadstring table sort实例
- LUA-TABLE数据类型的操作
- Lua基础之table详解
- Lua基础之table详解
- Lua中对table排序实例
- Lua操作详解
- Lua栈操作详解
- ios 内存管理
- ping命令
- 科普:SDN(软件定义网络)
- windows xp 待机
- zhangenmingLKR
- lua table操作实例详解 lua_gettable
- 解决方法:Ubuntu12.04安装Qt5.0后,首次运行,编译失败,提示 can`t find -Igl
- IOS 推送服务--Apple Push Notification Service
- POJ2186----Popular Cows(强连通+缩点)
- 通用的Java hashCode重写方案
- 请教关于pack的使用方法
- OpenGL学习三十八:图片文字
- VS2010ActiveX在主对话框弹出的模态对话框里怎么使用主对话框的数据
- 安装了VFP9.0,连编时出现项目文件.PJT缺少或无效而无法连编