From 566ab993df4e5e05920ceff6dab1da2448bfc68b Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 1 May 2015 14:06:45 -0400 Subject: [PATCH 1/5] Use lua 5.2+ without needing compatibility flags. --- profiles/bicycle.lua | 13 +++++++------ profiles/car.lua | 16 ++++------------ profiles/foot.lua | 7 ++++--- profiles/lib/access.lua | 8 +++++--- profiles/lib/maxspeed.lua | 6 ++++-- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 497321ccf..dc290e11a 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -1,5 +1,7 @@ -require("lib/access") -require("lib/maxspeed") +-- Bicycle profile + +local find_access_tag = require("lib/access").find_access_tag +local limit = require("lib/maxspeed").limit -- Begin of globals barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true } @@ -122,7 +124,6 @@ local function parse_maxspeed(source) return n end - function get_exceptions(vector) for i,v in ipairs(restriction_exception_tags) do vector:Add(v) @@ -131,7 +132,7 @@ end function node_function (node, result) local barrier = node:get_value_by_key("barrier") - local access = Access.find_access_tag(node, access_tags_hierachy) + local access = find_access_tag(node, access_tags_hierachy) local traffic_signal = node:get_value_by_key("highway") -- flag node if it carries a traffic light @@ -181,7 +182,7 @@ function way_function (way, result) end -- access - local access = Access.find_access_tag(way, access_tags_hierachy) + local access = find_access_tag(way, access_tags_hierachy) if access and access_tag_blacklist[access] then return end @@ -391,7 +392,7 @@ function way_function (way, result) end -- maxspeed - MaxSpeed.limit( result, maxspeed, maxspeed_forward, maxspeed_backward ) + limit( result, maxspeed, maxspeed_forward, maxspeed_backward ) end function turn_function (angle) diff --git a/profiles/car.lua b/profiles/car.lua index 813afd19c..6b77575ed 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -1,6 +1,8 @@ --- Begin of globals ---require("lib/access") --function temporarily inlined +-- Car profile +local find_access_tag = require("lib/access").find_access_tag + +-- Begin of globals barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["checkpoint"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["lift_gate"] = true, ["no"] = true, ["entrance"] = true } access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true } access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true, ["emergency"] = true, ["psv"] = true } @@ -147,16 +149,6 @@ local mode_normal = 1 local mode_ferry = 2 local mode_movable_bridge = 3 -local function find_access_tag(source, access_tags_hierachy) - for i,v in ipairs(access_tags_hierachy) do - local access_tag = source:get_value_by_key(v) - if access_tag and "" ~= access_tag then - return access_tag - end - end - return "" -end - function get_exceptions(vector) for i,v in ipairs(restriction_exception_tags) do vector:Add(v) diff --git a/profiles/foot.lua b/profiles/foot.lua index 5a370971a..3133cb843 100644 --- a/profiles/foot.lua +++ b/profiles/foot.lua @@ -1,7 +1,8 @@ -- Foot profile -require("lib/access") +local find_access_tag = require("lib/access").find_access_tag +-- Begin of globals barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true} access_tag_whitelist = { ["yes"] = true, ["foot"] = true, ["permissive"] = true, ["designated"] = true } access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true } @@ -75,7 +76,7 @@ end function node_function (node, result) local barrier = node:get_value_by_key("barrier") - local access = Access.find_access_tag(node, access_tags_hierachy) + local access = find_access_tag(node, access_tags_hierachy) local traffic_signal = node:get_value_by_key("highway") -- flag node if it carries a traffic light @@ -125,7 +126,7 @@ function way_function (way, result) end -- access - local access = Access.find_access_tag(way, access_tags_hierachy) + local access = find_access_tag(way, access_tags_hierachy) if access_tag_blacklist[access] then return end diff --git a/profiles/lib/access.lua b/profiles/lib/access.lua index 76d2e2c89..3fd4ff605 100644 --- a/profiles/lib/access.lua +++ b/profiles/lib/access.lua @@ -1,13 +1,15 @@ local ipairs = ipairs -module "Access" +local Access = {} -function find_access_tag(source,access_tags_hierachy) +function Access.find_access_tag(source,access_tags_hierachy) for i,v in ipairs(access_tags_hierachy) do local tag = source:get_value_by_key(v) if tag and tag ~= '' then return tag end end - return nil + return "" end + +return Access diff --git a/profiles/lib/maxspeed.lua b/profiles/lib/maxspeed.lua index aca344a79..0dd9b822d 100644 --- a/profiles/lib/maxspeed.lua +++ b/profiles/lib/maxspeed.lua @@ -1,8 +1,8 @@ local math = math -module "MaxSpeed" +local MaxSpeed = {} -function limit(way,max,maxf,maxb) +function MaxSpeed.limit(way,max,maxf,maxb) if maxf and maxf>0 then way.forward_speed = math.min(way.forward_speed, maxf) elseif max and max>0 then @@ -15,3 +15,5 @@ function limit(way,max,maxf,maxb) way.backward_speed = math.min(way.backward_speed, max) end end + +return MaxSpeed From f46b600ec0e883a37303c45fbe071afbd6d00e22 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 1 May 2015 14:24:07 -0400 Subject: [PATCH 2/5] Upgrade lua to 5.2 on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f42e7485d..bff8cfc54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ install: - sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test - sudo add-apt-repository -y ppa:boost-latest/ppa - sudo apt-get update >/dev/null - - sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev rubygems libtbb-dev + - sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.2 liblua5.2-dev rubygems libtbb-dev - sudo apt-get -q install g++-4.8 - sudo apt-get install libboost1.54-all-dev - sudo apt-get install libgdal-dev From 95088a785ab66ac21baf41f5e17e6c6e3014c566 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 1 May 2015 21:01:21 +0200 Subject: [PATCH 3/5] Make using profile.lua work again. Symbolic links are a _bad_ idea with lua script. Lua will search at the place of the symbolic link for modules _not_ at the actual location of the script. --- util/lua_util.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/lua_util.hpp b/util/lua_util.hpp index af6277c59..c68c427cf 100644 --- a/util/lua_util.hpp +++ b/util/lua_util.hpp @@ -59,7 +59,7 @@ inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_ std::string folder = profile_path.parent_path().string(); // TODO: This code is most probably not Windows safe since it uses UNIX'ish path delimiters const std::string lua_code = - "package.path = \"" + folder + "/?.lua;profiles/?.lua;\" .. package.path"; + "package.path = \"" + folder + "/?.lua;" + folder + "/profiles/?.lua;profiles/?.lua;\" .. package.path"; luaL_dostring(lua_state, lua_code.c_str()); } From fd76fba235c3deacdd8327d9198fee57f23e7f15 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 1 May 2015 16:14:07 -0400 Subject: [PATCH 4/5] Keep apt-get 5.1 for now --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bff8cfc54..f42e7485d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ install: - sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test - sudo add-apt-repository -y ppa:boost-latest/ppa - sudo apt-get update >/dev/null - - sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.2 liblua5.2-dev rubygems libtbb-dev + - sudo apt-get -q install protobuf-compiler libprotoc-dev libprotobuf7 libprotobuf-dev libbz2-dev libstxxl-dev libstxxl1 libxml2-dev libzip-dev lua5.1 liblua5.1-0-dev rubygems libtbb-dev - sudo apt-get -q install g++-4.8 - sudo apt-get install libboost1.54-all-dev - sudo apt-get install libgdal-dev From ed53888fce5dc510cf57193e090ce1f5cb85c108 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 15 May 2015 15:30:41 +0200 Subject: [PATCH 5/5] Follow symlinks --- util/lua_util.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util/lua_util.hpp b/util/lua_util.hpp index c68c427cf..6dbdc8bc1 100644 --- a/util/lua_util.hpp +++ b/util/lua_util.hpp @@ -55,11 +55,10 @@ inline bool lua_function_exists(lua_State *lua_state, const char *name) // See http://lua-users.org/wiki/PackagePath for details on the package.path syntax. inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_name) { - const boost::filesystem::path profile_path(file_name); + boost::filesystem::path profile_path = boost::filesystem::canonical(file_name); std::string folder = profile_path.parent_path().string(); // TODO: This code is most probably not Windows safe since it uses UNIX'ish path delimiters - const std::string lua_code = - "package.path = \"" + folder + "/?.lua;" + folder + "/profiles/?.lua;profiles/?.lua;\" .. package.path"; + const std::string lua_code = "package.path = \"" + folder + "/?.lua;\" .. package.path"; luaL_dostring(lua_state, lua_code.c_str()); }