diff --git a/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs b/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs
index c42eb009..2c71b168 100644
--- a/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs
+++ b/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs
@@ -92,7 +92,7 @@ namespace Fungus
Continue();
}
- luaEnvironment.RunLuaFunction(luaFunction, GetLuaString(), runAsCoroutine, (returnValue) => {
+ luaEnvironment.RunLuaFunction(luaFunction, runAsCoroutine, (returnValue) => {
StoreReturnVariable(returnValue);
if (waitUntilFinished)
{
diff --git a/Assets/Fungus/Lua/Scripts/LuaExtensions.cs b/Assets/Fungus/Lua/Scripts/LuaExtensions.cs
index 2ddb6be0..40141419 100644
--- a/Assets/Fungus/Lua/Scripts/LuaExtensions.cs
+++ b/Assets/Fungus/Lua/Scripts/LuaExtensions.cs
@@ -41,7 +41,7 @@ namespace Fungus
if (callBack != null)
{
- luaEnvironment.RunLuaFunction(callBack, text, true);
+ luaEnvironment.RunLuaFunction(callBack, true);
}
});
@@ -89,7 +89,7 @@ namespace Fungus
if (callBack != null)
{
- luaEnvironment.RunLuaFunction(callBack, "menutimer", true);
+ luaEnvironment.RunLuaFunction(callBack, true);
}
}
}
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs
index 95dc5dfe..30cafe6e 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs
@@ -235,11 +235,10 @@ namespace Fungus
///
/// Load and run a previously compiled Lua script. May be run as a coroutine.
/// A previously compiled Lua function.
- /// The Lua code to display in case of an error.
/// Run the Lua code as a coroutine to support asynchronous operations.
/// Method to callback when the Lua code finishes exection. Supports return parameters.
///
- public virtual void RunLuaFunction(Closure fn, string luaString, bool runAsCoroutine, Action onComplete = null)
+ public virtual void RunLuaFunction(Closure fn, bool runAsCoroutine, Action onComplete = null)
{
if (fn == null)
{
@@ -254,7 +253,7 @@ namespace Fungus
// Execute the Lua script
if (runAsCoroutine)
{
- StartCoroutine(RunLuaCoroutine(fn, luaString, onComplete));
+ StartCoroutine(RunLuaCoroutine(fn, onComplete));
}
else
{
@@ -265,7 +264,7 @@ namespace Fungus
}
catch (InterpreterException ex)
{
- LogException(ex.DecoratedMessage, luaString);
+ LogException(ex.DecoratedMessage, GetSourceCode());
}
if (onComplete != null)
@@ -285,16 +284,15 @@ namespace Fungus
public virtual void DoLuaString(string luaString, string friendlyName, bool runAsCoroutine, Action onComplete = null)
{
Closure fn = LoadLuaString(luaString, friendlyName);
- RunLuaFunction(fn, luaString, runAsCoroutine, onComplete);
+ RunLuaFunction(fn, runAsCoroutine, onComplete);
}
///
/// A Unity coroutine method which updates a Lua coroutine each frame.
/// A MoonSharp closure object representing a function.
- /// Debug text to display if an exception occurs (usually the Lua code that is being executed).
/// A delegate method that is called when the coroutine completes. Includes return parameter.
///
- protected virtual IEnumerator RunLuaCoroutine(Closure closure, string debugInfo, Action onComplete = null)
+ protected virtual IEnumerator RunLuaCoroutine(Closure closure, Action onComplete = null)
{
DynValue co = interpreter.CreateCoroutine(closure);
@@ -307,7 +305,7 @@ namespace Fungus
}
catch (InterpreterException ex)
{
- LogException(ex.DecoratedMessage, debugInfo);
+ LogException(ex.DecoratedMessage, GetSourceCode());
}
yield return null;
@@ -319,6 +317,21 @@ namespace Fungus
}
}
+ protected virtual string GetSourceCode()
+ {
+ // Get most recently executed source code
+ string sourceCode = "";
+ if (interpreter.SourceCodeCount > 0)
+ {
+ MoonSharp.Interpreter.Debugging.SourceCode sc = interpreter.GetSourceCode(interpreter.SourceCodeCount - 1);
+ if (sc != null)
+ {
+ sourceCode = sc.Code;
+ }
+ }
+ return sourceCode;
+ }
+
///
/// Start a Unity coroutine from a Lua call.
///
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs
index 15b8350a..f72aff48 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs
@@ -138,7 +138,7 @@ namespace Fungus
}
else
{
- luaEnvironment.RunLuaFunction(luaFunction, GetLuaString(), runAsCoroutine);
+ luaEnvironment.RunLuaFunction(luaFunction, runAsCoroutine);
}
}
}