Преглед изворни кода

Fix: throw exception if "attempt to yield across a C#-call boundary"

Akeit0 пре 1 година
родитељ
комит
73f6ac6566
1 измењених фајлова са 6 додато и 1 уклоњено
  1. 6 1
      src/Lua/LuaCoroutine.cs

+ 6 - 1
src/Lua/LuaCoroutine.cs

@@ -219,7 +219,12 @@ public sealed class LuaCoroutine : LuaThread, IValueTaskSource<LuaCoroutine.Yiel
         {
             throw new LuaRuntimeException(context.State.GetTraceback(), "cannot call yield on a coroutine that is not currently running");
         }
-
+        
+        if (context.Thread.GetCallStackFrames()[^2].Function is not Closure)
+        {
+            throw new LuaRuntimeException(context.State.GetTraceback(), "attempt to yield across a C#-call boundary");
+        }
+        
         resume.SetResult(new()
         {
             Results = context.Arguments.ToArray(),