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_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 关键特性 Upvalue:闭包所引用的变量 _ENV:提供沙盒功能,包含数据 函数的 Upvalue ...
任何时候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# [-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_pushvalue(L, -1); /* void lua_replace (lua_State *L, int index); 把栈顶元素放置到给定位置而不移动其它元素(因此覆盖了那个位置处的值),然后将栈顶元素弹出 */ lua_replace(L, lua_upvalueindex(1)); return 1; /* return new value */ ...
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之后插入于栈顶中!!!
// 创建一个协程对象 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...
(void*)&cls);// Stack: cl, "__index", clslua_pushvalue(L,-3);// Stack: cl, "__index", cls, cllua_pushcclosure(L,LuaCFunctions::StaticMemberMetaIndex,2);// Stack: cl, "__index", get_static_funclua_rawset(L,-3);// Stack: cl// Help namelua_pushliteral(L,"__tostring")...
void lua_pushvalue (lua_State *L, int index); 拷贝栈中指定索引处的元素并压入栈中 void lua_rotate (lua_State *L, int index, int n); 把从index 开始到栈顶的元素轮转 n 个位置。 对于 n 为正数时,轮转方向是向栈顶的; 当 n 为负数时,向栈底方向轮转 n 个位置 ...