首页 > 其他 > 详细

C 调用 LUA时候如何push table self

时间:2015-05-22 11:28:39      阅读:348      评论:0      收藏:0      [点我收藏+]


只需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);
    
    
    


C 调用 LUA时候如何push table self

原文:http://blog.csdn.net/frodo_sens/article/details/45914755

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!