ComponentLua内存错误,函数调用错乱

ComponentLua问题比较多,没有必要用,用老的reigsterScriptHandler完全可以覆盖

  1. 未找到函数时没有重置stack, 应该lua_pop(L, 1)弹出nil值:
//    if (type != LUA_TFUNCTION)
//    {
//        CCLOG("can not get %s function from %s", functionName.c_str(), _scriptFileName.c_str());
//    }
    
    return type == LUA_TFUNCTION;
  1. 把用户table的函数复制到所有ComponentLua共享的metatable上(代表ComponentLua这个类的metatable)导致重名函数调用错乱:
    参考:ComponentLua的Bug
    // add table's elements to userdata's metatable
    object_to_luaval<cocos2d::ComponentLua>(l, "cc.ComponentLua", this);  // stack: table_return_from_lua userdata
    lua_getmetatable(l, -1);                   // stack: table_return_from_lua userdata mt
    lua_remove(l, -2);                         // stack: table_return_from_lua mt
    lua_pushnil(l);                            // stack: table_return_from_lua mt nil
    while (lua_next(l, -3))                    // stack: table_return_from_lua mt key value
    {
        lua_pushvalue(l, -2);                  // stack: table_return_from_lua mt key value key
        lua_insert(l, -2);                     // stack: table_return_from_lua mt key key value
        lua_rawset(l, -4);                     // stack: table_return_from_lua mt key
    }

没用过这玩意。。。能问下这是干啥的嘛?

山寨unity的component系统:upside_down_face: