Difference between revisions of "Module:Data/sandbox"

From Yugipedia
Jump to: navigation, search
(Test new format for data.)
(Tag: Replaced)
(Forgot to apply the latest changes.)
Line 17: Line 17:
 
end,
 
end,
  
__call = function( self, modulePath )
+
__call = function( self, moduleName )
return require( 'Module:Data/' .. modulePath ).main;
+
return require( 'Module:Data/static/' .. moduleName .. '/data' ).main;
 
end,
 
end,
 
} )
 
} )
 
-- </pre>
 
-- </pre>

Revision as of 00:40, 23 December 2019

-- <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>