Browse Source

Rename Lua component to LuaEnvironment

master
chrisgregan 9 years ago
parent
commit
a5f733b3f5
  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
-- 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()
return unity.lua.getTime()
return unity.luaenvironment.getTime()
end
-- 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()
return unity.lua.getDeltaTime()
return unity.luaenvironment.getDeltaTime()
end
-------------
@ -57,7 +57,7 @@ end
function M.run(enumerator)
-- If the parameter isn't an enumerator then CreateTask will fail
local status, err = pcall( function()
local task = unity.lua.RunUnityCoroutine(enumerator)
local task = unity.luaenvironment.RunUnityCoroutine(enumerator)
end)
if (not status) then
@ -70,7 +70,7 @@ end
function M.runwait(enumerator)
-- If the parameter isn't an enumerator then CreateTask will fail
local status, err = pcall( function()
local task = unity.lua.RunUnityCoroutine(enumerator)
local task = unity.luaenvironment.RunUnityCoroutine(enumerator)
while (task != nil and task.Running) do
coroutine.yield();
end
@ -88,18 +88,18 @@ end
-- Set active language for string table
function M.setlanguage(languageCode)
unity.lua.activeLanguage = languageCode
unity.luaenvironment.activeLanguage = languageCode
end
-- Get a named string from the string table
function M.getstring(key)
return unity.lua.GetString(key)
return unity.luaenvironment.GetString(key)
end
-- Substitutes variables and localisation strings into a piece of text
-- e.g. v = 10, "Subbed value is [$v]" => "Subbed value is 10"
function M.sub(text)
return unity.lua.substitute(text)
return unity.luaenvironment.substitute(text)
end
--------------------
@ -211,7 +211,7 @@ function M.menu(text, callback, interactive)
-- Do variable substitution before displaying 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
-- 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.
function M.menutimer(duration, callback)
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)
end

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

