From 328f9dbb01b63c1a0651980fbdec39b34930f379 Mon Sep 17 00:00:00 2001 From: jurkan Date: Sat, 22 Oct 2011 22:41:33 +0200 Subject: Added function to determine the script engine by the file name extension Reviewed-by: Bjorn, Bertram. --- src/scripting/script.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/scripting/script.cpp') diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp index 490abf09..b6121bb8 100644 --- a/src/scripting/script.cpp +++ b/src/scripting/script.cpp @@ -20,6 +20,7 @@ #include "scripting/script.h" +#include "common/configuration.h" #include "common/resourcemanager.h" #include "game-server/being.h" #include "utils/logger.h" @@ -172,3 +173,20 @@ bool Script::performCraft(Being* crafter, std::list recipe) } return true; } + +std::string Script::determineEngineByFilename(const std::string &filename) +{ + std::string ext = filename.substr(filename.find_last_of(".") + 1); + + if (ext == "lua") + { + return "lua"; + } + else + { + // Set to default engine and print warning + LOG_WARN("Unknown file extension for script \"" + + filename + "\", falling back to default script engine"); + return Configuration::getValue("defaultScriptEngine", "lua"); + } +} -- cgit v1.2.3-70-g09d2