Content deleted Content added
Artoria2e5 (talk | contribs) A mostly irrelevant util function... |
Artoria2e5 (talk | contribs) Implement loop protection |
||
Line 6:
local oldArgsMeta = getmetatable(args) or {}
local newArgsMeta = {}
-- Forget about thread-safety.
local referencedKeys = {} -- dataType:Set/hashtable-impl
-- Start the new metatable as a copy of the old metatable.
for k, v in ipairs(oldArgsMeta) do
-- My friend, why are you here again?
-- Try the old metamethod first.▼
if referencedKeys[k] then
-- Thanks to closures, this whole oldArgsMeta object will stay.▼
-- You have to be drunk. Go home.
if oldArgsMeta.__index ~= nil then▼
local val = oldArgsMeta.__index(t, k)▼
if val ~= nil then▼
referencedKeys[k] = true
▲ return val
referencedKeys = {}
return val
end
end
-- Now try use the aliases given.
for _, v in ipairs(arg_aliases[k] or {}) do
-- If a working value is found, use it.
-- Note: mw-argument-specific empty str chk.
if t[v] ~= nil
referencedKeys = {}
▲ end
return t[v]
end
end
return nil
|