Module:Data/sandbox

From Yugipedia
< Module:Data
Revision as of 00:40, 23 December 2019 by Becasita (talk | contribs) (Forgot to apply the latest changes.)
Jump to: navigation, search
-- <pre>
local methods = mw.loadData( 'Module:Data/methods' )

return setmetatable( {}, {
	__index = function( self, key ) -- only if it doesn't contain the key
		local subModule = methods[ key ]

		if not subModule then
			-- Let it explode on the calling code, just like it would
			-- if all of the functions were explicitly declared.
			return nil
		else
			rawset( self, key, require( 'Module:Data/' .. subModule ) )

			return rawget( self, key )
		end
	end,

	__call = function( self, moduleName )
		return require( 'Module:Data/static/' .. moduleName .. '/data' ).main;
	end,
} )
-- </pre>