summaryrefslogtreecommitdiff
path: root/script/locale-loader.lua
blob: 018da68065785123c3071dcc4dc8667ad80ef44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local function mergeKey(key, k)
    if not key then
        return k
    end
    if k:sub(1, 1):match '%w' then
        return key .. '.' .. k
    else
        return key .. k
    end
end

local function proxy(results, key)
    return setmetatable({}, {
        __index = function (_, k)
            return proxy(results, mergeKey(key, k))
        end,
        __newindex = function (_, k, v)
            results[mergeKey(key, k)] = v
        end
    })
end

return function (text, path, results)
    results = results or {}
    assert(load(text, '@' .. path, "t", proxy(results)))()
    return results
end