本帖最后由 蜗牛 于 2022-1-23 18:13 编辑
这样??
- function clone(object)
- local lookup_table = {}
- local function _copy(object)
- if type(object) ~= "table" then
- return object
- elseif lookup_table[object] then
- return lookup_table[object]
- end
- local newObject = {}
- lookup_table[object] = newObject
- for key, value in pairs(object) do
- newObject[_copy(key)] = _copy(value)
- end
- return setmetatable(newObject, getmetatable(object))
- end
- return _copy(object)
- end
- a={1,2,3,4,5,6}
- b={3,4,5,6}
- function aaa(w,e)
- local c = {}
- c = clone(b)
- local a = w b = e
- for k,v in pairs(a) do
-
- for k1,v1 in pairs(b) do
-
- if v1==v then
-
- table.remove(b,k1)
-
- end
-
- end
-
- end
- b = clone(c)
-
- end
- aaa(a,b)
- print(b)
- aaa(a,b)
- print(b)
复制代码
|