lua table操作实例详解
2014-03-19 19:57
731 查看
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 table操作实例详解
- lua table操作实例详解
- lua table操作实例详解
- lua table操作实例详解 lua_gettable
- lua table 操作详解
- lua table操作详解
- tcltk实例详解——列表操作(一)
- python对json的相关操作实例详解
- C开发lua模块(二) --- 操作table和调用lua函数
- Python 文件读写操作实例详解
- seq命令详解太实例操作
- Mybatis笔记四:Mybatis中的resultType和resultMap查询操作实例详解
- Lua 操作 MongoDB 数据库实例
- 获取Lua表结构(table)数据实例
- 详解JSP中的语句对象Statement操作MySQL的使用实例
- Vue.js进行查询操作的实例详解
- 【Lua学习笔记】 --> 《字符串string与table的函数操作》
- PHP文件上传操作实例详解(包含上传文件类型MIME验证)
- VC操作word实例详解
- Servlet中操作文件详解及实例