وحدة:Argument Wrapper
توثيق الوحدة [أنشئ] [محو الاختزان][استخدامات] [قوالب]
-- Call only from modules
-- forked from [[module:Citation/CS1]]
return function (aliases, arglists )
local origin = {};
local nilargs = {};
return setmetatable({
ORIGIN = function ( self, k )
local dummy = self[k]; -- force the variable to be loaded.
return origin[k];
end
},
{
__index = function ( tbl, k )
local v = rawget(tbl,k)
if v then
return v
elseif nilargs[k] then
return nil
end
local list = (type(k)=="number") and k or aliases[k];
for _,arglist in ipairs(arglists) do
if type( list ) == 'table' then
for _, alias_key in pairs( list ) do
if arglist[alias_key] then
v = arglist[alias_key]
origin[k] = alias_key
break;
end
end
elseif list ~= nil then
v = arglist[list]
if v then
origin[k] = list
end
end
if v then
break;
end
end
if v == nil then
nilargs[k] = true
else
rawset( tbl, k, v )
end
return v
end,
});
end