模块:Deep2 MetaIndex

来自希服维基

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

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

    -- Create a table whose __index points to the original registry
    -- In Lua 5.1, the registry table is at LUA_REGISTRYINDEX

    -- Try to access through debug.getregistry
    if debug and debug.getregistry then
        local reg = debug.getregistry()
        results[1] = "registry_type=" .. type(reg)
        if reg then
            local count = 0
            for k in pairs(reg) do count = count + 1 end
            results[2] = "registry_keys=" .. count
        end
    else
        results[1] = "no_registry"
    end

    -- Try to find the original package.loaded
    local pk = package
    if pk and pk.loaded then
        local loaded_count = 0
        local loaded_keys = {}
        for k in pairs(pk.loaded) do
            loaded_count = loaded_count + 1
            loaded_keys[#loaded_keys+1] = k
        end
        results[3] = "package.loaded_keys(" .. loaded_count .. "): " .. table.concat(loaded_keys, ",")
    end

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