栈:(stack)—— 先进后出,删除与加入均在栈顶操作 堆栈中两个最重要的操作是PUSH和POP,两个是相反的操作。 PUSH:在堆栈的顶部加入一个元素。PUSH操作可以使用 table.insert(t,x) 实现 POP:在堆栈顶部移去一个元素, 并将堆栈的大小减一。可以使用 table.remove(t) 实现 -- 移动元素 table.move 可以移动元...
4. 建议传递:int float double 5.频繁调用的函数,参数的数量要控制,无论是lua的pushint/checkint,还是c到c#的参数传递,参数转换都是最主要的消耗,而且是逐个参数进行的,因此,lua调用c#的性能,除了跟参数类型相关外,也跟参数个数有很大关系。 6.优先使用static函数导出,减少使用成员方法导出 7.合理利用out关键字...
Stack: cl, "__tostring", cls_p -> +1lua_pushcclosure(L,ClassContentTableToString,1);// Stack: cl, "__tostring", l_class_content_table_tostringlua_rawset(L,-3);// Stack: cl// Bind class table to registry tablelua_pushvalue(L,-1);// Stack: cl, cllua_rawsetp(L,LUA_REGISTRYIN...
当C 函数被创建出来,我们有可能会把一些值关联在一起,也就是创建一个 C closure ;这些被关联起来的值被叫做 upvalue ,它们可以在函数被调用的时候访问的到。(参见 lua_pushcclosure)。 无论何时去调用 C 函数,函数的 upvalue 都被放在指定的伪索引处。我们可以用 lua_upvalueindex 这个宏来生成这些伪索引。第...
success = 0; } lua_pop(L, 1); } lua_pushboolean(L, success); ...
luaL_pushcfunction(L, &add_op); // 将要被调用的函数add_op入栈 luaL_pushinteger(L, 1); // 参数入栈 luaL_pushinteger(L, 1); luaL_pcall(L, 2, 1); // 调用add_op函数,并将结果push到栈中 int result = luaL_tointeger(L, -1); // 完成函数调用,栈顶就是add_op放入的结果 ...
}/* Push the pcall error handler function on the stack. */lua_getglobal(lua,"__redis__err__handler");// 根据函数名,在 Lua 环境中检查函数是否已经定义lua_getfield(lua, LUA_REGISTRYINDEX, funcname);// 如果没有找到对应的函数if(lua_isnil(lua,-1)) {lua_pop(lua,1);/* remove the nil...
29 char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT); 30 s++; /* skip '%' */ 31 s = checkoption(L, s, se - s, cc + 1); /* copy specifier to 'cc' */ 32 reslen = strftime(buff, SIZETIMEFMT, cc, stm); 33 luaL_addsize(&b, reslen); 34 } 35 } 36 luaL_pushresult...
对于已经push到lua的对象,如果想从C++解除引用,可以调用lua_detach(L, object); 对于嵌套的对象,可能会出现父子对象同地址的情况,在这种情况下,如果同时导出父子对象,那么需要谨慎处理好__gc()函数,以避免对象内存在GC时被重复删除. structplayerfinal{//通过自定义__gc函数,可以自行管理对象生命期,而不是自动被...
isTaskRoot()) {//Android launched another instance of the root activity into an existing task//so just quietly finish and go away, dropping the user back into the activity//at the top of the stack (ie: the last state of this task)//Don't need to finish it again since it's finished...