Browse Source

Refactored FungusLua classes to match layout in main Fungus project.

master
Christopher 8 years ago
parent
commit
066bb719a9
  1. 36
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaBindings.cs
  2. 22
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs
  3. 23
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironmentInitializer.cs
  4. 12
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironmentInitializer.cs.meta
  5. 3
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaScript.cs
  6. 3
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaStore.cs
  7. 24
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs
  8. 4
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs
  9. 5
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IExecuteHandler.cs
  10. 24
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaBindings.cs
  11. 5
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaEnvironment.cs
  12. 3
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaScript.cs
  13. 5
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaStore.cs
  14. 20
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs
  15. 5
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IStringSubstituter.cs

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

@ -2,7 +2,6 @@
// 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;
using MoonSharp.Interpreter;
@ -15,10 +14,9 @@ namespace Fungus
/// </summary>
public abstract class LuaBindingsBase : MonoBehaviour, ILuaBindings
{
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
public abstract void AddBindings(ILuaEnvironment luaEnv);
public abstract List<BoundObject> BoundObjects { get; }
}
/// <summary>
@ -27,26 +25,12 @@ namespace Fungus
[ExecuteInEditMode]
public class LuaBindings : LuaBindingsBase
{
/// <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;
}
[Tooltip("Add bindings to every Lua Environment in the scene. If false, only add bindings to a specific Lua Environment.")]
[SerializeField] protected bool allEnvironments = true;
[Tooltip("The specific LuaEnvironment to register the bindings in.")]
[SerializeField] protected LuaEnvironment luaEnvironment;
/// <summary>
/// Name of global table variable to store bindings in. If left blank then each binding will be added as a global variable.
/// </summary>
[Tooltip("Name of global table variable to store bindings in. If left blank then each binding will be added as a global variable.")]
[SerializeField] protected string tableName = "";
@ -56,19 +40,12 @@ namespace Fungus
[HideInInspector]
[SerializeField] protected List<string> boundTypes = new List<string>();
/// <summary>
/// The list of Unity objects to be bound for access in Lua.
/// </summary>
[Tooltip("The list of Unity objects to be bound to make them accessible in Lua script.")]
[SerializeField] protected List<BoundObject> boundObjects = new List<BoundObject>();
public virtual List<BoundObject> BoundObjects { get { return boundObjects; } }
[Tooltip("Show inherited public members.")]
[SerializeField] protected bool showInherited;
/// <summary>
/// Always ensure there is at least one row in the bound objects list.
/// </summary>
protected virtual void Update()
{
// Add in a single empty line at start
@ -78,9 +55,8 @@ namespace Fungus
}
}
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
#region ILuaBindings implementation
public override void AddBindings(ILuaEnvironment luaEnv)
{
if (!allEnvironments &&
@ -170,5 +146,9 @@ namespace Fungus
}
}
}
public override List<BoundObject> BoundObjects { get { return boundObjects; } }
#endregion
}
}

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

