模块:Deep2 MetaString

来自希服维基

可在模块:Deep2 MetaString/doc创建此模块的帮助文档

local p = {}
function p.test()
    local results = {}

    -- Can we set metatable on any type?
    local types = {"string", "number", "boolean", "function", "table"}
    for _, t in ipairs(types) do
        local val
        if t == "string" then val = "test"
        elseif t == "number" then val = 42
        elseif t == "boolean" then val = true
        elseif t == "function" then val = function() end
        elseif t == "table" then val = {}
        end
        local ok, err = pcall(setmetatable, val, {})
        results[#results+1] = t .. "=" .. tostring(ok) .. ":" .. tostring(err)
    end

    return table.concat(results, " | ")
end
return p