Module:VoiceActor

Revision as of 07:23, 3 August 2016 by com>Ckwng

Documentation for this module may be created at Module:VoiceActor/doc

local VoiceActor = {}

local voice_actors = {}

local VoiceActorData = require('Module:VoiceActorData')

function VoiceActor:get(stat, name)
	return self:create(name)[stat]()
end

function VoiceActor:create(name)
	if name == nil then
		return VoiceActorData()
	--check if we already have it
	elseif voice_actors[name] then
		return voice_actors[name]
	else
		--Catch a failed require
		local success, voice_actor_table = pcall(function () return require(self:get_module(name)) end)
		--require failed
		if not success then
			--create a VoiceActorData with what we have
			voice_actor_table = {_name = name}
		end
		local voice_actor = VoiceActorData(voice_actor_table)
		voice_actors[name] = voice_actor
		return voice_actor
	end
end

function VoiceActor:get_module(name)
	if name == nil then
		return nil
	end
	return mw.ustring.format('Module:VoiceActor/%s', name)
end

function VoiceActor:extend(data)
	data = data or {}
	setmetatable(data, data)
	data.__index = self
	data.__call = self.__call
	return data
end

VoiceActor.__call = VoiceActor.create
setmetatable(VoiceActor, VoiceActor)

return VoiceActor