@ -18,22 +18,6 @@ namespace Fungus
/// </summary>
public class LuaEnvironment : MonoBehaviour, ILuaEnvironment
{
/// <summary>
/// Helper class used to extend the initialization behavior of LuaEnvironment.
/// </summary>
public abstract class Initializer : MonoBehaviour
{
/// <summary>
/// Called when the LuaEnvironment is initializing.
/// </summary>
public abstract void Initialize();
/// <summary>
/// Applies transformations to the input script prior to execution.
/// </summary>
public abstract string PreprocessScript(string input);
}
/// <summary>
/// Custom file loader for MoonSharp that loads in all Lua scripts in the project.
/// Scripts must be placed in a Resources/Lua directory.
@ -308,8 +292,8 @@ namespace Fungus
InitLuaScriptFiles();
// Initialize any attached initializer components (e.g. LuaUtils)
Initializer[] initializers = GetComponents<Initializer>();
foreach (Initializer initializer in initializers)
LuaEnvironmentInitializer[] initializers = GetComponents<LuaEnvironmentInitializer>();
foreach (LuaEnvironmentInitializer initializer in initializers)
{
initializer.Initialize();
}
@ -329,7 +313,7 @@ namespace Fungus
InitEnvironment();
string processedString;
Initializer initializer = GetComponent<Initializer>();
var initializer = GetComponent<LuaEnvironmentInitializer>();
if (initializer != null)
{
processedString = initializer.PreprocessScript(luaString);

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

@ -0,0 +1,23 @@
// 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;
namespace Fungus
{
/// <summary>
/// Helper class used to extend the initialization behavior of LuaEnvironment.
/// </summary>
public abstract class LuaEnvironmentInitializer : MonoBehaviour
{
/// <summary>
/// Called when the LuaEnvironment is initializing.
/// </summary>
public abstract void Initialize();
/// <summary>
/// Applies transformations to the input script prior to execution.
/// </summary>
public abstract string PreprocessScript(string input);
}
}

12
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironmentInitializer.cs.meta vendored

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

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

@ -1,9 +1,6 @@
// 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)
// Adapted from the Unity Test Tools project (MIT license)
// https://bitbucket.org/Unity-Technologies/unitytesttools/src/a30d562427e9/Assets/UnityTestTools/
using UnityEngine;
using MoonSharp.Interpreter;
using Debug = UnityEngine.Debug;

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

@ -3,6 +3,7 @@
using UnityEngine;
using MoonSharp.Interpreter;
using System.Collections.Generic;
namespace Fungus
{
@ -93,6 +94,8 @@ namespace Fungus
}
}
public override List<BoundObject> BoundObjects { get { return null; } }
#endregion
#region ILuaStore implementation

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

@ -15,28 +15,13 @@ namespace Fungus
/// <summary>
/// A collection of utilites to use in Lua for common Unity / Fungus tasks.
/// </summary>
public class LuaUtils : LuaEnvironment.Initializer, ISubstitutionHandler, ILuaUtils
public class LuaUtils : LuaEnvironmentInitializer, ISubstitutionHandler, ILuaUtils
{
public enum FungusModuleOptions
{
UseGlobalVariables, // Fungus helper items will be available as global variables.
UseFungusVariable, // Fungus helper items will be available in the 'fungus' global variable.
NoFungusModule // The fungus helper module will not be loaded.
}
/// <summary>
/// Controls if the fungus utilities are accessed from globals (e.g. say) or via a fungus variable (e.g. fungus.say)"
/// You can also choose to disable loading the fungus module if it's not required by your script.
/// </summary>
[Tooltip("Controls if the fungus utilities are accessed from globals (e.g. say) or via a fungus variable (e.g. fungus.say)")]
[Tooltip("Controls if the fungus utilities are accessed from globals (e.g. say) or via a fungus variable (e.g. fungus.say). You can also choose to disable loading the fungus module if it's not required by your script.")]
[SerializeField] protected FungusModuleOptions fungusModule = FungusModuleOptions.UseGlobalVariables;
/// <summary>
/// The currently selected language in the string table. Affects variable substitution.
/// </summary>
[Tooltip("The currently selected language in the string table. Affects variable substitution.")]
[SerializeField] protected string activeLanguage = "en";
public virtual string ActiveLanguage { get { return activeLanguage; } set { activeLanguage = value; } }
/// <summary>
/// Lua script file which defines the global string table used for localisation.
@ -298,9 +283,6 @@ namespace Fungus
InitBindings();
}
/// <summary>
/// Called by LuaEnvironment prior to executing a script.
/// </summary>
public override string PreprocessScript(string input)
{
return input;
@ -310,6 +292,8 @@ namespace Fungus
#region ILuaUtils implementation
public virtual string ActiveLanguage { get { return activeLanguage; } set { activeLanguage = value; } }
public virtual string GetString(string key)
{
if (stringTable != null)

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

@ -201,7 +201,7 @@ namespace Fungus
details.Add("");
LuaBindings luaBindings = target as LuaBindings;
foreach (LuaBindings.BoundObject boundObject in luaBindings.BoundObjects)
foreach (BoundObject boundObject in luaBindings.BoundObjects)
{
UnityEngine.Object inspectObject = boundObject.obj;
if (boundObject.component != null)
@ -408,7 +408,7 @@ namespace Fungus
// Use a temp HashSet to store the list of types.
// The final list is stored as a list of type strings.
HashSet<System.Type> typeSet = new HashSet<System.Type>();
foreach (LuaBindings.BoundObject boundObject in luaBindings.BoundObjects)
foreach (BoundObject boundObject in luaBindings.BoundObjects)
{
if (boundObject.obj == null)
{

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

@ -1,4 +1,7 @@
using System;
// 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
{

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

@ -1,8 +1,23 @@
using UnityEngine;
using System.Collections;
// 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>
@ -12,5 +27,10 @@ namespace Fungus
/// 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; }
}
}

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

@ -1,4 +1,7 @@
using MoonSharp.Interpreter;
// 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
{

3
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaScript.cs vendored

@ -1,4 +1,5 @@
using UnityEngine;
// 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
{

5
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaStore.cs vendored

@ -1,4 +1,7 @@
using MoonSharp.Interpreter;
// 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
{

20
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/ILuaUtils.cs vendored

@ -1,11 +1,29 @@
using UnityEngine;
// 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.Collections;
using System.Text;
namespace Fungus
{
/// <summary>
/// Options for using the Lua FungusModule.
/// </summary>
public enum FungusModuleOptions
{
UseGlobalVariables, // Fungus helper items will be available as global variables.
UseFungusVariable, // Fungus helper items will be available in the 'fungus' global variable.
NoFungusModule // The fungus helper module will not be loaded.
}
public interface ILuaUtils
{
/// <summary>
/// The currently selected language in the string table. Affects variable substitution.
/// </summary>
string ActiveLanguage { get; set; }
/// <summary>
/// Returns a string from the string table for this key.
/// The string returned depends on the active language.

5
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IStringSubstituter.cs vendored

@ -1,4 +1,7 @@
using System.Text;
// 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.Text;
namespace Fungus
{

Loading…
Cancel
Save