Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Road data/strings/doc
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Switching=== Some logic is too complicated to represent with only format strings. This framework provides several methods to express complex data. All of these involve storing a nested table as the value of a field. The most straightforward functionality provided by nested tables is switching. In its most basic form, the table consists of a series of key-value pairs, with the keys being route numbers and the values being the format strings used by those routes. Usually, the format string returned does not need parsing, but the option is there. A <code>default</code> entry should be provided to handle any route numbers not explicitly stated. The following is a representative example of route-based switching (from [[Module:Road data/strings/USA/AR]]): <syntaxhighlight lang="lua"> AR.AR = { shield = { default = "Arkansas %route%.svg", ["917"] = "Arkansas 917-1.svg", ["980"] = "Arkansas 980(Airport).svg" }, link = "Arkansas Highway %route% [dab||(%dab%)|]", abbr = "Hwy. %route%", width = "expand" } </syntaxhighlight> In this example, Highways 917 and 980 have non-standard shield names, which are explicitly provided. Other route numbers use the default format. Switching on other arguments is also allowed. The name of the argument to be used for switching is stated in the <code>arg</code> field of the table. Nesting switches on different arguments is also allowed. A good example that uses both forms of switching can be found in [[Module:Road data/strings/CAN/ON|Ontario]]: <syntaxhighlight lang="lua"> local regionalShields = { arg = "county", ["Essex"] = "Essex County Road %route%.png", ["York"] = "York Regional Road %route%.svg", ["Durham"] = "Durham Regional Road %route%.svg", ["Niagara"] = "Niagara Regional Road %route%.svg", ["Simcoe"] = { ["52"] = "Simcoe county road 52.png", default = "Simcoe County Road %route%.JPG" } } </syntaxhighlight> In this example, which is a shield table that is reused by several types in Ontario, the <code>county</code> argument is used for the primary switch. If the route is in Simcoe County, a second switch is performed, this time on the route number.
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)