diff --git a/include/extractor/scripting_environment_lua.hpp b/include/extractor/scripting_environment_lua.hpp index 0a137bbdaaa..9b91031cea5 100644 --- a/include/extractor/scripting_environment_lua.hpp +++ b/include/extractor/scripting_environment_lua.hpp @@ -30,6 +30,8 @@ struct LuaScriptingContext final bool has_node_function; bool has_way_function; bool has_segment_function; + + int api_version; }; /** @@ -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; diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 7495867e647..db64b022079 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -1,3 +1,5 @@ +api_version = 1 + -- Bicycle profile local find_access_tag = require("lib/access").find_access_tag diff --git a/profiles/car.lua b/profiles/car.lua index 196fa924c9f..8f93272cdc7 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -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 diff --git a/profiles/foot.lua b/profiles/foot.lua index 3b24cbb922b..86c09c37a36 100644 --- a/profiles/foot.lua +++ b/profiles/foot.lua @@ -1,3 +1,4 @@ +api_version = 0 -- Foot profile local find_access_tag = require("lib/access").find_access_tag diff --git a/profiles/rasterbot.lua b/profiles/rasterbot.lua index bc2b2b247b9..69e70961609 100644 --- a/profiles/rasterbot.lua +++ b/profiles/rasterbot.lua @@ -1,3 +1,4 @@ +api_version = 0 -- Rasterbot profile -- Minimalist node_ and way_functions in order to test source_ and segment_functions diff --git a/profiles/rasterbotinterp.lua b/profiles/rasterbotinterp.lua index f81e6e2f5a5..e75c808d886 100644 --- a/profiles/rasterbotinterp.lua +++ b/profiles/rasterbotinterp.lua @@ -1,3 +1,4 @@ +api_version = 0 -- Rasterbot profile -- Minimalist node_ and way_functions in order to test source_ and segment_functions diff --git a/profiles/testbot.lua b/profiles/testbot.lua index dd69e0ae1ff..004a345a863 100644 --- a/profiles/testbot.lua +++ b/profiles/testbot.lua @@ -1,3 +1,4 @@ +api_version = 0 -- Testbot profile -- Moves at fixed, well-known speeds, practical for testing speed and travel times: diff --git a/profiles/turnbot.lua b/profiles/turnbot.lua index 7629515d130..dc6a09fb4e6 100644 --- a/profiles/turnbot.lua +++ b/profiles/turnbot.lua @@ -1,3 +1,5 @@ +api_version = 0 + -- Testbot, with turn penalty -- Used for testing turn penalties diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index e42a9d8aea1..cd5ce0c9512 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -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>("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()