Skip to content

Commit

Permalink
Add api_version gloabal variable to profiles
Browse files Browse the repository at this point in the history
Currently only `0` is supported (the default).
  • Loading branch information
TheMarex committed Dec 22, 2016
1 parent 7b11cd3 commit 81b90f7
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/extractor/scripting_environment_lua.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct LuaScriptingContext final
bool has_node_function;
bool has_way_function;
bool has_segment_function;

int api_version;
};

/**
Expand All @@ -42,6 +44,9 @@ struct LuaScriptingContext final
class Sol2ScriptingEnvironment final : public ScriptingEnvironment
{
public:
static const constexpr int SUPPORTED_MIN_API_VERSION = 0;
static const constexpr int SUPPORTED_MAX_API_VERSION = 0;

explicit Sol2ScriptingEnvironment(const std::string &file_name);
~Sol2ScriptingEnvironment() override = default;

Expand Down
2 changes: 2 additions & 0 deletions profiles/bicycle.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
api_version = 1

-- Bicycle profile

local find_access_tag = require("lib/access").find_access_tag
Expand Down
2 changes: 2 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
api_version = 0

-- Car profile
local find_access_tag = require("lib/access").find_access_tag
local get_destination = require("lib/destination").get_destination
Expand Down
1 change: 1 addition & 0 deletions profiles/foot.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api_version = 0
-- Foot profile

local find_access_tag = require("lib/access").find_access_tag
Expand Down
1 change: 1 addition & 0 deletions profiles/rasterbot.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api_version = 0
-- Rasterbot profile

-- Minimalist node_ and way_functions in order to test source_ and segment_functions
Expand Down
1 change: 1 addition & 0 deletions profiles/rasterbotinterp.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api_version = 0
-- Rasterbot profile

-- Minimalist node_ and way_functions in order to test source_ and segment_functions
Expand Down
1 change: 1 addition & 0 deletions profiles/testbot.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api_version = 0
-- Testbot profile

-- Moves at fixed, well-known speeds, practical for testing speed and travel times:
Expand Down
2 changes: 2 additions & 0 deletions profiles/turnbot.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
api_version = 0

-- Testbot, with turn penalty
-- Used for testing turn penalties

Expand Down
14 changes: 14 additions & 0 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
context.has_node_function = node_function.valid();
context.has_way_function = way_function.valid();
context.has_segment_function = segment_function.valid();
auto maybe_version = context.state.get<sol::optional<int>>("api_version");
if (maybe_version)
{
context.api_version = *maybe_version;
}

if (context.api_version < SUPPORTED_MIN_API_VERSION ||
context.api_version > SUPPORTED_MAX_API_VERSION )
{
throw util::exception("Invalid profile API version " + std::to_string(context.api_version) +
" only versions from " + std::to_string(SUPPORTED_MIN_API_VERSION) +
" to " + std::to_string(SUPPORTED_MAX_API_VERSION) +
" are supported." + SOURCE_REF);
}
}

const ProfileProperties &Sol2ScriptingEnvironment::GetProfileProperties()
Expand Down

0 comments on commit 81b90f7

Please sign in to comment.