Template:LuaCodeToAccessCSVDataTemplates: Difference between revisions

From Against the Storm Official Wiki
(Created for some reusable documentation for data templates)
 
m (added category; reordered)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>This is a little reusable documentation snippet for data templates.
You can use this wiki's data templates to retrieve the game data for use in any Lua module on this wiki. A utility module, <code>CsvUtils</code> processes the document for you, giving you just the CSV data, if you need to parse it yourself. Or, the utility module can split it for you into a Lua table.
 
To do this, you need these two lines in your Lua code:
 
# <code>local CsvUtils = require("Module:CsvUtils")</code>
# <code>local luaTable, headerLookup = CsvUtils.extractTables({{{1|Template:Data_Template_csv}}})</code>


== Explanation ==</noinclude>
If you need the raw CSV code for some reason, to process it differently, the method '''extractTables''' is a shortcut method that calls two methods you can instead call directly: '''extractCSV''' and '''luaTableFromCSV.''' However, this is not advised.<noinclude>
You can use this wiki's data templates to retrieve the game data for use in any Lua module on this wiki. A utility module, <code>CsvUtils</code> processes the document for you, giving you just the CSV data, if you need to parse it yourself. Or, the utility module can split it for you into a Lua table.


To do this, you add these three lines in your Lua code:
== Usage ==
This is a little reusable documentation snippet for data templates.


# <code>local CsvUtils = require('Module:CsvUtils')</code>
[[Category:Templates/Text]]</noinclude>
# <code>local rawCSV = CsvUtils.extractCSV("{{{1|Template:Data_Template_csv}}}")</code>
# <code>local luaTable, headerLookup = CsvUtils.luaTableFromCSV(rawCSV)</code>

Latest revision as of 04:04, 1 October 2024

You can use this wiki's data templates to retrieve the game data for use in any Lua module on this wiki. A utility module, CsvUtils processes the document for you, giving you just the CSV data, if you need to parse it yourself. Or, the utility module can split it for you into a Lua table.

To do this, you need these two lines in your Lua code:

  1. local CsvUtils = require("Module:CsvUtils")
  2. local luaTable, headerLookup = CsvUtils.extractTables(Template:Data_Template_csv)

If you need the raw CSV code for some reason, to process it differently, the method extractTables is a shortcut method that calls two methods you can instead call directly: extractCSV and luaTableFromCSV. However, this is not advised.

Usage

This is a little reusable documentation snippet for data templates.