I want new and at to return the same userdata, please tell me how to do it
example code that I use
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 has different addresses, because of this new != at
local createdCheckpoint = mp.checkpoints.new()
print(createdCheckpoint.id)
local gettedCheckpoint = mp.checkpoints.at(0)
print(gettedCheckpoint.id)
print(createdCheckpoint, gettedCheckpoint, createdCheckpoint == gettedCheckpoint)
returned - 0 0 userdata: 0x34a8c320 userdata: 0x34a8d5b0 false