lua_pushvalue:Pushes a copy of the element at the given valid index onto the stack ,也就是说复制指定索引的值到栈顶,指定索引的值不变,影响栈大小。 lua_remove:Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with ...
static int _counter (lua_State *L) { // //获取第一个upvalue // double val = lua_tonumber(L, lua_upvalueindex(1)); lua_pushnumber(L, ++val); /* void lua_pushvalue (lua_State *L, int index); 把栈上给定索引处的元素作一个副本压栈。 */ lua_pushvalue(L, -1); /* void lua_...
如果这个线程是当前状态机的主线程的话返回 1 。 lua_pushvalue## 原型:void lua_pushvalue (lua_State *L, int index); 解释:把堆栈上给定有效处索引处的元素作一个拷贝压栈。 lua_pushvfstring## 原型:const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp); 解释:等价于 ...
lua_pushnumber 压入的初始值0。 其中压入一个upvalues值,则在pushcclosure第三个参数个数则为1. 在函数中 static int counter (lua_State *L) { double val = lua_tonumber(L, lua_upvalueindex(1)); lua_pushnumber(L, ++val); lua_pushvalue(L, -1); /* duplicate it */ lua_replace(L, lu...
lua_pushvalue(L, -nup); ///这里将函数压入栈,这个函数我们前面分析过,他最终会把当前state的env赋值给新建的closure,也就是说这里最终模块内的所有函数都会共享当前的state的env。 lua_pushcclosure(L, l->func, nup); lua_setfield(L, -(nup+2), l->name); ...
lua_pushvalue(L,1); lua_insert(L, i+2);returnn +1; }staticintLremove(lua_State *L) {intn = lua_gettop(L) -1; lua_Integer i= posrelat(luaL_checkinteger(L,1), n);if(i <=n) { lua_remove(L, i+1);--n; }returnn; ...
} // 更新成功,从数组里剔除掉 lua_pushvalue(L, -2); lua_pushnil(L); lu...
lua_pushvalue(L, lua_upvalueindex(op)); return 1; /*有这个键值对,返回1个结果*/ } } //tuplelib中的一个函数 int t_new (lua_State *L) { //检测参数个数并进行处理 int top = lua_gettop(L); luaL_argcheck(L, top < 256, top, "too many fields"); ...
(3)函数lua_pushvalue用于将指定索引上的元素的副本压入栈。 (4)函数lua_rotate将指定索引的元素向栈顶转动n个位置。若n为正数,表示将元素向栈顶方向转动,而n为负数则表示向相反的方向转动。由此可实现lua_remove和lua_insert操作。 (5)函数lua_replace弹出一个值,并将栈顶设置为指定索引上的值,而不移动任何...