• 近期没有账户的用户将会被禁止编辑。我们强烈推荐您创建一个账户或是使用共享账户
  • 公用账号用户名及密码:用户名:Shared_Account 密码:hmoe520502

Module:Var

H萌娘,万物皆可H的百科全书!
imported>850710247liu2020年1月29日 (三) 09:46的版本 (创建页面,内容为“local frame = mw.getCurrentFrame() local module = { getPlain = function(key, type) if type then type = '_'..type else type = '' end return frame:call…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索
模块文档  [创建] [刷新]
local frame = mw.getCurrentFrame()

local module = {
  getPlain = function(key, type)
	if type then
  		type = '_'..type	
	else
		type = ''
	end
   return frame:callParserFunction("#var"..type, tostring(key))
  end,
  
  set = function(key, val)
    frame:callParserFunction("#vardefine", tostring(key), tostring(val))
    return val
  end
}

module.get = function(key, type)
	local val = module.getPlain(key, type)
	if val == '' then return nil end
	if val:find('^0') then return val end
	if tonumber(val) then return tonumber(val) end
	if var == 'true' then return true end
	if var == 'false' then return false end
	return val
end

module.remove = function(key)
  local removedVal = module.getPlain(key)
  module.set(key, "")
  return removedVal
end

return module