C 调用 LUA时候如何push table self

来源:互联网 发布:网络性能测试 编辑:程序博客网 时间:2024/05/18 00:06


只需lua_pushvalue(L, -2) 即可

-2 就是 相对table的位置


void FSLuaChannel::call_local_method( const FSMethod* method, FSParams* params ){            auto engine = cocos2d::LuaEngine::getInstance();    cocos2d::ScriptEngineManager::getInstance()->setScriptEngine(engine);    lua_State* L = engine->getLuaStack()->getLuaState();            lua_getglobal(L, "_global_channels");        int top = lua_gettop(L);        if(lua_istable(L, -1)){                lua_getfield(L, -1, this->uuid().c_str());                if(lua_istable(L, -1)){                        lua_getfield(L, -1, method->name().c_str());                        if(lua_isfunction(L, -1)){                                                lua_pushvalue(L, -2);                __push_params(L, params, false, false);                                lua_pcall(L, 1 + params->size(), 0, 0);                            }                    }                    }        lua_settop(L, top);            


0 0