Lua Module

;How to create a Lua Module
A module needs an opening and closing. It is labelled as p
local p = {}
 
return p
A module needs an opening and closing function
local p = {}
 
function
end
 
return p
A module needs a function label. It is included in the #explode to switch it on. It is labelled as city → {{#invoke:CityResource|city}}
local p = {}
 
function p.city( frame )
 
end
 
return p
The function has a step-by-step progress
local p = {}
 
function p.city( frame )
 local cityData = mw.loadData( 'Module:City/data' )
 local cityName = frame.args[1]
 local cityResource = cityData[cityName]
 local tab = mw.text.split( cityResource, " ")
 
 
end
 
return p
* cityData → stores the data via Module:City/data
* cityName → is the variable in the #explode to pick individual item from cityData → {{#invoke:CityResource|city|Jacksonville}}
** city → is function p.city( frame )
** Jacksonville → is frame.args[1]
* cityResource → joins cityData and cityName together to select the switch word → Jacksonville
* tab → with cityResource joining cityData and cityName together, tab informs the data in Module:City/data is split by a space → mw.text.split( cityResource, " ")
A module needs a return to activate the function
local p = {}
 
function p.city( frame )
 local cityData = mw.loadData( 'Module:City/data' )
 local cityName = frame.args[1]
 local cityResource = cityData[cityName]
 local tab = mw.text.split( cityResource, " ")
 
 return (tab[1])
 
end
 
return p
* return (tab[1]) → with cityResource joining cityData and cityName together, (tab[1]) informs that cityResource is the 1st column data
category:Lua