Skip to content

Commit c128647

Browse files
committed
Lua example configs: Using local variables is good practice
1 parent 12bf572 commit c128647

File tree

14 files changed

+30
-31
lines changed

14 files changed

+30
-31
lines changed

flex-config/addresses.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local addrs = osm2pgsql.define_table({
1919
}
2020
})
2121

22-
function get_address(tags)
22+
local function get_address(tags)
2323
local addr = {}
2424
local count = 0
2525

flex-config/attributes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tables.relations = osm2pgsql.define_relation_table('relations', {
4949
{ column = 'members', type = 'jsonb' },
5050
})
5151

52-
function format_date(ts)
52+
local function format_date(ts)
5353
return os.date('!%Y-%m-%dT%H:%M:%SZ', ts)
5454
end
5555

flex-config/bbox.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
3232

3333
-- Helper function to remove some of the tags we usually are not interested in.
3434
-- Returns true if there are no tags left.
35-
function clean_tags(tags)
35+
local function clean_tags(tags)
3636
tags.odbl = nil
3737
tags.created_by = nil
3838
tags.source = nil
@@ -43,7 +43,7 @@ end
4343

4444
-- Helper function that looks at the tags and decides if this is possibly
4545
-- an area.
46-
function has_area_tags(tags)
46+
local function has_area_tags(tags)
4747
if tags.area == 'yes' then
4848
return true
4949
end
@@ -81,8 +81,8 @@ end
8181

8282
-- Format the bounding box we get from calling get_bbox() on the parameter
8383
-- in the way needed for the PostgreSQL/PostGIS box2d type.
84-
function format_bbox(object)
85-
xmin, ymin, xmax, ymax = object.get_bbox()
84+
local function format_bbox(object)
85+
local xmin, ymin, xmax, ymax = object.get_bbox()
8686
if xmin == nil then
8787
return nil
8888
end

flex-config/compatible.lua

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ if hstore and hstore_all then
5252
end
5353

5454
-- Used for splitting up long linestrings
55-
if srid == 4326 then
56-
max_length = 1
57-
else
55+
local max_length = 1
56+
if srid == 3857 then
5857
max_length = 100000
5958
end
6059

@@ -320,8 +319,8 @@ local non_point_columns = {
320319
'wood',
321320
}
322321

323-
function gen_columns(text_columns, with_hstore, area, geometry_type)
324-
columns = {}
322+
local function gen_columns(text_columns, with_hstore, area, geometry_type)
323+
local columns = {}
325324

326325
local add_column = function (name, type)
327326
columns[#columns + 1] = { column = name, type = type }
@@ -412,11 +411,11 @@ local z_order_lookup = {
412411
motorway = {39, true}
413412
}
414413

415-
function as_bool(value)
414+
local function as_bool(value)
416415
return value == 'yes' or value == 'true' or value == '1'
417416
end
418417

419-
function get_z_order(tags)
418+
local function get_z_order(tags)
420419
local z_order = 100 * math.floor(tonumber(tags.layer or '0') or 0)
421420
local roads = false
422421

@@ -447,7 +446,7 @@ function get_z_order(tags)
447446
return z_order, roads
448447
end
449448

450-
function make_check_in_list_func(list)
449+
local function make_check_in_list_func(list)
451450
local h = {}
452451
for _, k in ipairs(list) do
453452
h[k] = true
@@ -465,7 +464,7 @@ end
465464
local is_polygon = make_check_in_list_func(polygon_keys)
466465
local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)
467466

468-
function make_column_hash(columns)
467+
local function make_column_hash(columns)
469468
local h = {}
470469

471470
for _, k in ipairs(columns) do
@@ -475,7 +474,7 @@ function make_column_hash(columns)
475474
return h
476475
end
477476

478-
function make_get_output(columns, hstore_all)
477+
local function make_get_output(columns, hstore_all)
479478
local h = make_column_hash(columns)
480479
if hstore_all then
481480
return function(tags)
@@ -514,7 +513,7 @@ local has_generic_tag = make_check_in_list_func(generic_keys)
514513
local get_point_output = make_get_output(point_columns, hstore_all)
515514
local get_non_point_output = make_get_output(non_point_columns, hstore_all)
516515

517-
function get_hstore_column(tags)
516+
local function get_hstore_column(tags)
518517
local len = #hstore_column
519518
local h = {}
520519
for k, v in pairs(tags) do
@@ -561,7 +560,7 @@ function osm2pgsql.process_node(object)
561560
tables.point:insert(output)
562561
end
563562

564-
function add_line(output, geom, roads)
563+
local function add_line(output, geom, roads)
565564
for sgeom in geom:segmentize(max_length):geometries() do
566565
output.way = sgeom
567566
tables.line:insert(output)

flex-config/data-types.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ local highways = osm2pgsql.define_way_table('highways', {
3030

3131
-- Helper function to remove some of the tags we usually are not interested in.
3232
-- Returns true if there are no tags left.
33-
function clean_tags(tags)
33+
local function clean_tags(tags)
3434
tags.odbl = nil
3535
tags.created_by = nil
3636
tags.source = nil
@@ -63,7 +63,7 @@ for _, k in ipairs(highway_types) do
6363
end
6464

6565
-- Parse a maxspeed value like "30" or "55 mph" and return a number in km/h
66-
function parse_speed(input)
66+
local function parse_speed(input)
6767
if not input then
6868
return nil
6969
end

flex-config/expire.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ print(")")
8484

8585
-- Helper function that looks at the tags and decides if this is possibly
8686
-- an area.
87-
function has_area_tags(tags)
87+
local function has_area_tags(tags)
8888
if tags.area == 'yes' then
8989
return true
9090
end

flex-config/gen/forests.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
-- the forest has a name tag and the area is larger than a defined minimum
6767
-- we'll also add the name and a point for the label.
6868
local minimum_area_for_label = 0.001
69-
function insert_forest(tags, geom)
69+
local function insert_forest(tags, geom)
7070
local attrs = {
7171
tags = tags,
7272
geom = geom,

flex-config/generic.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys)
182182

183183
-- Helper function that looks at the tags and decides if this is possibly
184184
-- an area.
185-
function has_area_tags(tags)
185+
local function has_area_tags(tags)
186186
if tags.area == 'yes' then
187187
return true
188188
end

flex-config/geometries.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ tables.pubs = osm2pgsql.define_node_table('pubs', {
5454

5555
-- Helper function to remove some of the tags we usually are not interested in.
5656
-- Returns true if there are no tags left.
57-
function clean_tags(tags)
57+
local function clean_tags(tags)
5858
tags.odbl = nil
5959
tags.created_by = nil
6060
tags.source = nil
@@ -65,7 +65,7 @@ end
6565

6666
-- Helper function that looks at the tags and decides if this is possibly
6767
-- an area.
68-
function has_area_tags(tags)
68+
local function has_area_tags(tags)
6969
if tags.area == 'yes' then
7070
return true
7171
end

flex-config/indexes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tables.postboxes = osm2pgsql.define_node_table('postboxes', {
7171

7272
-- Helper function that looks at the tags and decides if this is possibly
7373
-- an area.
74-
function has_area_tags(tags)
74+
local function has_area_tags(tags)
7575
if tags.area == 'yes' then
7676
return true
7777
end

0 commit comments

Comments
 (0)