浏览代码

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(),