Skip to content

Commit 6ed30a8

Browse files
committed
Add comments to multi-backend example
1 parent 1524c3f commit 6ed30a8

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

multi.lua

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ link_lookup = {motorway_link = 0,
8181
trunk_link = 1,
8282
primary_link = 2,
8383
secondary_link = 3,
84-
tertiary_link = 4,
85-
unclassified_link = 5,
86-
residential_link = 5}
84+
tertiary_link = 4}
8785

8886
function highway_interesting (kv)
8987
-- The kv["highway"] check is not necessary but helps performance
@@ -94,24 +92,23 @@ function highway_transform (kv)
9492
-- Thanks to highway_interesting we know that kv["highway"] is in one of
9593
-- highway_lookup or link_lookup
9694
kv["road_class"] = highway_lookup[kv["highway"]] or link_lookup[kv["highway"]]
95+
-- This is a lua way of doing an inline conditional
9796
kv["road_type"] = highway_lookup[kv["highway"]] and "road" or "link"
9897
kv["name_en"] = name_lang(kv, "en")
9998
kv["name_de"] = name_lang(kv, "de")
10099
kv["name_fr"] = name_lang(kv, "fr")
101100
return kv
102101
end
103102

104-
105103
function highway_ways (kv, num_keys)
106104
return generic_ways(highway_interesting, kv, false, highway_transform)
107105
end
108106

109107
-- Some generic and utility helper functions
110108

111-
-- This little function normalizes a tag to true/false. It turns no or false
112-
-- into false and anything else to true. The result can then be used with a
109+
-- This function normalizes a tag to true/false. It turns no or false into
110+
-- false and anything else to true. The result can then be used with a
113111
-- boolean column.
114-
--
115112
-- > = yesno(nil)
116113
-- nil
117114
-- > = yesno("no")
@@ -153,11 +150,12 @@ function name_lang(kv, lang, name_tag)
153150
end
154151
end
155152

156-
-- This function gets rid of something we don't care about
153+
-- This function gets rid of an object we don't care about
157154
function drop_all (...)
158155
return 1, {}
159156
end
160157

158+
-- This eliminates tags to be deleted
161159
function preprocess_tags (kv)
162160
tags = {}
163161
for k, v in pairs (kv) do
@@ -187,18 +185,19 @@ end
187185

188186
-- A generic way to process ways, given a function which determines if tags are interesting
189187
-- Takes an optional function to process tags.
190-
function generic_ways (f, kv, area, t)
191-
if f(kv) then
192-
t = t or function (kv) return kv end
188+
function generic_ways (interesting, kv, area, transform)
189+
if interesting(kv) then
190+
t = transform or function (kv) return kv end
193191
tags = t(preprocess_tags(kv))
194192
return 0, tags, area and 1 or 0, 0
195193
else
196194
return 1, {}, 0, 0
197195
end
198196
end
199197

200-
-- A generic way to process relations, given a function which determines if tags are interesting
201-
-- The tag transformation work is done in generic_rel_members so we don't need to pass in a t
198+
-- A generic way to process relations, given a function which determines if
199+
-- tags are interesting. The tag transformation work is done in
200+
-- generic_rel_members so we don't need to pass in a transformation function.
202201
function generic_rels (f, kv)
203202
if kv["type"] == "multipolygon" and f(kv) then
204203
tags = kv
@@ -208,13 +207,13 @@ function generic_rels (f, kv)
208207
end
209208
end
210209

211-
-- Basically taken from style.lua
212-
function generic_rel_members (f, keyvals, keyvaluemembers, roles, membercount, t)
210+
-- Basically taken from style.lua, with the potential for a transform added
211+
function generic_rel_members (f, keyvals, keyvaluemembers, roles, membercount, transform)
213212
filter = 0
214213
boundary = 0
215214
polygon = 0
216215
roads = 0
217-
t = t or function (kv) return kv end
216+
t = transform or function (kv) return kv end
218217

219218
--mark each way of the relation to tell the caller if its going
220219
--to be used in the relation or by itself as its own standalone way

0 commit comments

Comments
 (0)