Browse Source

Merge pull request #428 from FungusGames/rename-lua-environment

Rename Lua component to LuaEnvironment
master
Chris Gregan 9 years ago
parent
commit
1de101cd96
  1. 22
      Assets/Fungus/Lua/Resources/Lua/fungus.txt
  2. 2
      Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab
  3. 0
      Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab.meta
  4. 2
      Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt
  5. 4
      Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs
  6. 4
      Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs.meta
  7. 6
      Assets/Fungus/Lua/Scripts/Editor/MenuItems.cs
  8. 4
      Assets/Fungus/Lua/Scripts/LuaBindings.cs
  9. 27
      Assets/Fungus/Lua/Scripts/LuaEnvironment.cs
  10. 0
      Assets/Fungus/Lua/Scripts/LuaEnvironment.cs.meta
  11. 14
      Assets/Fungus/Lua/Scripts/LuaScript.cs
  12. 14
      Assets/Fungus/Lua/Thirdparty/FungusExtensions/ExecuteLua.cs
  13. 8
      Assets/Fungus/Lua/Thirdparty/FungusExtensions/LuaExtensions.cs
  14. 6
      Assets/Tests/Lua/LuaEnvironmentTests.unity
  15. 0
      Assets/Tests/Lua/LuaEnvironmentTests.unity.meta

22
Assets/Fungus/Lua/Resources/Lua/fungus.txt

