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
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 接收参数...
任何时候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_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_pushvalue函数Notice lua_pushvalue [-0, +1,-] void lua_pushvalue (lua_State *L, int index); Pushes a copy of the element at the given valid index onto the stack 如上所述, lua_pushvalue(L, -4) 并不是往栈顶插入元素-4, 而是把在栈中位置为-4的元素copy之后插入于栈顶中!!!
lua_pushvalue(L, -1); /* duplicate it */ lua_replace(L, lua_upvalueindex(1)); return 1; } lua_upvaluesindex(1) ,就是取出upvalues值,其索引为第一个参数。 由于这个参数并不是堆栈中索引,而是仅仅表示参数序位的索引,即,取出 upvalue的当前值。
// 创建一个协程对象 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...
//创建一个库table luaL_newlibtable(L, l); //压入一个upvalue 也就是这个表自身 lua_pushvalue(L, -1);//这句你可以注释掉测试一下,并且luaL_setfuncs最后一个参数设为0。 //为这个表注册函数 ,并且设置1个upvalue luaL_setfuncs(L, l, 1); //这个函数就有了这个libtable的环境(也就是upvalue) ...
lua_pushvalue (L , - 2 ); lua_rawset (L , - 4 ); } //往getttag表中写入数据 key:name value:get lua_pushstring ( L, name); //lua_pushcfunction(L, get); tolua_pushcclosure ( L, get); lua_rawset (L , - 3 ); /* store variable */ ...