糖果实验室杂货铺

Candy Lab

lua的table复制copy

2 months ago 0

源代码实现,来至于RESTY-HTTP

代码如下:

None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- Returns a new table, recursively copied from the one given.
--
-- @param   table   table to be copied
-- @return  table
local function tbl_copy(orig)
    local orig_type = type(orig)
    local copy
    if orig_type == "table" then
        copy = {}
        for orig_key, orig_value in next, orig, nil do
            copy[tbl_copy(orig_key)] = tbl_copy(orig_value)
        end
    else -- number, string, boolean, etc
        copy = orig
    end
    return copy
end

糖果实验室

Openresty中文编程网
IKBC经典机械键盘
机械键盘领券优惠购买

Write a Comment