Browse Source

Added Preprocessor support for LuaEnvironment / LuaUtils

master
Christopher 9 years ago
parent
commit
4c786232d8
  1. 18
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs
  2. 8
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs

18
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs vendored

@ -28,6 +28,11 @@ namespace Fungus
/// Called when the LuaEnvironment is initializing. /// Called when the LuaEnvironment is initializing.
/// </summary> /// </summary>
public abstract void Initialize(); public abstract void Initialize();
/// <summary>
/// Applies transformations to the input script prior to execution.
/// </summary>
public abstract string PreprocessScript(string input);
} }
/// <summary> /// <summary>
@ -216,11 +221,22 @@ namespace Fungus
{ {
InitEnvironment(); InitEnvironment();
string processedString;
Initializer initializer = GetComponent<Initializer>();
if (initializer != null)
{
processedString = initializer.PreprocessScript(luaString);
}
else
{
processedString = luaString;
}
// Load the Lua script // Load the Lua script
DynValue res = null; DynValue res = null;
try try
{ {
res = interpreter.LoadString(luaString, null, friendlyName); res = interpreter.LoadString(processedString, null, friendlyName);
} }
catch (InterpreterException ex) catch (InterpreterException ex)
{ {

8
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs vendored

@ -95,6 +95,14 @@ namespace Fungus
InitBindings(); InitBindings();
} }
/// <summary>
/// Called by LuaEnvironment prior to executing a script.
/// </summary>
public override string PreprocessScript(string input)
{
return input;
}
/// <summary> /// <summary>
/// Registers all listed c# types for interop with Lua. /// Registers all listed c# types for interop with Lua.
/// You can also register types directly in the Awake method of any /// You can also register types directly in the Awake method of any

Loading…
Cancel
Save