Throw Lua errors on lua cothread they were done on (instead of the main cothread)

Fixes #4252
This commit is contained in:
CasualPokePlayer 2025-03-01 22:29:55 -08:00
parent a42b259762
commit 05722664e0
5 changed files with 112 additions and 56 deletions

View File

@ -328,22 +328,6 @@ namespace NLua
return Translator.PopValues(State, oldTop)[0] as string;
}
/// <summary>
/// Convert C# exceptions into Lua errors
/// </summary>
/// <returns>num of things on stack</returns>
/// <param name = "e">null for no pending exception</param>
internal int SetPendingException(Exception e)
{
if (e == null)
{
return 0;
}
Translator.ThrowError(State, e);
return 1;
}
/// <summary>
///
/// </summary>

View File

@ -1246,11 +1246,13 @@ namespace NLua
e.GetBaseException().Data["Traceback"] = _translator.interpreter.GetDebugTraceback();
}
return _translator.Interpreter.SetPendingException(e.GetBaseException());
_translator.ThrowError(luaState, e.GetBaseException());
return 1;
}
catch (Exception e)
{
return _translator.Interpreter.SetPendingException(e);
_translator.ThrowError(luaState, e);
return 1;
}
}

View File

@ -95,14 +95,6 @@ namespace NLua.Method
return methods.Concat(baseMethods).ToArray();
}
/// <summary>
/// Convert C# exceptions into Lua errors
/// </summary>
/// <returns>num of things on stack</returns>
/// <param name="e">null for no pending exception</param>
internal int SetPendingException(Exception e)
=> _translator.interpreter.SetPendingException(e);
internal int FillMethodArguments(LuaState luaState, int numStackToSkip)
{
var args = _lastCalledMethod.args;
@ -171,13 +163,18 @@ namespace NLua.Method
catch (TargetInvocationException e)
{
// Failure of method invocation
if (_translator.interpreter.UseTraceback)
if (_translator.interpreter.UseTraceback)
{
e.GetBaseException().Data["Traceback"] = _translator.interpreter.GetDebugTraceback();
return SetPendingException(e.GetBaseException());
}
_translator.ThrowError(luaState, e.GetBaseException());
return 1;
}
catch (Exception e)
{
return SetPendingException(e);
_translator.ThrowError(luaState, e);
return 1;
}
return PushReturnValue(luaState);
@ -318,8 +315,6 @@ namespace NLua.Method
throw new LuaException("Lua stack overflow");
}
SetPendingException(null);
// Method from name
if (_method == null)
{
@ -350,7 +345,7 @@ namespace NLua.Method
return 1;
}
}
else if (!_translator.MatchParameters(luaState, _method, _lastCalledMethod, 0))
else if (!_translator.MatchParameters(luaState, _method, _lastCalledMethod, 0))
{
_translator.ThrowError(luaState, "Invalid arguments to method call");
return 1;

View File

@ -10,11 +10,13 @@
"NLua/1.0.0": {
"dependencies": {
"DotNetAnalyzers.DocumentationAnalyzers": "1.0.0-beta.59",
"Menees.Analyzers": "3.0.10",
"Meziantou.Analyzer": "2.0.33",
"Menees.Analyzers": "3.2.2",
"Meziantou.Analyzer": "2.0.163",
"NETStandard.Library": "2.0.3",
"Nullable": "1.3.1",
"StyleCop.Analyzers": "1.2.0-beta.435"
"Roslynator.Analyzers": "4.12.11",
"StyleCop.Analyzers": "1.2.0-beta.556",
"System.Memory": "4.6.0"
},
"runtime": {
"NLua.dll": {}
@ -26,8 +28,8 @@
}
},
"DotNetAnalyzers.DocumentationAnalyzers.Unstable/1.0.0.59": {},
"Menees.Analyzers/3.0.10": {},
"Meziantou.Analyzer/2.0.33": {},
"Menees.Analyzers/3.2.2": {},
"Meziantou.Analyzer/2.0.163": {},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
@ -35,12 +37,50 @@
}
},
"Nullable/1.3.1": {},
"StyleCop.Analyzers/1.2.0-beta.435": {
"Roslynator.Analyzers/4.12.11": {},
"StyleCop.Analyzers/1.2.0-beta.556": {
"dependencies": {
"StyleCop.Analyzers.Unstable": "1.2.0.435"
"StyleCop.Analyzers.Unstable": "1.2.0.556"
}
},
"StyleCop.Analyzers.Unstable/1.2.0.435": {}
"StyleCop.Analyzers.Unstable/1.2.0.556": {},
"System.Buffers/4.6.0": {
"runtime": {
"lib/netstandard2.0/System.Buffers.dll": {
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.600.24.56208"
}
}
},
"System.Memory/4.6.0": {
"dependencies": {
"System.Buffers": "4.6.0",
"System.Numerics.Vectors": "4.6.0",
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
},
"runtime": {
"lib/netstandard2.0/System.Memory.dll": {
"assemblyVersion": "4.0.2.0",
"fileVersion": "4.600.24.56208"
}
}
},
"System.Numerics.Vectors/4.6.0": {
"runtime": {
"lib/netstandard2.0/System.Numerics.Vectors.dll": {
"assemblyVersion": "4.1.3.0",
"fileVersion": "4.600.24.56208"
}
}
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"runtime": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.100.24.56208"
}
}
}
}
},
"libraries": {
@ -63,19 +103,19 @@
"path": "dotnetanalyzers.documentationanalyzers.unstable/1.0.0.59",
"hashPath": "dotnetanalyzers.documentationanalyzers.unstable.1.0.0.59.nupkg.sha512"
},
"Menees.Analyzers/3.0.10": {
"Menees.Analyzers/3.2.2": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ZaCxhd3KKxOqgtDv4YL0Tm6+dhlH+HtXyXrolb6zquAHBR8ONwywofNOb6d8UlafQaNiNdiqVQz8tG4+4NdLyw==",
"path": "menees.analyzers/3.0.10",
"hashPath": "menees.analyzers.3.0.10.nupkg.sha512"
"sha512": "sha512-4A+MGWBlcevNRvtHPU6MG5iIlU0CoFiKTydq8kAAeeZh8k/CZq7CluQ2y79xBAvoY2v15o/ZmC73AuFnZFrXcA==",
"path": "menees.analyzers/3.2.2",
"hashPath": "menees.analyzers.3.2.2.nupkg.sha512"
},
"Meziantou.Analyzer/2.0.33": {
"Meziantou.Analyzer/2.0.163": {
"type": "package",
"serviceable": true,
"sha512": "sha512-LslJaY4cjxOjIM8X7JRMRHL2roG7E28m1ZPFxIcvNp4sfiGQJz0jsHCl9HsblRmXS/IX65eu3qZ15Q3FL2EsPg==",
"path": "meziantou.analyzer/2.0.33",
"hashPath": "meziantou.analyzer.2.0.33.nupkg.sha512"
"sha512": "sha512-vN0YmOkuvPLukMsefLHYCWYaLPzpc6SfoR74aPwuLeK8QdxgxkavywQ1q/II0shLEEaN1RhlMjmL1RxMPW853w==",
"path": "meziantou.analyzer/2.0.163",
"hashPath": "meziantou.analyzer.2.0.163.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
@ -98,19 +138,54 @@
"path": "nullable/1.3.1",
"hashPath": "nullable.1.3.1.nupkg.sha512"
},
"StyleCop.Analyzers/1.2.0-beta.435": {
"Roslynator.Analyzers/4.12.11": {
"type": "package",
"serviceable": true,
"sha512": "sha512-TADk7vdGXtfTnYCV7GyleaaRTQjfoSfZXprQrVMm7cSJtJbFc1QIbWPyLvrgrfGdfHbGmUPvaN4ODKNxg2jgPQ==",
"path": "stylecop.analyzers/1.2.0-beta.435",
"hashPath": "stylecop.analyzers.1.2.0-beta.435.nupkg.sha512"
"sha512": "sha512-yvsRYT5EVtcT+V8ZW+5cxd1O9Sgf8PbC7DlQL/T5NA4g5yjaFe+WQ7evpy92Lj29m2E+XayBsO2TnCWKZlPWaA==",
"path": "roslynator.analyzers/4.12.11",
"hashPath": "roslynator.analyzers.4.12.11.nupkg.sha512"
},
"StyleCop.Analyzers.Unstable/1.2.0.435": {
"StyleCop.Analyzers/1.2.0-beta.556": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ouwPWZxbOV3SmCZxIRqHvljkSzkCyi1tDoMzQtDb/bRP8ctASV/iRJr+A2Gdj0QLaLmWnqTWDrH82/iP+X80Lg==",
"path": "stylecop.analyzers.unstable/1.2.0.435",
"hashPath": "stylecop.analyzers.unstable.1.2.0.435.nupkg.sha512"
"sha512": "sha512-llRPgmA1fhC0I0QyFLEcjvtM2239QzKr/tcnbsjArLMJxJlu0AA5G7Fft0OI30pHF3MW63Gf4aSSsjc5m82J1Q==",
"path": "stylecop.analyzers/1.2.0-beta.556",
"hashPath": "stylecop.analyzers.1.2.0-beta.556.nupkg.sha512"
},
"StyleCop.Analyzers.Unstable/1.2.0.556": {
"type": "package",
"serviceable": true,
"sha512": "sha512-zvn9Mqs/ox/83cpYPignI8hJEM2A93s2HkHs8HYMOAQW0PkampyoErAiIyKxgTLqbbad29HX/shv/6LGSjPJNQ==",
"path": "stylecop.analyzers.unstable/1.2.0.556",
"hashPath": "stylecop.analyzers.unstable.1.2.0.556.nupkg.sha512"
},
"System.Buffers/4.6.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-lN6tZi7Q46zFzAbRYXTIvfXcyvQQgxnY7Xm6C6xQ9784dEL1amjM6S6Iw4ZpsvesAKnRVsM4scrDQaDqSClkjA==",
"path": "system.buffers/4.6.0",
"hashPath": "system.buffers.4.6.0.nupkg.sha512"
},
"System.Memory/4.6.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-OEkbBQoklHngJ8UD8ez2AERSk2g+/qpAaSWWCBFbpH727HxDq5ydVkuncBaKcKfwRqXGWx64dS6G1SUScMsitg==",
"path": "system.memory/4.6.0",
"hashPath": "system.memory.4.6.0.nupkg.sha512"
},
"System.Numerics.Vectors/4.6.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-t+SoieZsRuEyiw/J+qXUbolyO219tKQQI0+2/YI+Qv7YdGValA6WiuokrNKqjrTNsy5ABWU11bdKOzUdheteXg==",
"path": "system.numerics.vectors/4.6.0",
"hashPath": "system.numerics.vectors.4.6.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg==",
"path": "system.runtime.compilerservices.unsafe/6.1.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.1.0.nupkg.sha512"
}
}
}

Binary file not shown.