模組:沙盒/Cwek/NavboxV2/Context
来自维基百科,自由的百科全书
![文档图示](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
local NavboxContext={}
--[[local NavboxContext_Remove=function(_obj,key)
_obj["_Context"][tostring(key)]=nil
end]]
local NavboxContextNewObj=function(_prefix,_level,_type)
return {
prefix = _prefix
,level = _level
,type = _type
,_Context={}
}
end
local NavboxContextMetaFunction={
__index=function(_obj,key)
local _key = tostring(key)
if _key=='prefix' or _key =='level' or _key =='type' then
return _obj[_key]
else
return _obj._Context[_key]
end
end
,__newindex=function(_obj,key,val)
local _key = tostring(key)
if _key=='prefix' or _key =='level' or _key =='type' then
_obj[_key]=val
else
_obj._Context[_key]=val
end
end
,__tostring=function(_obj)
local output={}
table.insert(output,'prefix='.._obj.prefix)
table.insert(output,'level='.._obj.level)
table.insert(output,'type='.._obj.type)
for k,v in pairs(_obj._Context) do
table.insert(output,k..'='..v)
end
return 'context:{\n'..table.concat(output,",\n")..'\n}'
end
}
NavboxContext.new=function(prefix,level,_type)
local _prefix = prefix or ""
local _level = level or 1
local newobj=NavboxContextNewObj(_prefix,_level,_type or '')
setmetatable(newobj,NavboxContextMetaFunction)
--[[function newobj:remove(key)
mw.log(self)
NavboxContext_Remove(self,key)
end]]
return newobj
end
return NavboxContext
Wikiwand in your browser!
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.