Module:Station: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
-- Load JSON data | -- Load JSON data | ||
local data = mw.loadJsonData("Data:NguhRoutes/network.json") | local data = mw.loadJsonData("Data:NguhRoutes/network.json") | ||
local find_when = function (predicate, list) | |||
for i, v in pairs(list) do | |||
if predicate(i, v) then | |||
return v | |||
end | |||
end | |||
end | |||
p.yes = function(frame) | p.yes = function(frame) | ||
| Line 12: | Line 20: | ||
end | end | ||
p.code = function(frame) | |||
find_when(frame.args.code,data) | |||
end | |||
-- CRITICAL: You must return the module table | -- CRITICAL: You must return the module table | ||
return p | return p | ||
Revision as of 23:07, 8 January 2026
Documentation for this module may be created at Module:Station/doc
local p = {}
-- Load JSON data
local data = mw.loadJsonData("Data:NguhRoutes/network.json")
local find_when = function (predicate, list)
for i, v in pairs(list) do
if predicate(i, v) then
return v
end
end
end
p.yes = function(frame)
-- Add error handling for JSON data
if data == nil then
return "Error: Failed to load JSON data from Data:NguhRoutes/network.json"
end
return mw.text.jsonEncode(data)
end
p.code = function(frame)
find_when(frame.args.code,data)
end
-- CRITICAL: You must return the module table
return p