@ -10,7 +10,7 @@ GameObject:
- 4: {fileID: 495584}
- 114: {fileID: 11493126}
m_Layer: 0
m_Name: Lua
m_Name: LuaEnvironment
m_TagString: Untagged
m_Icon: {fileID: 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.Flowchart
Fungus.FungusPrefs
Fungus.Lua
Fungus.LuaEnvironment
Fungus.GameObjectVariable
Fungus.IntegerVariable
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
{
[CustomEditor (typeof(Lua))]
public class LuaEditor : Editor
[CustomEditor (typeof(LuaEnvironment))]
public class LuaEnvironmentEditor : Editor
{
protected SerializedProperty registerTypesProp;
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
guid: f4acd124c87104104a6b71bff9b35b0b
timeCreated: 1459332962
guid: 4fba065af9c124bbd837138d28ac0cab
timeCreated: 1459508303
licenseType: Free
MonoImporter:
serializedVersion: 2

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

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

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

@ -11,7 +11,7 @@ namespace Fungus
/// <summary>
/// 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.
/// </summary>
public abstract class LuaBindingsBase : MonoBehaviour
@ -100,7 +100,7 @@ namespace Fungus
// Register types of bound object with MoonSharp
foreach (string typeName in boundTypes)
{
Lua.RegisterType(typeName);
LuaEnvironment.RegisterType(typeName);
}
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
{
public class Lua : MonoBehaviour
public class LuaEnvironment : MonoBehaviour
{
/// <summary>
/// Custom file loader for MoonSharp that loads in all Lua scripts in the project.
@ -64,23 +64,23 @@ namespace Fungus
}
/// <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.
/// </summary>
public static Lua GetLua()
public static LuaEnvironment GetLua()
{
Lua lua = GameObject.FindObjectOfType<Lua>();
if (lua == null)
LuaEnvironment luaEnvironment = GameObject.FindObjectOfType<LuaEnvironment>();
if (luaEnvironment == null)
{
GameObject prefab = Resources.Load<GameObject>("Prefabs/Lua");
GameObject prefab = Resources.Load<GameObject>("Prefabs/LuaEnvironment");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "Lua";
lua = go.GetComponent<Lua>();
go.name = "LuaEnvironment";
luaEnvironment = go.GetComponent<LuaEnvironment>();
}
}
return lua;
return luaEnvironment;
}
protected Script interpreter;
@ -156,8 +156,7 @@ namespace Fungus
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.
// You can restrict which core lua modules are available here if needed.
// See the MoonSharp documentation for details.
// You can restrict which core lua modules are available here if needed. See the MoonSharp documentation for details.
interpreter = new Script(CoreModules.Preset_Complete);
InitLuaScriptFiles();
@ -269,8 +268,8 @@ namespace Fungus
UserData.RegisterType(typeof(PODTypeFactory));
unityTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory));
// This Lua object
unityTable["lua"] = this;
// This Lua Environment component
unityTable["luaenvironment"] = this;
// Provide access to the Unity Test Tools (if available).
Type testType = Type.GetType("IntegrationTest");
@ -538,7 +537,7 @@ namespace Fungus
/// <summary>
/// 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.
/// </summary>
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;
/// <summary>
/// The Lua script environment to use when executing.
/// The Lua Environment to use when executing Lua script.
/// </summary>
[Tooltip("The Lua environment to use when executing.")]
public Lua luaEnvironment;
[Tooltip("The Lua Environment to use when executing Lua script.")]
public LuaEnvironment luaEnvironment;
/// <summary>
/// Lua script file to execute.
@ -105,13 +105,13 @@ namespace Fungus
{
if (luaEnvironment == null)
{
// Create a Lua environment if none exists yet
luaEnvironment = Lua.GetLua();
// Create a Lua Environment if none exists yet
luaEnvironment = LuaEnvironment.GetLua();
}
if (luaEnvironment == null)
{
Debug.LogError("No Lua environment found");
Debug.LogError("No Lua Environment found");
return;
}
@ -293,7 +293,7 @@ namespace Fungus
{
if (luaEnvironment == null)
{
Debug.LogWarning("No Lua component selected");
Debug.LogWarning("No Lua Environment found");
}
else
{

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

@ -8,11 +8,11 @@ namespace Fungus
[CommandInfo("Scripting",
"Execute Lua",
"Executes a Lua code chunk using a Lua component.")]
"Executes a Lua code chunk using a Lua Environment.")]
public class ExecuteLua : Command
{
[Tooltip("Lua environment to use to execute this Lua script")]
public Lua luaEnvironment;
[Tooltip("Lua Environment to use to execute this Lua script")]
public LuaEnvironment luaEnvironment;
[TextArea(10,100)]
[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)
{
luaEnvironment = Lua.GetLua();
luaEnvironment = LuaEnvironment.GetLua();
}
}
public override void OnEnter()
{
// 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)
{
luaEnvironment = Lua.GetLua();
luaEnvironment = LuaEnvironment.GetLua();
}
if (luaEnvironment == null)
{
Debug.LogError("No Lua environment found");
Debug.LogError("No Lua Environment found");
Continue();
return;
}

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

@ -13,7 +13,7 @@ namespace Fungus
/// <summary>
/// Extension for MenuDialog that allows AddOption to call a Lua function when an option is selected.
/// </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;
foreach (Button button in menuDialog.cachedButtons)
@ -41,7 +41,7 @@ namespace Fungus
if (callBack != null)
{
lua.RunLuaCoroutine(callBack, text);
luaEnvironment.RunLuaCoroutine(callBack, text);
}
});
@ -56,7 +56,7 @@ namespace Fungus
/// <summary>
/// Extension for MenuDialog that allows ShowTimer to call a Lua function when the timer expires.
/// </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 ||
duration <= 0f)
@ -89,7 +89,7 @@ namespace Fungus
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
unity.lua.timeScale = 0.5
unity.luaenvironment.timeScale = 0.5
t= fungus.time()
@ -882,7 +882,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &1228088164
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1502,7 +1502,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &1900871525
MonoBehaviour:
m_ObjectHideFlags: 0

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

Loading…
Cancel
Save