返回2个相同的用户数据

时间:2017-11-04 06:53:22

标签: c++ lua luabridge

我想要new和at返回相同的用户数据,请告诉我该怎么做

我使用的示例代码

struct SCheckpoint {

    rage::ICheckpoint* r_Checkpoint;

    SCheckpoint(rage::ICheckpoint* checkpoint) {
        r_Checkpoint = checkpoint;
    }

    int GetId() const {
        return r_Checkpoint->GetId();
    }
}

int createCheckpoint(lua_State* state) {
    rage::ICheckpoint* checkpoint = RaluCore::getInstance().getMultiPlayer()->GetCheckpointPool().New(model, vec, vec, radius, color, defaultShow, dimension);

    SCheckpoint* scriptCheckpoint = new SCheckpoint(checkpoint);
    checkpoint->External(scriptCheckpoint);

    push(state, scriptCheckpoint);
    return 1;
}

int atCheckpoint(lua_State* state) {

    LuaRef ref = LuaRef::fromStack(state, 1);

    rage::ICheckpoint* checkpoint = RaluCore::getInstance().getMultiPlayer()->GetCheckpointPool().GetAt(ref);
    SCheckpoint* scriptCheckpoint = checkpoint->External<SCheckpoint>();
    push (state, scriptCheckpoint);
    return 1;
}

getGlobalNamespace(state)
    .beginClass<SCheckpoint>("SCheckpoint")
        .addProperty("id", &SCheckpoint::GetId)
    .endClass()

    .addCFunction("at", &atCheckpoint)
    .addCFunction("new", &createCheckpoint);

userdata有不同的地址,因为这个新的!= at

local createdCheckpoint = mp.checkpoints.new()
print(createdCheckpoint.id)

local gettedCheckpoint = mp.checkpoints.at(0)

print(gettedCheckpoint.id)

print(createdCheckpoint, gettedCheckpoint, createdCheckpoint == gettedCheckpoint)

返回 - 0 0 userdata:0x34a8c320 userdata:0x34a8d5b0 false

0 个答案:

没有答案