How to create a Lua database

1) Create the database 
* -- → will not break the module and can be used for column narrative
* switchword is put inside → ["switchword"]
* data is put inside → "data", → with comma at end
* split must be consistent. if single space is used, lining up data with multi-space will break Lua
-- ar dw power speed slide mass bal aiv
 
return {
 ["166 MM"] = "6.0 40 850 60 0.5 400 0.95 5.5",
 ["208 GTB-t"] = "5.2 80 1485 65 0.125 605 1.05 5.5",
 ["250 GTO"] = "4.5 80 1450 65 0.4 630 1.15 5.5",
 ["250 GT SWB"] = "6.0 60 950 60 0.5 430 0.95 5.5",
 ["288 GTO"] = "4.7 80 1520 65 0.2 610 1.05 5.5",
 ["312 P"] = "4.8 80 1350 65 0.1 600 1.05 4.0",
 ["330 GTC"] = "5.6 65 1150 65 0.25 635 1.05 5.5",
 ["330 GT 2+2"] = "5.7 65 1150 65 0.35 655 1.05 5.5",
 ["330 P4"] = "5.0 80 1350 65 0.05 600 1.025 4.0",
 ["348 GTB"] = "5.3 80 1520 65 0.05 620 1.1 5.5",
 ["360 Modena"] = "5.0 85 1600 65 0 635 1.075 5.5",
 ["365 GT 2+2"] = "5.7 65 1200 65 0.35 660 0.975 5.5",
 ["365 GTB4"] = "5.5 80 1500 65 0.3 650 0.95 5.5",
 ["365 GTC4"] = "5.5 80 1450 65 0.3 660 0.925 5.5",
 
}
Module:GeneRally/data
2) Create switch 
Lua is expecting a single data value so need a switch. Names are used for indentification purposes
* p.ferrari → this is Ferrari database
* ferrariData → this is the Ferrari data
* ferrariText → this is the Ferrari model
local p = {}
 
function p.ferrari( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariText = frame.args[1]
 
 return ferrariData[ferrariText] or ""
end
 
return p
Module:GeneRally
3) Create split 
Lua is expecting a single data value so need to split it into individual data
# ar → Air Resistance
# df → Downforce
# power → Power
# ts → Top Speed
# slide → Sliding
# mass → Mass
# balance → Balance
# av → AI Value
Names are used for indentification purposes
* Module:Performance → this data is for Car Performance
* ferrariData → this is the Ferrari data
* ferrariModel → this is the Ferrari model
* ferrariSplit → the data is split by → " "
local p = {}
 
function p.ar( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[1])
 
end
 
function p.df( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[2])
 
end
 
function p.power( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[3])
 
end
 
function p.ts( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[4])
 
end
 
function p.slide( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[5])
 
end
 
function p.mass( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[6])
 
end
 
function p.balance( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[7])
 
end
 
function p.av( frame )
 local ferrariData = mw.loadData( 'Module:GeneRally/data' )
 local ferrariModel = frame.args[1]
 local ferrariSplit = ferrariData[ferrariModel]
 local tab = mw.text.split( ferrariSplit, " ")
 
 return (tab[8])
 
end
 
return p
Module:Performance
4) Insert module into infobox or table 
* module format → {{#invoke:modulename|dataname|switchword}}
* example → {{#invoke:Performance|ar|166 MM}} → 
5) Example template 
Puts data into a row
|-
! style="text-align:left; padding-left:15px"| {{{1}}}
| {{#invoke:Performance|ar|{{{1}}}}}
| {{#invoke:Performance|df|{{{1}}}}}
| {{#invoke:Performance|power|{{{1}}}}}
| {{#invoke:Performance|ts|{{{1}}}}}
| style="text-align:left; padding-left:20px"| {{#invoke:Performance|slide|{{{1}}}}}
| {{#invoke:Performance|mass|{{{1}}}}}
| style="text-align:left; padding-left:20px"| {{#invoke:Performance|balance|{{{1}}}}}
| {{#invoke:Performance|av|{{{1}}}}}
6) Example table 
{| class="wikitable sortable" style="width:100%; text-align:center"
|- valign=top
! FerrariSeries  !! width=10%| AirResistance !! width=10%| Downforce  !! width=10%| Power   !! width=10%| TopSpeed  !! width=10%| Sliding   !! width=10%| Mass   !! width=10%| Balance   !! width=10%| AIValue 
{{Performance|166 MM}}
{{Performance|208 GTB-t}}
{{Performance|250 GTO}}
{{Performance|250 GT SWB}}
{{Performance|288 GTO}}
{{Performance|312 P}}
{{Performance|330 GTC}}
{{Performance|330 GT 2+2}}
{{Performance|330 P4}}
{{Performance|348 GTB}}
{{Performance|360 Modena}}
{{Performance|365 GT 2+2}}
{{Performance|365 GTB4}}
{{Performance|365 GTC4}}
|}
FerrariSeries 	AirResistance	Downforce 	Power  	TopSpeed 	Sliding  	Mass  	Balance  	AIValue 
Category:Lua