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 by s with size len onto the stack. // B
lua_rawget(L, -);    // lua_rawget(): Similar to lua_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的更多相关文章

  1. Lua.LearningLua.7-userdata

    Learning Lua: 7 - userdata 1. Userdata basic "There are eight basic types in Lua: nil, boolean, ...

  2. 苹果手机浏览器$(document).on(“click”,function(){})点击无效的问题

    <label class="js_highlight" style="display: inline-block;float: left;width: 50%;&q ...

  3. 苹果手机浏览器的$(document).on(“click”,function(){}) 绑定的事件点击无效

    需要给对应的元素加上 cursor: pointer  的css样式才可以生效点击事件:

  4. $(document).ready(){}、$(fucntion(){})、(function(){})(jQuery)onload()的区别

     1.首先说JQuery的几个写法  $(function(){     //do someting   });   $(document).ready(function(){     //do so ...

  5. JQuery $(function(){})和$(document).ready(function(){})

    document.ready和onload的区别——JavaScript文档加载完成事件页面加载完成有两种事件一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件)二是onload,指 ...

  6. $(function(){})和$(document).ready(function(){})

    document.ready和onload的区别——JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二是onloa ...

  7. jquery的 $(function(){ }) = $(document).ready(function(){ }) ,及页面的加载顺序

    document.ready和onload的区别:一.JavaScript文档加载完成事件页面加载完成有两种事件一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二.是onloa ...

  8. Lua function 函数

    Lua支持面向对象,操作符为冒号‘:’.o:foo(x) <==> o.foo(o, x). Lua程序可以调用C语言或者Lua实现的函数.Lua基础库中的所有函数都是用C实现的.但这些细 ...

  9. $(function(){})和$(document).ready(function(){}) 的区别

    document.ready和onload的区别——JavaScript文档加载完成事件 页面加载完成有两种事件 一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件) 二是onloa ...

随机推荐

  1. 3D Touch集成过程整理

    1.集成App图标按压快速打开某个功能 在AppDelegate.m中加入以下三个东西 在启动方法里加入3D Touch菜单 - (BOOL)application:(UIApplication *) ...

  2. ROC曲线

    1.混淆矩阵(confusion matrix)     针对预测值和真实值之间的关系,我们可以将样本分为四个部分,分别是:     真正例(True Positive,TP):预测值和真实值都为1 ...

  3. js json排序

    var p = [             {name:"kitty", age:12},             {name:"sonny", age:9}, ...

  4. linux 下 文件权限和文件主

    文件与文件夹的权限和所有者 1.chmod -R 755 file 777 含义与来源: 777含义:分别为:所有者.同组用户.其他用户 7的来源:文件有三种操作模式:读4.写2.执行1,分别值为42 ...

  5. time.h-------日期与时间函数

    1.clock函数----返回CPU计时单元.函数返回开启这个程序进程到程序中调用clock函数时之间的CPU时钟计时单元(返回毫秒). (计的是占用cpu的时间) 函数原型:long clock() ...

  6. ModelAttribute注解

    1.使用@ModelAttribute标记方法,会在每个目标方法执行前被springMVC调用 2.使用@ModelAttribute修饰目标方法pojo入参,其value属性值有以下作用: 1)sp ...

  7. C Primer Plus(第五版)12

    第 12 章 存储类, 链接和内存管理 在本章中你将学习下列内容 . 关键字: auto, extern, static, register, const, volatile, restricted. ...

  8. jmeter的逻辑控制器

    这篇是在网上找的,写的实在是比我写的具体得多,也没什么好补充的,拿来记录一下,方便以后查询,感激原作者!! JMeter中的Logic Controller分为两类:一类用来控制Test Plan执行 ...

  9. eclipse配置javacv0.8

    之前配置了一次javacv,但是忘了做笔记,这次又重新查了一遍资料,很多东西模棱两可,浪费了很多时间,这次配置成功,总结如下,希望能帮到大家. 如不明确,可以联系我.   javacv下载 https ...

  10. C++学习基础九——继承

    1.不同于Java中通过extends实现继承,C++是通过:实现的. 2.C++中同样包含public,private,protected三个关键字: public关键字表示在任意其他类中可调用该成 ...