From 4c786232d8b4061918c23140d0bd833d84fa825e Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 27 Jun 2016 18:42:50 +0100 Subject: [PATCH] Added Preprocessor support for LuaEnvironment / LuaUtils --- .../FungusLua/Scripts/LuaEnvironment.cs | 20 +++++++++++++++++-- .../Thirdparty/FungusLua/Scripts/LuaUtils.cs | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs index dd0724ee..a7354f56 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs @@ -27,7 +27,12 @@ namespace Fungus /// /// Called when the LuaEnvironment is initializing. /// - public abstract void Initialize(); + public abstract void Initialize(); + + /// + /// Applies transformations to the input script prior to execution. + /// + public abstract string PreprocessScript(string input); } /// @@ -216,11 +221,22 @@ namespace Fungus { InitEnvironment(); + string processedString; + Initializer initializer = GetComponent(); + if (initializer != null) + { + processedString = initializer.PreprocessScript(luaString); + } + else + { + processedString = luaString; + } + // Load the Lua script DynValue res = null; try { - res = interpreter.LoadString(luaString, null, friendlyName); + res = interpreter.LoadString(processedString, null, friendlyName); } catch (InterpreterException ex) { diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs index c2e68d7c..4e27b6fe 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs @@ -95,6 +95,14 @@ namespace Fungus InitBindings(); } + /// + /// Called by LuaEnvironment prior to executing a script. + /// + public override string PreprocessScript(string input) + { + return input; + } + /// /// Registers all listed c# types for interop with Lua. /// You can also register types directly in the Awake method of any