Browse Source

Reverted IExecuteHandler, ILuaBindings and ILuaEnvironment interfaces

master
Christopher 8 years ago
parent
commit
a550d29e10
  1. 17
      Assets/Fungus/Scripts/Commands/ExecuteLua.cs
  2. 2
      Assets/Fungus/Scripts/Components/Flowchart.cs
  3. 4
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  4. 107
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/ExecuteHandler.cs
  5. 34
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaBindings.cs
  6. 227
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs
  7. 4
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironmentInitializer.cs
  8. 23
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaScript.cs
  9. 2
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaStore.cs
  10. 28
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs
  11. 10
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs
  12. 99
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandler.cs
  13. 43
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandlerConfigurator.cs
  14. 0
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandlerConfigurator.cs.meta
  15. 36
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaBindings.cs
  16. 12
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaBindings.cs.meta
  17. 47
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaEnvironment.cs
  18. 64
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/LuaScriptLoader.cs
  19. 4
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/LuaScriptLoader.cs.meta

17
Assets/Fungus/Scripts/Commands/ExecuteLua.cs

@ -18,7 +18,6 @@ namespace Fungus.Commands
{
[Tooltip("Lua Environment to use to execute this Lua script")]
[SerializeField] protected LuaEnvironment luaEnvironment;
public ILuaEnvironment LuaEnv { set; get; }
[Tooltip("A text file containing Lua script to execute.")]
[SerializeField] protected TextAsset luaFile;
@ -65,24 +64,24 @@ namespace Fungus.Commands
var flowchart = GetFlowchart();
// See if a Lua Environment has been assigned to this Flowchart
if (luaEnvironment == null)
if (luaEnvironment == null)
{
LuaEnv = flowchart.LuaEnv;
luaEnvironment = flowchart.LuaEnv;
}
// No Lua Environment specified so just use any available or create one.
if (LuaEnv == null)
if (luaEnvironment == null)
{
LuaEnv = LuaEnvironment.GetLua();
// No Lua Environment specified so just use any available or create one.
luaEnvironment = LuaEnvironment.GetLua();
}
string s = GetLuaString();
luaFunction = LuaEnv.LoadLuaFunction(s, friendlyName);
luaFunction = luaEnvironment.LoadLuaFunction(s, friendlyName);
// Add a binding to the parent flowchart
if (flowchart.LuaBindingName != "")
{
Table globals = LuaEnv.Interpreter.Globals;
Table globals = luaEnvironment.Interpreter.Globals;
if (globals != null)
{
globals[flowchart.LuaBindingName] = flowchart;
@ -182,7 +181,7 @@ namespace Fungus.Commands
Continue();
}
LuaEnv.RunLuaFunction(luaFunction, runAsCoroutine, (returnValue) => {
luaEnvironment.RunLuaFunction(luaFunction, runAsCoroutine, (returnValue) => {
StoreReturnVariable(returnValue);
if (waitUntilFinished)
{

2
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -368,7 +368,7 @@ namespace Fungus
/// <summary>
/// Lua Environment to be used by default for all Execute Lua commands in this Flowchart.
/// </summary>
public virtual ILuaEnvironment LuaEnv { get { return luaEnvironment; } }
public virtual LuaEnvironment LuaEnv { get { return luaEnvironment; } }
/// <summary>
/// The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.

4
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -240,7 +240,7 @@ namespace Fungus
/// Will cause the Menu dialog to become visible if it is not already visible.
/// </summary>
/// <returns><c>true</c>, if the option was added successfully.</returns>
public virtual bool AddOption(string text, bool interactable, ILuaEnvironment luaEnv, Closure callBack)
public virtual bool AddOption(string text, bool interactable, LuaEnvironment luaEnv, Closure callBack)
{
if (!gameObject.activeSelf)
{
@ -301,7 +301,7 @@ namespace Fungus
/// <summary>
/// Show a timer during which the player can select an option. Calls a Lua function when the timer expires.
/// </summary>
public virtual IEnumerator ShowTimer(float duration, ILuaEnvironment luaEnv, Closure callBack)
public virtual IEnumerator ShowTimer(float duration, LuaEnvironment luaEnv, Closure callBack)
{
if (CachedSlider == null ||
duration <= 0f)

107
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/ExecuteHandler.cs vendored

@ -12,23 +12,60 @@ using Object = UnityEngine.Object;
namespace Fungus
{
[Flags]
public enum ExecuteMethod
{
AfterPeriodOfTime = 1 << 0,
Start = 1 << 1,
Update = 1 << 2,
FixedUpdate = 1 << 3,
LateUpdate = 1 << 4,
OnDestroy = 1 << 5,
OnEnable = 1 << 6,
OnDisable = 1 << 7,
OnControllerColliderHit = 1 << 8,
OnParticleCollision = 1 << 9,
OnJointBreak = 1 << 10,
OnBecameInvisible = 1 << 11,
OnBecameVisible = 1 << 12,
OnTriggerEnter = 1 << 13,
OnTriggerExit = 1 << 14,
OnTriggerStay = 1 << 15,
OnCollisionEnter = 1 << 16,
OnCollisionExit = 1 << 17,
OnCollisionStay = 1 << 18,
OnTriggerEnter2D = 1 << 19,
OnTriggerExit2D = 1 << 20,
OnTriggerStay2D = 1 << 21,
OnCollisionEnter2D = 1 << 22,
OnCollisionExit2D = 1 << 23,
OnCollisionStay2D = 1 << 24,
}
/// <summary>
/// Executes an LuaScript component in the same gameobject when a condition occurs.
/// </summary>
public class ExecuteHandler : MonoBehaviour, IExecuteHandler, IExecuteHandlerConfigurator
public class ExecuteHandler : MonoBehaviour, IExecuteHandlerConfigurator
{
[Tooltip("Execute after a period of time.")]
[SerializeField] protected float executeAfterTime = 1f;
[Tooltip("Repeat execution after a period of time.")]
[SerializeField] protected bool repeatExecuteTime = true;
[Tooltip("Repeat forever.")]
[SerializeField] protected float repeatEveryTime = 1f;
[Tooltip("Execute after a number of frames have elapsed.")]
[SerializeField] protected int executeAfterFrames = 1;
[Tooltip("Repeat execution after a number of frames have elapsed.")]
[SerializeField] protected bool repeatExecuteFrame = true;
[Tooltip("Execute on every frame.")]
[SerializeField] protected int repeatEveryFrame = 1;
[Tooltip("The bitmask for the currently selected execution methods.")]
[SerializeField] protected ExecuteMethod executeMethods = ExecuteMethod.Start;
[Tooltip("Name of the method on a component in this gameobject to call when executing.")]
@ -209,46 +246,56 @@ namespace Fungus
Execute();
}
}
#region Public methods
#region AssertionComponentConfigurator
public int UpdateExecuteStartOnFrame { set { executeAfterFrames = value; } }
public int UpdateExecuteRepeatFrequency { set { repeatEveryFrame = value; } }
public bool UpdateExecuteRepeat { set { repeatExecuteFrame = value; } }
public float TimeExecuteStartAfter { set { executeAfterTime = value; } }
public float TimeExecuteRepeatFrequency { set { repeatEveryTime = value; } }
public bool TimeExecuteRepeat { set { repeatExecuteTime = value; } }
public ExecuteHandler Component { get { return this; } }
#endregion
#region IExecuteHandler implementation
/// <summary>
/// Execute after a period of time.
/// </summary>
public virtual float ExecuteAfterTime { get { return executeAfterTime; } set { executeAfterTime = value; } }
/// <summary>
/// Repeat execution after a period of time.
/// </summary>
public virtual bool RepeatExecuteTime { get { return repeatExecuteTime; } set { repeatExecuteTime = value; } }
/// <summary>
/// Repeat forever.
/// </summary>
public virtual float RepeatEveryTime { get { return repeatEveryTime; } set { repeatEveryTime = value; } }
/// <summary>
/// Execute after a number of frames have elapsed.
/// </summary>
public virtual int ExecuteAfterFrames { get { return executeAfterFrames; } set { executeAfterFrames = value; } }
/// <summary>
/// Repeat execution after a number of frames have elapsed.
/// </summary>
public virtual bool RepeatExecuteFrame { get { return repeatExecuteFrame; } set { repeatExecuteFrame = value; } }
/// <summary>
/// Execute on every frame.
/// </summary>
public virtual int RepeatEveryFrame { get { return repeatEveryFrame; } set { repeatEveryFrame = value; } }
/// <summary>
/// The bitmask for the currently selected execution methods.
/// </summary>
public virtual ExecuteMethod ExecuteMethods { get { return executeMethods; } set { executeMethods = value; } }
/// <summary>
/// Returns true if the specified execute method option has been enabled.
/// </summary>
public virtual bool IsExecuteMethodSelected(ExecuteMethod method)
{
return method == (executeMethods & method);
}
/// <summary>
/// Execute the Lua script immediately.
/// This is the function to call if you want to trigger execution from an external script.
/// </summary>
public virtual void Execute()
{
// Call any OnExecute methods in components on this gameobject
@ -259,5 +306,23 @@ namespace Fungus
}
#endregion
#region AssertionComponentConfigurator implementation
public int UpdateExecuteStartOnFrame { set { executeAfterFrames = value; } }
public int UpdateExecuteRepeatFrequency { set { repeatEveryFrame = value; } }
public bool UpdateExecuteRepeat { set { repeatExecuteFrame = value; } }
public float TimeExecuteStartAfter { set { executeAfterTime = value; } }
public float TimeExecuteRepeatFrequency { set { repeatEveryTime = value; } }
public bool TimeExecuteRepeat { set { repeatExecuteTime = value; } }
public ExecuteHandler Component { get { return this; } }
#endregion
}
}

34
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaBindings.cs vendored

@ -4,18 +4,36 @@
using UnityEngine;
using System.Collections.Generic;
using MoonSharp.Interpreter;
using System;
namespace Fungus
{
/// <summary>
/// Represents a single Unity object (+ optional component) bound to a string key.
/// </summary>
[Serializable]
public class BoundObject
{
public string key;
public UnityEngine.Object obj;
public Component component;
}
/// <summary>
/// Base class for a component which registers Lua Bindings.
/// When the Lua Environment initialises, it finds all components in the scene that inherit
/// from LuaBindingsBase and calls them to add their bindings.
/// </summary>
public abstract class LuaBindingsBase : MonoBehaviour, ILuaBindings
public abstract class LuaBindingsBase : MonoBehaviour
{
public abstract void AddBindings(ILuaEnvironment luaEnv);
/// <summary>
/// Adds the required bindings to the Lua environment.
/// </summary>
public abstract void AddBindings(LuaEnvironment luaEnv);
/// <summary>
/// Returns a list of the object that will be bound to the Lua environment.
/// </summary>
public abstract List<BoundObject> BoundObjects { get; }
}
@ -55,9 +73,12 @@ namespace Fungus
}
}
#region ILuaBindings implementation
#region Public methods
public override void AddBindings(ILuaEnvironment luaEnv)
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
public override void AddBindings(LuaEnvironment luaEnv)
{
if (!allEnvironments &&
(luaEnvironment != null && !luaEnvironment.Equals(luaEnv)))
@ -147,6 +168,9 @@ namespace Fungus
}
}
/// <summary>
/// The list of objects to be bound to Lua.
/// </summary>
public override List<BoundObject> BoundObjects { get { return boundObjects; } }
#endregion

227
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs vendored

@ -16,84 +16,19 @@ namespace Fungus
/// <summary>
/// Wrapper for a MoonSharp Lua Script instance.
/// </summary>
public class LuaEnvironment : MonoBehaviour, ILuaEnvironment
public class LuaEnvironment : MonoBehaviour
{
/// <summary>
/// Custom file loader for MoonSharp that loads in all Lua scripts in the project.
/// Scripts must be placed in a Resources/Lua directory.
/// Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command.
/// </summary>
protected class LuaScriptLoader : ScriptLoaderBase
{
// Give the script loader access to the list of accessible Lua Modules.
private IEnumerable<TextAsset> luaScripts;
public LuaScriptLoader(IEnumerable<TextAsset> luaScripts)
{
this.luaScripts = luaScripts;
}
/// <summary>
// Bypasses the standard path resolution logic for require.
/// </summary>
protected override string ResolveModuleName(string modname, string[] paths)
{
return modname;
}
public override object LoadFile(string file, Table globalContext)
{
foreach (TextAsset luaScript in luaScripts)
{
// Case insensitive string compare to allow standard Lua naming conventions in code
if (String.Compare(luaScript.name, file, true) == 0)
{
return luaScript.text;
}
}
return "";
}
public override bool ScriptFileExists(string name)
{
foreach (TextAsset luaScript in luaScripts)
{
// Case insensitive string compare to allow standard Lua naming conventions in code
if (String.Compare(luaScript.name, name, true) == 0)
{
return true;
}
}
return false;
}
}
[Tooltip("Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command. Standalone platform only.")]
[SerializeField] protected bool remoteDebugger = false;
/// <summary>
/// Returns the first Lua Environment found in the scene, or creates one if none exists.
/// This is a slow operation, call it once at startup and cache the returned value.
/// The MoonSharp interpreter instance.
/// </summary>
public static ILuaEnvironment GetLua()
{
ILuaEnvironment luaEnv = GameObject.FindObjectOfType<LuaEnvironment>();
if (luaEnv == null)
{
GameObject prefab = Resources.Load<GameObject>("Prefabs/LuaEnvironment");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "LuaEnvironment";
luaEnv = go.GetComponent<ILuaEnvironment>();
}
}
return luaEnv;
}
protected Script interpreter;
/// <summary>
/// Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command.
/// </summary>
[Tooltip("Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command. Standalone platform only.")]
[SerializeField] protected bool remoteDebugger = false;
/// <summary>
/// Instance of remote debugging service when debugging option is enabled.
/// </summary>
@ -118,44 +53,6 @@ namespace Fungus
interpreter.Options.ScriptLoader = new LuaScriptLoader(result.OfType<TextAsset>());
}
/// <summary>
/// Register a type given it's assembly qualified name.
/// </summary>
public static void RegisterType(string typeName, bool extensionType = false)
{
System.Type t = System.Type.GetType(typeName);
if (t == null)
{
UnityEngine.Debug.LogWarning("Type not found: " + typeName);
return;
}
// Registering System.Object breaks MoonSharp's automated conversion of Lists and Dictionaries to Lua tables.
if (t == typeof(System.Object))
{
return;
}
if (!UserData.IsTypeRegistered(t))
{
try
{
if (extensionType)
{
UserData.RegisterExtensionType(t);
}
else
{
UserData.RegisterType(t);
}
}
catch (ArgumentException ex)
{
UnityEngine.Debug.LogWarning(ex.Message);
}
}
}
/// <summary>
/// A Unity coroutine method which updates a Lua coroutine each frame.
/// <param name="closure">A MoonSharp closure object representing a function.</param>
@ -201,21 +98,6 @@ namespace Fungus
return sourceCode;
}
/// <summary>
/// Start a Unity coroutine from a Lua call.
/// </summary>
public virtual Task RunUnityCoroutine(IEnumerator coroutine)
{
if (coroutine == null)
{
return null;
}
// We use the Task class so we can poll the coroutine to check if it has finished.
// Standard Unity coroutines don't support this check.
return new Task(RunUnityCoroutineImpl(coroutine));
}
/// <summary>
/// Starts a standard Unity coroutine.
/// The coroutine is managed by the LuaEnvironment monobehavior, so you can call StopAllCoroutines to
@ -273,8 +155,84 @@ namespace Fungus
UnityEngine.Debug.LogError(output);
}
#region ILuaEnvironment implementation
#region Public members
/// <summary>
/// Returns the first Lua Environment found in the scene, or creates one if none exists.
/// This is a slow operation, call it once at startup and cache the returned value.
/// </summary>
public static LuaEnvironment GetLua()
{
var luaEnv = GameObject.FindObjectOfType<LuaEnvironment>();
if (luaEnv == null)
{
GameObject prefab = Resources.Load<GameObject>("Prefabs/LuaEnvironment");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "LuaEnvironment";
luaEnv = go.GetComponent<LuaEnvironment>();
}
}
return luaEnv;
}
/// <summary>
/// Register a type given it's assembly qualified name.
/// </summary>
public static void RegisterType(string typeName, bool extensionType = false)
{
System.Type t = System.Type.GetType(typeName);
if (t == null)
{
UnityEngine.Debug.LogWarning("Type not found: " + typeName);
return;
}
// Registering System.Object breaks MoonSharp's automated conversion of Lists and Dictionaries to Lua tables.
if (t == typeof(System.Object))
{
return;
}
if (!UserData.IsTypeRegistered(t))
{
try
{
if (extensionType)
{
UserData.RegisterExtensionType(t);
}
else
{
UserData.RegisterType(t);
}
}
catch (ArgumentException ex)
{
UnityEngine.Debug.LogWarning(ex.Message);
}
}
}
/// <summary>
/// Start a Unity coroutine from a Lua call.
/// </summary>
public virtual Task RunUnityCoroutine(IEnumerator coroutine)
{
if (coroutine == null)
{
return null;
}
// We use the Task class so we can poll the coroutine to check if it has finished.
// Standard Unity coroutines don't support this check.
return new Task(RunUnityCoroutineImpl(coroutine));
}
/// <summary>
/// Initialise the Lua interpreter so we can start running Lua code.
/// </summary>
public virtual void InitEnvironment()
{
if (initialised)
@ -306,8 +264,16 @@ namespace Fungus
initialised = true;
}
/// <summary>
/// The MoonSharp interpreter instance used to run Lua code.
/// </summary>
public virtual Script Interpreter { get { return interpreter; } }
/// <summary>
/// Loads and compiles a string containing Lua script, returning a closure (Lua function) which can be executed later.
/// <param name="luaString">The Lua code to be run.</param>
/// <param name="friendlyName">A descriptive name to be used in error reports.</param>
/// </summary>
public virtual Closure LoadLuaFunction(string luaString, string friendlyName)
{
InitEnvironment();
@ -344,6 +310,12 @@ namespace Fungus
return res.Function;
}
/// <summary>
/// Load and run a previously compiled Lua script. May be run as a coroutine.
/// <param name="fn">A previously compiled Lua function.</param>
/// <param name="runAsCoroutine">Run the Lua code as a coroutine to support asynchronous operations.</param>
/// <param name="onComplete">Method to callback when the Lua code finishes exection. Supports return parameters.</param>
/// </summary>
public virtual void RunLuaFunction(Closure fn, bool runAsCoroutine, Action<DynValue> onComplete = null)
{
if (fn == null)
@ -380,6 +352,13 @@ namespace Fungus
}
}
/// <summary>
/// Load and run a string containing Lua script. May be run as a coroutine.
/// <param name="luaString">The Lua code to be run.</param>
/// <param name="friendlyName">A descriptive name to be used in error reports.</param>
/// <param name="runAsCoroutine">Run the Lua code as a coroutine to support asynchronous operations.</param>
/// <param name="onComplete">Method to callback when the Lua code finishes exection. Supports return parameters.</param>
/// </summary>
public virtual void DoLuaString(string luaString, string friendlyName, bool runAsCoroutine, Action<DynValue> onComplete = null)
{
Closure fn = LoadLuaFunction(luaString, friendlyName);

4
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironmentInitializer.cs vendored

@ -10,6 +10,8 @@ namespace Fungus
/// </summary>
public abstract class LuaEnvironmentInitializer : MonoBehaviour
{
#region Public members
/// <summary>
/// Called when the LuaEnvironment is initializing.
/// </summary>
@ -19,5 +21,7 @@ namespace Fungus
/// Applies transformations to the input script prior to execution.
/// </summary>
public abstract string PreprocessScript(string input);
#endregion
}
}

23
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaScript.cs vendored

@ -18,7 +18,6 @@ namespace Fungus
/// </summary>
[Tooltip("The Lua Environment to use when executing Lua script.")]
[SerializeField] protected LuaEnvironment luaEnvironment;
protected ILuaEnvironment LuaEnv { get; set; }
/// <summary>
/// Text file containing Lua script to be executed.
@ -50,7 +49,7 @@ namespace Fungus
protected Closure luaFunction;
// Recursively build the full hierarchy path to this game object
private static string GetPath(Transform current)
protected static string GetPath(Transform current)
{
if (current.parent == null)
{
@ -74,32 +73,26 @@ namespace Fungus
return;
}
if (LuaEnv == null &&
luaEnvironment != null)
{
LuaEnv = luaEnvironment as ILuaEnvironment;
}
if (LuaEnv == null)
if (luaEnvironment == null)
{
// Create a Lua Environment if none exists yet
LuaEnv = LuaEnvironment.GetLua();
luaEnvironment = LuaEnvironment.GetLua();
}
if (LuaEnv == null)
if (luaEnvironment == null)
{
Debug.LogError("No Lua Environment found");
return;
}
// Ensure the LuaEnvironment is initialized before trying to execute code
LuaEnv.InitEnvironment();
luaEnvironment.InitEnvironment();
// Cache a descriptive name to use in Lua error messages
friendlyName = GetPath(transform) + ".LuaScript";
string s = GetLuaString();
luaFunction = LuaEnv.LoadLuaFunction(s, friendlyName);
luaFunction = luaEnvironment.LoadLuaFunction(s, friendlyName);
initialised = true;
}
@ -136,13 +129,13 @@ namespace Fungus
// Make sure the script and Lua environment are initialised before executing
InitLuaScript();
if (LuaEnv == null)
if (luaEnvironment == null)
{
Debug.LogWarning("No Lua Environment found");
}
else
{
LuaEnv.RunLuaFunction(luaFunction, runAsCoroutine);
luaEnvironment.RunLuaFunction(luaFunction, runAsCoroutine);
}
}