@ -16,15 +16,15 @@ end
------- -------
-- Returns the absolute time -- Returns the absolute time
-- Use this timing function to work correctly with the Lua component's timeScale property -- Use this timing function to work correctly with the Lua Environment's timeScale property
function M.time() function M.time()
return unity.lua.getTime() return unity.luaenvironment.getTime()
end end
-- Returns the delta time this frame -- Returns the delta time this frame
-- Use this timing function to work correctly with the Lua component's timeScale property -- Use this timing function to work correctly with the Lua Environment's timeScale property
function M.deltatime() function M.deltatime()
return unity.lua.getDeltaTime() return unity.luaenvironment.getDeltaTime()
end end
------------- -------------
@ -57,7 +57,7 @@ end
function M.run(enumerator) function M.run(enumerator)
-- If the parameter isn't an enumerator then CreateTask will fail -- If the parameter isn't an enumerator then CreateTask will fail
local status, err = pcall( function() local status, err = pcall( function()
local task = unity.lua.RunUnityCoroutine(enumerator) local task = unity.luaenvironment.RunUnityCoroutine(enumerator)
end) end)
if (not status) then if (not status) then
@ -70,7 +70,7 @@ end
function M.runwait(enumerator) function M.runwait(enumerator)
-- If the parameter isn't an enumerator then CreateTask will fail -- If the parameter isn't an enumerator then CreateTask will fail
local status, err = pcall( function() local status, err = pcall( function()
local task = unity.lua.RunUnityCoroutine(enumerator) local task = unity.luaenvironment.RunUnityCoroutine(enumerator)
while (task != nil and task.Running) do while (task != nil and task.Running) do
coroutine.yield(); coroutine.yield();
end end
@ -88,18 +88,18 @@ end
-- Set active language for string table -- Set active language for string table
function M.setlanguage(languageCode) function M.setlanguage(languageCode)
unity.lua.activeLanguage = languageCode unity.luaenvironment.activeLanguage = languageCode
end end
-- Get a named string from the string table -- Get a named string from the string table
function M.getstring(key) function M.getstring(key)
return unity.lua.GetString(key) return unity.luaenvironment.GetString(key)
end end
-- Substitutes variables and localisation strings into a piece of text -- Substitutes variables and localisation strings into a piece of text
-- e.g. v = 10, "Subbed value is [$v]" => "Subbed value is 10" -- e.g. v = 10, "Subbed value is [$v]" => "Subbed value is 10"
function M.sub(text) function M.sub(text)
return unity.lua.substitute(text) return unity.luaenvironment.substitute(text)
end end
-------------------- --------------------
@ -211,7 +211,7 @@ function M.menu(text, callback, interactive)
-- Do variable substitution before displaying text -- Do variable substitution before displaying text
local subbed = fungus.sub(text) local subbed = fungus.sub(text)
M.menuoptions.menudialog.AddOption(subbed, interactive or true, unity.lua, callback) M.menuoptions.menudialog.AddOption(subbed, interactive or true, unity.luaenvironment, callback)
end end
-- Display a timer during which the player has to choose an option. -- Display a timer during which the player has to choose an option.
@ -219,7 +219,7 @@ end
-- callback: Function to call if the timer expires before an option is selected. -- callback: Function to call if the timer expires before an option is selected.
function M.menutimer(duration, callback) function M.menutimer(duration, callback)
assert(M.menuoptions.menudialog, "menudialog must not be nil") assert(M.menuoptions.menudialog, "menudialog must not be nil")
local e = M.menuoptions.menudialog.ShowTimer(duration, unity.lua, callback) local e = M.menuoptions.menudialog.ShowTimer(duration, unity.luaenvironment, callback)
fungus.runwait(e) fungus.runwait(e)
end end

2
Assets/Fungus/Lua/Resources/Prefabs/Lua.prefab → Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab

@ -10,7 +10,7 @@ GameObject:
- 4: {fileID: 495584} - 4: {fileID: 495584}
- 114: {fileID: 11493126} - 114: {fileID: 11493126}
m_Layer: 0 m_Layer: 0
m_Name: Lua m_Name: LuaEnvironment
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0

0
Assets/Fungus/Lua/Resources/Prefabs/Lua.prefab.meta → Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab.meta

2
Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt

@ -18,7 +18,7 @@ Fungus.FacingDirection
Fungus.FloatVariable Fungus.FloatVariable
Fungus.Flowchart Fungus.Flowchart
Fungus.FungusPrefs Fungus.FungusPrefs
Fungus.Lua Fungus.LuaEnvironment
Fungus.GameObjectVariable Fungus.GameObjectVariable
Fungus.IntegerVariable Fungus.IntegerVariable
Fungus.Label Fungus.Label

4
Assets/Fungus/Lua/Scripts/Editor/LuaEditor.cs → Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs

@ -10,8 +10,8 @@ using System.IO;
namespace Fungus namespace Fungus
{ {
[CustomEditor (typeof(Lua))] [CustomEditor (typeof(LuaEnvironment))]
public class LuaEditor : Editor public class LuaEnvironmentEditor : Editor
{ {
protected SerializedProperty registerTypesProp; protected SerializedProperty registerTypesProp;
protected ReorderableList registerTypeList; protected ReorderableList registerTypeList;

4
Assets/Fungus/Lua/Scripts/Editor/LuaEditor.cs.meta → Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs.meta

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f4acd124c87104104a6b71bff9b35b0b guid: 4fba065af9c124bbd837138d28ac0cab
timeCreated: 1459332962 timeCreated: 1459508303
licenseType: Free licenseType: Free
MonoImporter: MonoImporter:
serializedVersion: 2 serializedVersion: 2

6
Assets/Fungus/Lua/Scripts/Editor/MenuItems.cs

@ -8,10 +8,10 @@ namespace Fungus
public class MenuItems public class MenuItems
{ {
[MenuItem("Tools/Fungus/Create/Lua", false, 2000)] [MenuItem("Tools/Fungus/Create/Lua Environment", false, 2000)]
static void CreateLua() static void CreateLuaEnvironment()
{ {
SpawnPrefab("Prefabs/Lua", false); SpawnPrefab("Prefabs/LuaEnvironment", false);
} }
[MenuItem("Tools/Fungus/Create/Lua Bindings", false, 2001)] [MenuItem("Tools/Fungus/Create/Lua Bindings", false, 2001)]

4
Assets/Fungus/Lua/Scripts/LuaBindings.cs

@ -11,7 +11,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Base class for a component which registers Lua Bindings. /// Base class for a component which registers Lua Bindings.
/// When the Lua component initialises, it finds all components in the scene that inherit /// When the Lua Environment initialises, it finds all components in the scene that inherit
/// from LuaBindingsBase and calls them to add their bindings. /// from LuaBindingsBase and calls them to add their bindings.
/// </summary> /// </summary>
public abstract class LuaBindingsBase : MonoBehaviour public abstract class LuaBindingsBase : MonoBehaviour
@ -100,7 +100,7 @@ namespace Fungus
// Register types of bound object with MoonSharp // Register types of bound object with MoonSharp
foreach (string typeName in boundTypes) foreach (string typeName in boundTypes)
{ {
Lua.RegisterType(typeName); LuaEnvironment.RegisterType(typeName);
} }
for (int i = 0; i < boundObjects.Count; ++i) for (int i = 0; i < boundObjects.Count; ++i)

27
Assets/Fungus/Lua/Scripts/Lua.cs → Assets/Fungus/Lua/Scripts/LuaEnvironment.cs

@ -13,7 +13,7 @@ using MoonSharp.RemoteDebugger;
namespace Fungus namespace Fungus
{ {
public class Lua : MonoBehaviour public class LuaEnvironment : MonoBehaviour
{ {
/// <summary> /// <summary>
/// Custom file loader for MoonSharp that loads in all Lua scripts in the project. /// Custom file loader for MoonSharp that loads in all Lua scripts in the project.
@ -64,23 +64,23 @@ namespace Fungus
} }
/// <summary> /// <summary>
/// Returns the first Lua component found in the scene, or creates one if none exists. /// 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. /// This is a slow operation, call it once at startup and cache the returned value.
/// </summary> /// </summary>
public static Lua GetLua() public static LuaEnvironment GetLua()
{ {
Lua lua = GameObject.FindObjectOfType<Lua>(); LuaEnvironment luaEnvironment = GameObject.FindObjectOfType<LuaEnvironment>();
if (lua == null) if (luaEnvironment == null)
{ {
GameObject prefab = Resources.Load<GameObject>("Prefabs/Lua"); GameObject prefab = Resources.Load<GameObject>("Prefabs/LuaEnvironment");
if (prefab != null) if (prefab != null)
{ {
GameObject go = Instantiate(prefab) as GameObject; GameObject go = Instantiate(prefab) as GameObject;
go.name = "Lua"; go.name = "LuaEnvironment";
lua = go.GetComponent<Lua>(); luaEnvironment = go.GetComponent<LuaEnvironment>();
} }
} }
return lua; return luaEnvironment;
} }
protected Script interpreter; protected Script interpreter;
@ -156,8 +156,7 @@ namespace Fungus
Script.DefaultOptions.DebugPrint = (s) => { UnityEngine.Debug.Log(s); }; Script.DefaultOptions.DebugPrint = (s) => { UnityEngine.Debug.Log(s); };
// In some use cases (e.g. downloadable Lua files) some Lua modules can pose a potential security risk. // In some use cases (e.g. downloadable Lua files) some Lua modules can pose a potential security risk.
// You can restrict which core lua modules are available here if needed. // You can restrict which core lua modules are available here if needed. See the MoonSharp documentation for details.
// See the MoonSharp documentation for details.
interpreter = new Script(CoreModules.Preset_Complete); interpreter = new Script(CoreModules.Preset_Complete);
InitLuaScriptFiles(); InitLuaScriptFiles();
@ -269,8 +268,8 @@ namespace Fungus
UserData.RegisterType(typeof(PODTypeFactory)); UserData.RegisterType(typeof(PODTypeFactory));
unityTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory)); unityTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory));
// This Lua object // This Lua Environment component
unityTable["lua"] = this; unityTable["luaenvironment"] = this;
// Provide access to the Unity Test Tools (if available). // Provide access to the Unity Test Tools (if available).
Type testType = Type.GetType("IntegrationTest"); Type testType = Type.GetType("IntegrationTest");
@ -538,7 +537,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Starts a standard Unity coroutine. /// Starts a standard Unity coroutine.
/// The coroutine is managed by the Lua monobehavior, so you can call StopAllCoroutines to /// The coroutine is managed by the LuaEnvironment monobehavior, so you can call StopAllCoroutines to
/// stop all active coroutines later. /// stop all active coroutines later.
/// </summary> /// </summary>
protected virtual IEnumerator RunUnityCoroutineImpl(IEnumerator coroutine) protected virtual IEnumerator RunUnityCoroutineImpl(IEnumerator coroutine)

0
Assets/Fungus/Lua/Scripts/Lua.cs.meta → Assets/Fungus/Lua/Scripts/LuaEnvironment.cs.meta

14
Assets/Fungus/Lua/Scripts/LuaScript.cs

@ -57,10 +57,10 @@ namespace Fungus
[SerializeField] public ExecuteMethod executeMethods = ExecuteMethod.Start; [SerializeField] public ExecuteMethod executeMethods = ExecuteMethod.Start;
/// <summary> /// <summary>
/// The Lua script environment to use when executing. /// The Lua Environment to use when executing Lua script.
/// </summary> /// </summary>
[Tooltip("The Lua environment to use when executing.")] [Tooltip("The Lua Environment to use when executing Lua script.")]
public Lua luaEnvironment; public LuaEnvironment luaEnvironment;
/// <summary> /// <summary>
/// Lua script file to execute. /// Lua script file to execute.
@ -105,13 +105,13 @@ namespace Fungus
{ {
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
// Create a Lua environment if none exists yet // Create a Lua Environment if none exists yet
luaEnvironment = Lua.GetLua(); luaEnvironment = LuaEnvironment.GetLua();
} }
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
Debug.LogError("No Lua environment found"); Debug.LogError("No Lua Environment found");
return; return;
} }
@ -293,7 +293,7 @@ namespace Fungus
{ {
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
Debug.LogWarning("No Lua component selected"); Debug.LogWarning("No Lua Environment found");
} }
else else
{ {

14
Assets/Fungus/Lua/Thirdparty/FungusExtensions/ExecuteLua.cs vendored

@ -8,11 +8,11 @@ namespace Fungus
[CommandInfo("Scripting", [CommandInfo("Scripting",
"Execute Lua", "Execute Lua",
"Executes a Lua code chunk using a Lua component.")] "Executes a Lua code chunk using a Lua Environment.")]
public class ExecuteLua : Command public class ExecuteLua : Command
{ {
[Tooltip("Lua environment to use to execute this Lua script")] [Tooltip("Lua Environment to use to execute this Lua script")]
public Lua luaEnvironment; public LuaEnvironment luaEnvironment;
[TextArea(10,100)] [TextArea(10,100)]
[Tooltip("Lua script to execute. Use {$VarName} to insert a Flowchart variable in the Lua script.")] [Tooltip("Lua script to execute. Use {$VarName} to insert a Flowchart variable in the Lua script.")]
@ -43,22 +43,22 @@ namespace Fungus
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
luaEnvironment = Lua.GetLua(); luaEnvironment = LuaEnvironment.GetLua();
} }
} }
public override void OnEnter() public override void OnEnter()
{ {
// This command could be executed from the Start of another component, so we // This command could be executed from the Start of another component, so we
// need to check the Lua environment here and in Start. // need to check the Lua Environment here and in Start.
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
luaEnvironment = Lua.GetLua(); luaEnvironment = LuaEnvironment.GetLua();
} }
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
Debug.LogError("No Lua environment found"); Debug.LogError("No Lua Environment found");
Continue(); Continue();
return; return;
} }

8
Assets/Fungus/Lua/Thirdparty/FungusExtensions/LuaExtensions.cs vendored

@ -13,7 +13,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Extension for MenuDialog that allows AddOption to call a Lua function when an option is selected. /// Extension for MenuDialog that allows AddOption to call a Lua function when an option is selected.
/// </summary> /// </summary>
public static bool AddOption(this MenuDialog menuDialog, string text, bool interactable, Lua lua, Closure callBack) public static bool AddOption(this MenuDialog menuDialog, string text, bool interactable, LuaEnvironment luaEnvironment, Closure callBack)
{ {
bool addedOption = false; bool addedOption = false;
foreach (Button button in menuDialog.cachedButtons) foreach (Button button in menuDialog.cachedButtons)
@ -41,7 +41,7 @@ namespace Fungus
if (callBack != null) if (callBack != null)
{ {
lua.RunLuaCoroutine(callBack, text); luaEnvironment.RunLuaCoroutine(callBack, text);
} }
}); });
@ -56,7 +56,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Extension for MenuDialog that allows ShowTimer to call a Lua function when the timer expires. /// Extension for MenuDialog that allows ShowTimer to call a Lua function when the timer expires.
/// </summary> /// </summary>
public static IEnumerator ShowTimer(this MenuDialog menuDialog, float duration, Lua lua, Closure callBack) public static IEnumerator ShowTimer(this MenuDialog menuDialog, float duration, LuaEnvironment luaEnvironment, Closure callBack)
{ {
if (menuDialog.cachedSlider == null || if (menuDialog.cachedSlider == null ||
duration <= 0f) duration <= 0f)
@ -89,7 +89,7 @@ namespace Fungus
if (callBack != null) if (callBack != null)
{ {
lua.RunLuaCoroutine(callBack, "menutimer"); luaEnvironment.RunLuaCoroutine(callBack, "menutimer");
} }
} }
} }

6
Assets/Tests/Lua/LuaTests.unity → Assets/Tests/Lua/LuaEnvironmentTests.unity

@ -842,7 +842,7 @@ MonoBehaviour:
-- Should take 2 seconds in realtime to wait for 1 second -- Should take 2 seconds in realtime to wait for 1 second
unity.lua.timeScale = 0.5 unity.luaenvironment.timeScale = 0.5
t= fungus.time() t= fungus.time()
@ -882,7 +882,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!114 &1228088164 --- !u!114 &1228088164
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1502,7 +1502,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!114 &1900871525 --- !u!114 &1900871525
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

0
Assets/Tests/Lua/LuaTests.unity.meta → Assets/Tests/Lua/LuaEnvironmentTests.unity.meta

Loading…
Cancel
Save