This commit is contained in:
2025-06-30 00:25:43 +08:00
parent 20269c25b3
commit fa75dff380
7 changed files with 754 additions and 10 deletions

View File

@@ -377,3 +377,50 @@ function Rindro_GetEquAddr(addr) {
//本地模式
if(!getroottable().rawin("RINDROLOCAL"))RINDROLOCAL <- false;
function deepcopy(obj) {
local copies = {}; // 用于跟踪已拷贝对象的表
return _deepcopy(obj, copies);
}
function _deepcopy(obj, copies) {
local type = typeof obj;
// 处理基本类型
if (type != "table" && type != "array" && type != "class" && type != "instance") {
return obj;
}
// 处理循环引用
if (obj in copies) {
return copies[obj];
}
// 创建新容器
local newObj;
if (type == "array") {
newObj = array(obj.len());
copies[obj] <- newObj; // 在拷贝前记录
for (local i = 0; i < obj.len(); i++) {
newObj[i] = _deepcopy(obj[i], copies);
}
}
else if (type == "table") {
newObj = {};
copies[obj] <- newObj; // 在拷贝前记录
foreach(key, val in obj) {
// 键也需要深拷贝
local newKey = _deepcopy(key, copies);
local newVal = _deepcopy(val, copies);
newObj[newKey] <- newVal;
}
}
else { // 类和实例(浅拷贝)
newObj = obj;
copies[obj] <- newObj;
}
return newObj;
}