• 您还可以去尝试使用本站的安卓客户端,在手机上方便的浏览H萌娘!
  • 模块:Var

    From H萌娘
    Jump to: navigation, search
    Template-info.svg 模块文档  [创建] [刷新]
    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