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 ...
lua_pushvalue(L, lua_upvalueindex(i+1));return2;caseLUA_TSTRING:/*as length operator*/if(*lua_tostring(L,1) =='#') { lua_pushinteger(L, n);return1; }break;caseLUA_TNONE:/*get all varargs*/luaL_checkstack(L, n,"too many values");for(i =1; i <= n; ++i) lua_pushvalue...
任何时候Lua调用C,都可以保证最少有LUA_MINSTACK个堆栈位置是可用 void lua_settop(lua_State* L,int index)//把堆栈的栈顶索引设置为指定的数值 #define lua_pop(L,n) lua_settop(L,-(n)-1)//用于把从栈顶开始的n个元素删除 void lua_pushvalue(lua_State* L,int index)//将栈上指定索引处的值...
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...
void lua_pushvalue (lua_State *L, int index); 把栈上给定索引处的元素作一个副本压栈。 */ lua_pushvalue(L, -1); /* void lua_replace (lua_State *L, int index); 把栈顶元素放置到给定位置而不移动其它元素(因此覆盖了那个位置处的值),然后将栈顶元素弹出 ...
} // 更新成功,从数组里剔除掉 lua_pushvalue(L, -2); lua_pushnil(L); lu...
// 创建一个协程对象 static int luaB_cocreate (lua_State *L) { lua_State *NL; // 第一个参数一定是一个函数对象 luaL_checktype(L, 1, LUA_TFUNCTION); // 新建线程 NL = lua_newthread(L); lua_pushvalue(L, 1); /* move function to top */ // 将函数对象转移到NL lua_xmove(L, NL...
lua_pushvalue# [-0, +1, –] void lua_pushvalue (lua_State *L, int index); 把栈上给定索引处的元素作一个副本压栈。 lua_pushvfstring# [-0, +1, e] const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp); 等价于 lua_pushfstring, 不过是用 va_list 接收参数...
//创建一个库table luaL_newlibtable(L, l); //压入一个upvalue 也就是这个表自身 lua_pushvalue(L, -1);//这句你可以注释掉测试一下,并且luaL_setfuncs最后一个参数设为0。 //为这个表注册函数 ,并且设置1个upvalue luaL_setfuncs(L, l, 1); //这个函数就有了这个libtable的环境(也就是upvalue) ...