2
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaStore.cs vendored

@ -65,7 +65,7 @@ namespace Fungus
#region LuaBindingsBase implementation
public override void AddBindings(ILuaEnvironment luaEnv)
public override void AddBindings(LuaEnvironment luaEnv)
{
if (!Init())
{

28
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs vendored

@ -51,7 +51,7 @@ namespace Fungus
/// <summary>
/// Cached reference to the Lua Environment component.
/// </summary>
protected ILuaEnvironment LuaEnv { get; set; }
protected LuaEnvironment luaEnvironment { get; set; }
protected StringSubstituter stringSubstituter;
@ -140,7 +140,7 @@ namespace Fungus
LuaBindingsBase[] bindings = GameObject.FindObjectsOfType<LuaBindingsBase>();
foreach (LuaBindingsBase binding in bindings)
{
binding.AddBindings(LuaEnv);
binding.AddBindings(luaEnvironment);
}
}
@ -156,7 +156,7 @@ namespace Fungus
return;
}
MoonSharp.Interpreter.Script interpreter = LuaEnv.Interpreter;
MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
// Require the Fungus module and assign it to the global 'fungus'
Table fungusTable = null;
@ -180,7 +180,7 @@ namespace Fungus
fungusTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory));
// Lua Environment and Lua Utils components
fungusTable["luaenvironment"] = LuaEnv;
fungusTable["luaenvironment"] = luaEnvironment;
fungusTable["luautils"] = this;
// Provide access to the Unity Test Tools (if available).
@ -266,14 +266,14 @@ namespace Fungus
public override void Initialize()
{
LuaEnv = GetComponent<ILuaEnvironment>();
if (LuaEnv == null)
luaEnvironment = GetComponent<LuaEnvironment>();
if (luaEnvironment == null)
{
Debug.LogError("No Lua Environment found");
return;
}
if (LuaEnv.Interpreter == null)
if (luaEnvironment.Interpreter == null)
{
Debug.LogError("No Lua interpreter found");
return;
@ -319,28 +319,28 @@ namespace Fungus
{
// This method could be called from the Start of another component, so
// we need to ensure that the LuaEnvironment has been initialized.
if (LuaEnv == null)
if (luaEnvironment == null)
{
LuaEnv = GetComponent<ILuaEnvironment>();
if (LuaEnv != null)
luaEnvironment = GetComponent<LuaEnvironment>();
if (luaEnvironment != null)
{
LuaEnv.InitEnvironment();
luaEnvironment.InitEnvironment();
}
}
if (LuaEnv == null)
if (luaEnvironment == null)
{
UnityEngine.Debug.LogError("No Lua Environment found");
return false;
}
if (LuaEnv.Interpreter == null)
if (luaEnvironment.Interpreter == null)
{
UnityEngine.Debug.LogError("No Lua interpreter found");
return false;
}
MoonSharp.Interpreter.Script interpreter = LuaEnv.Interpreter;
MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
// Instantiate the regular expression object.
Regex r = new Regex("\\{\\$.*?\\}");

10
Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs vendored

@ -63,7 +63,7 @@ namespace Fungus
if (EditorGUI.EndChangeCheck())
{
// Force the key to be a valid Lua variable name
LuaBindings luaBindings = target as LuaBindings;
var luaBindings = target as LuaBindings;
keyProp.stringValue = GetUniqueKey(luaBindings, keyProp.stringValue, index);
}
@ -77,7 +77,7 @@ namespace Fungus
{
// Use the object name as the key
string keyName = objectProp.objectReferenceValue.name;
LuaBindings luaBindings = target as LuaBindings;
var luaBindings = target as LuaBindings;
element.FindPropertyRelative("key").stringValue = GetUniqueKey(luaBindings, keyName.ToLower(), index);
// Auto select any Flowchart component in the object
@ -200,7 +200,7 @@ namespace Fungus
List<string> details = new List<string>();
details.Add("");
LuaBindings luaBindings = target as LuaBindings;
var luaBindings = target as LuaBindings;
foreach (BoundObject boundObject in luaBindings.BoundObjects)
{
UnityEngine.Object inspectObject = boundObject.obj;
@ -388,8 +388,8 @@ namespace Fungus
[DidReloadScripts()]
protected static void DidReloadScripts()
{
LuaBindings[] luaBindingsList = GameObject.FindObjectsOfType<LuaBindings>();
foreach (LuaBindings luaBindings in luaBindingsList)
var luaBindingsList = GameObject.FindObjectsOfType<LuaBindings>();
foreach (var luaBindings in luaBindingsList)
{
SerializedObject so = new SerializedObject(luaBindings);
so.Update();

99
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandler.cs vendored

@ -1,99 +0,0 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using System;
namespace Fungus
{
[Flags]
public enum ExecuteMethod
{
AfterPeriodOfTime = 1 << 0,
Start = 1 << 1,
Update = 1 << 2,
FixedUpdate = 1 << 3,
LateUpdate = 1 << 4,
OnDestroy = 1 << 5,
OnEnable = 1 << 6,
OnDisable = 1 << 7,
OnControllerColliderHit = 1 << 8,
OnParticleCollision = 1 << 9,
OnJointBreak = 1 << 10,
OnBecameInvisible = 1 << 11,
OnBecameVisible = 1 << 12,
OnTriggerEnter = 1 << 13,
OnTriggerExit = 1 << 14,
OnTriggerStay = 1 << 15,
OnCollisionEnter = 1 << 16,
OnCollisionExit = 1 << 17,
OnCollisionStay = 1 << 18,
OnTriggerEnter2D = 1 << 19,
OnTriggerExit2D = 1 << 20,
OnTriggerStay2D = 1 << 21,
OnCollisionEnter2D = 1 << 22,
OnCollisionExit2D = 1 << 23,
OnCollisionStay2D = 1 << 24,
}
/// <summary>
/// Executes an LuaScript component in the same gameobject when a condition occurs.
/// </summary>
public interface IExecuteHandler
{
float ExecuteAfterTime { get; set; }
bool RepeatExecuteTime { get; set; }
float RepeatEveryTime { get; set; }
int ExecuteAfterFrames { get; set; }
bool RepeatExecuteFrame { get; set; }
int RepeatEveryFrame { get; set; }
ExecuteMethod ExecuteMethods { get; set; }
/// <summary>
/// Returns true if the specified execute method option has been enabled.
/// </summary>
bool IsExecuteMethodSelected(ExecuteMethod method);
/// <summary>
/// Execute the Lua script immediately.
/// This is the function to call if you want to trigger execution from an external script.
/// </summary>
void Execute();
}
public interface IExecuteHandlerConfigurator
{
/// <summary>
/// If the assertion is evaluated in Update, after how many frame should the evaluation start. Defult is 1 (first frame)
/// </summary>
int UpdateExecuteStartOnFrame { set; }
/// <summary>
/// If the assertion is evaluated in Update and UpdateExecuteRepeat is true, how many frame should pass between evaluations
/// </summary>
int UpdateExecuteRepeatFrequency { set; }
/// <summary>
/// If the assertion is evaluated in Update, should the evaluation be repeated after UpdateExecuteRepeatFrequency frames
/// </summary>
bool UpdateExecuteRepeat { set; }
/// <summary>
/// If the assertion is evaluated after a period of time, after how many seconds the first evaluation should be done
/// </summary>
float TimeExecuteStartAfter { set; }
/// <summary>
/// If the assertion is evaluated after a period of time and TimeExecuteRepeat is true, after how many seconds should the next evaluation happen
/// </summary>
float TimeExecuteRepeatFrequency { set; }
/// <summary>
/// If the assertion is evaluated after a period, should the evaluation happen again after TimeExecuteRepeatFrequency seconds
/// </summary>
bool TimeExecuteRepeat { set; }
ExecuteHandler Component { get; }
}
}

43
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandlerConfigurator.cs vendored

@ -0,0 +1,43 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
namespace Fungus
{
public interface IExecuteHandlerConfigurator
{
/// <summary>
/// If the assertion is evaluated in Update, after how many frame should the evaluation start. Defult is 1 (first frame)
/// </summary>
int UpdateExecuteStartOnFrame { set; }
/// <summary>
/// If the assertion is evaluated in Update and UpdateExecuteRepeat is true, how many frame should pass between evaluations
/// </summary>
int UpdateExecuteRepeatFrequency { set; }
/// <summary>
/// If the assertion is evaluated in Update, should the evaluation be repeated after UpdateExecuteRepeatFrequency frames
/// </summary>
bool UpdateExecuteRepeat { set; }
/// <summary>
/// If the assertion is evaluated after a period of time, after how many seconds the first evaluation should be done
/// </summary>
float TimeExecuteStartAfter { set; }
/// <summary>
/// If the assertion is evaluated after a period of time and TimeExecuteRepeat is true, after how many seconds should the next evaluation happen
/// </summary>
float TimeExecuteRepeatFrequency { set; }
/// <summary>
/// If the assertion is evaluated after a period, should the evaluation happen again after TimeExecuteRepeatFrequency seconds
/// </summary>
bool TimeExecuteRepeat { set; }
/// <summary>
/// Returns the ExecuteHandler component.
/// </summary>
ExecuteHandler Component { get; }
}
}

0
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandler.cs.meta → Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandlerConfigurator.cs.meta vendored

36
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaBindings.cs vendored

@ -1,36 +0,0 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using System;
using System.Collections.Generic;
namespace Fungus
{
/// <summary>
/// Represents a single Unity object (+ optional component) bound to a string key.
/// </summary>
[Serializable]
public class BoundObject
{
public string key;
public UnityEngine.Object obj;
public Component component;
}
/// <summary>
/// Binds objects to identifiers in a Lua Environment.
/// </summary>
public interface ILuaBindings
{
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
void AddBindings(ILuaEnvironment luaEnv);
/// <summary>
/// The list of objects to be bound to Lua.
/// </summary>
List<BoundObject> BoundObjects { get; }
}
}

12
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaBindings.cs.meta vendored

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 171f4567dbd354491adfd4d9b72bea9f
timeCreated: 1473671931
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

47
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaEnvironment.cs vendored

@ -1,47 +0,0 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using MoonSharp.Interpreter;
namespace Fungus
{
/// <summary>
/// Wrapper for a MoonSharp Lua Script instance.
/// </summary>
public interface ILuaEnvironment
{
/// <summary>
/// Initialise the Lua interpreter so we can start running Lua code.
/// </summary>
void InitEnvironment();
/// <summary>
/// The MoonSharp interpreter instance used to run Lua code.
/// </summary>
Script Interpreter { get; }
/// <summary>
/// Loads and compiles a string containing Lua script, returning a closure (Lua function) which can be executed later.
/// <param name="luaString">The Lua code to be run.</param>
/// <param name="friendlyName">A descriptive name to be used in error reports.</param>
/// </summary>
Closure LoadLuaFunction(string luaString, string friendlyName);
/// <summary>
/// Load and run a previously compiled Lua script. May be run as a coroutine.
/// <param name="fn">A previously compiled Lua function.</param>
/// <param name="runAsCoroutine">Run the Lua code as a coroutine to support asynchronous operations.</param>
/// <param name="onComplete">Method to callback when the Lua code finishes exection. Supports return parameters.</param>
/// </summary>
void RunLuaFunction(Closure fn, bool runAsCoroutine, System.Action<DynValue> onComplete = null);
/// <summary>
/// Load and run a string containing Lua script. May be run as a coroutine.
/// <param name="luaString">The Lua code to be run.</param>
/// <param name="friendlyName">A descriptive name to be used in error reports.</param>
/// <param name="runAsCoroutine">Run the Lua code as a coroutine to support asynchronous operations.</param>
/// <param name="onComplete">Method to callback when the Lua code finishes exection. Supports return parameters.</param>
/// </summary>
void DoLuaString(string luaString, string friendlyName, bool runAsCoroutine, System.Action<DynValue> onComplete = null);
}
}

64
Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/LuaScriptLoader.cs vendored

@ -0,0 +1,64 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using MoonSharp.Interpreter.Loaders;
using System.Collections.Generic;
using System;
using MoonSharp.Interpreter;
namespace Fungus
{
/// <summary>
/// Custom file loader for MoonSharp that loads in all Lua scripts in the project.
/// Scripts must be placed in a Resources/Lua directory.
/// </summary>
public class LuaScriptLoader : ScriptLoaderBase///
{
// Give the script loader access to the list of accessible Lua Modules.
protected IEnumerable<TextAsset> luaScripts;
/// <summary>
// Bypasses the standard path resolution logic for require.
/// </summary>
protected override string ResolveModuleName(string modname, string[] paths)
{
return modname;
}
#region Public members
public LuaScriptLoader(IEnumerable<TextAsset> luaScripts)
{
this.luaScripts = luaScripts;
}
public override object LoadFile(string file, Table globalContext)
{
foreach (TextAsset luaScript in luaScripts)
{
// Case insensitive string compare to allow standard Lua naming conventions in code
if (String.Compare(luaScript.name, file, true) == 0)
{
return luaScript.text;
}
}
return "";
}
public override bool ScriptFileExists(string name)
{
foreach (TextAsset luaScript in luaScripts)
{
// Case insensitive string compare to allow standard Lua naming conventions in code
if (String.Compare(luaScript.name, name, true) == 0)
{
return true;
}
}
return false;
}
#endregion
}
}

4
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaEnvironment.cs.meta → Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/LuaScriptLoader.cs.meta vendored

@ -1,6 +1,6 @@
fileFormatVersion: 2
guid: 73324073029d844479927d75293a9c38
timeCreated: 1473436184
guid: 46edd67be52d94203bad78d03e01efed
timeCreated: 1475067497
licenseType: Free
MonoImporter:
serializedVersion: 2
Loading…
Cancel
Save