- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Difference between revisions of "Module:Equipment"
Jump to navigation
Jump to search
com>Ckwng (add __call metamethod) |
com>Ckwng |
||
Line 10: | Line 10: | ||
function Equipment:create(name) | function Equipment:create(name) | ||
− | if equipments[name] then | + | if name == nil then |
+ | return EquipmentData() | ||
+ | elseif equipments[name] then | ||
return equipments[name] | return equipments[name] | ||
else | else | ||
local equipment_table = require(mw.ustring.format('Module:%s', name)) | local equipment_table = require(mw.ustring.format('Module:%s', name)) | ||
− | local equipment = EquipmentData | + | local equipment = EquipmentData(equipment_table) |
equipments[name] = equipment | equipments[name] = equipment | ||
return equipment | return equipment |
Revision as of 19:19, 27 February 2015
Documentation for this module may be created at Module:Equipment/doc
local Equipment = {}
local equipments = {}
local EquipmentData = require('Module:EquipmentData')
function Equipment:get(stat, name)
return self:create(name)[stat]()
end
function Equipment:create(name)
if name == nil then
return EquipmentData()
elseif equipments[name] then
return equipments[name]
else
local equipment_table = require(mw.ustring.format('Module:%s', name))
local equipment = EquipmentData(equipment_table)
equipments[name] = equipment
return equipment
end
end
Equipment.__call = Equipment.create
setmetatable(Equipment, Equipment)
return Equipment