Lua.LearningLua.5-document-for-luaL_findtable-function
Learning Lua: 5 - Document for luaL_findtable() function
文档中没有找到luaL_findtable()函数的说明,这里尝试补充。
LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
const char *fname, int szhint);
@brief
luaL_findtable()在由参数idx标识的target-table中查找名字为fname的table。 fname支持"tableA.tableB.tableC"这种
级联的方式来命名要查找的table,其中在target-table中以"tableA"为key的field的值需要是table类型,否则会返回"tableA"。
@parameters
L: lua_State
idx: target-table在lua_State对象L中的位置
fname: 在target-table中所要查找的table的名字。支持"GrandfatherTableName.ParentTableName.TableName"这种形式。
szhint: 如果查找的table不存在,则会新创建fname对应的table,szhint是创建新table时non-array elements的提示值。参见"lua_createtable()"。
@return
成功:返回NULL; L中的top位置(即: -1的位置)会保留找到的table。
异常:返回fname中有问题的部分; L 会被复原为调用luaL_findtable()前的状态。
luaL_findtable()代码如下:
LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
const char *fname, int szhint) {
const char *e;
lua_pushvalue(L, idx); // lua_pushvalue(): Pushes a copy of the element at the given valid index onto the stack. // A
do {
e = strchr(fname, '.');
if (e == NULL) e = fname + strlen(fname);
lua_pushlstring(L, fname, e - fname); // lua_pushlstring(): Pushes the string pointed to bys
with sizelen
onto the stack. // B
lua_rawget(L, -); // lua_rawget(): Similar tolua_gettable
, but does a raw access // C
if (lua_isnil(L, -)) { /* no such field? */
lua_pop(L, ); /* remove this nil */
lua_createtable(L, , (*e == '.' ? : szhint)); /* new table for field */ // D
lua_pushlstring(L, fname, e - fname);
lua_pushvalue(L, -);
lua_settable(L, -); /* set new table into field */ // E
}
else if (!lua_istable(L, -)) { /* field has a non-table value? */
lua_pop(L, ); /* remove table and value */
return fname; /* return problematic part of the name */
}
lua_remove(L, -); /* remove previous table */ // F
fname = e + ;
} while (*e == '.');
return NULL;
}
lua_gettable()
void lua_gettable (lua_State *L, int index);
"Pushes onto the stack the value t[k]
, where t
is the value at the given valid index and k
is the value at the top of the stack.
This function pops the key from the stack (putting the resulting value in its place). As in Lua, this function may trigger a metamethod for the "index" event " Ref[1]
lua_createtable()
void lua_createtable (lua_State *L, int narr, int nrec);
"Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr
array elements and nrec
non-array elements." Ref[1]
lua_settable()
void lua_settable (lua_State *L, int index);
"Does the equivalent to t[k] = v
, where t
is the value at the given valid index, v
is the value at the top of the stack, and k
is the value just below the top.
This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event" Ref[1]
lua_remove()
void lua_remove (lua_State *L, int index);
"Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position." Ref[1]
Reference
1. http://www.lua.org/manual/5.1/manual.html
Lua.LearningLua.5-document-for-luaL_findtable-function的更多相关文章
- Lua.LearningLua.7-userdata
Learning Lua: 7 - userdata 1. Userdata basic "There are eight basic types in Lua: nil, boolean, ...
- 苹果手机浏览器$(document).on(“click”,function(){})点击无效的问题
<label class="js_highlight" style="display: inline-block;float: left;width: 50%;&q ...
- 苹果手机浏览器的$(document).on(“click”,function(){}) 绑定的事件点击无效
需要给对应的元素加上 cursor: pointer 的css样式才可以生效点击事件:
- $(document).ready(){}、$(fucntion(){})、(function(){})(jQuery)onload()的区别
1.首先说JQuery的几个写法 $(function(){ //do someting }); $(document).ready(function(){ //do so ...
- JQuery $(function(){})和$(document).ready(function(){})
document.ready和onload的区别——JavaScript文档加载完成事件页面加载完成有两种事件一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件)二是onload,指 ...
- $(function(){})和$(document).ready(function(){})
document.ready和onload的区别——JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二是onloa ...
- jquery的 $(function(){ }) = $(document).ready(function(){ }) ,及页面的加载顺序
document.ready和onload的区别:一.JavaScript文档加载完成事件页面加载完成有两种事件一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二.是onloa ...
- Lua function 函数
Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...
- $(function(){})和$(document).ready(function(){}) 的区别
document.ready和onload的区别——JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二是onloa ...
随机推荐
- maya,mel,eval,stringarray
mel里,当要eval("client()"),并且要传递stirngarray参数给函数client()时,正确的写法应该是: global proc intermediator ...
- 使用springMVC实现文件上传和下载之环境配置与上传
最近的项目中用到了文件的上传和下载功能,任务分配给了其他的同时完成.如今项目结束告一段落,我觉着这个功能比较重要,因此特意把它提取出来自己进行了尝试. 一. 基础配置: maven导包及配置pom.x ...
- 黄聪:jquery 校验中国身份证号码
大陆18位身份证(第二代身份证) 身份号码是一组具有特征组合码,由十七位数字本体码和一位校验码组成. 排列顺序从左至右依次为:六位数字地区码,八位数字生日码,三位数字顺序码和一位数字校验码. 校验方法 ...
- [jQuery]html(),text(),val()方法的区别
1.HTML html():取得第一个匹配元素的html内容.这个函数不能用于XML文档.但可以用于XHTML文档 html(val):设置每一个匹配元素的html内容.这个函数不能用于XML文档.但 ...
- Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations
题意: 对于一个长度为n的排列P,如果P在所有长度为n的排列中,按照字典序排列后,在第s位,则P的value为s 现在给出一个长度为n的排列P,P有一些位置确定了,另外一些位置为0,表示不确定. 现在 ...
- ORM框架
半自动:iBATIS是一个半自动化的ORM框架,需要通过配置方式指定映射SQL语句 全自:由框架本身生成(如Hibernate自动生成对应SQL来持久化对象),即Hibernate属于全自动ORM框架 ...
- linux 多个python版本的切换
源码安装新的python版本,我的安装路径: /usr/self/Python3.5.2 修改软链接到你所安装的python版本中: 默认python命令是在/usr/bin/目录下 1 sudo m ...
- pyhon之对memcached及redis操作
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...
- 44. 普通对象建一个用户方法,提交时报:失败:建立业务逻辑对象失败:业务逻辑定义更新到数据库失败:ORA-00904: "DEFVERSION": 标识符无效
LBBIZPROCESSDEFSLBHISTORYBIZPROCESSDEFSLBHISTORYMULTIWFDEFSDESIGNLBHISTORYWORKFLOWDEFSDESIGNLBMULTIW ...
- 比较一下Linux下的Epoll模型和select模型的区别
一. select 模型(apache的常用) 1. 最大并发数限制,因为一个进程所打开的 FD (文件描述符)是有限制的,由 FD_SETSIZE 设置,默认值是 1024/2048 ,因此 Sel ...