|
|
@@ -1,3 +1,4 @@
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using Lua.Internal;
|
|
|
|
|
|
namespace Lua.Runtime;
|
|
|
@@ -8,7 +9,7 @@ public sealed class Closure : LuaFunction
|
|
|
FastListCore<UpValue> upValues;
|
|
|
|
|
|
public Closure(LuaState state, Chunk proto, LuaTable? environment = null)
|
|
|
- : base(proto.Name, (context, buffer, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, context.Thread.GetCurrentFrame(), buffer, ct))
|
|
|
+ : base(proto.Name, (context, buffer, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, buffer, ct))
|
|
|
{
|
|
|
this.proto = proto;
|
|
|
|
|
|
@@ -19,11 +20,26 @@ public sealed class Closure : LuaFunction
|
|
|
var upValue = GetUpValueFromDescription(state, environment == null ? state.EnvUpValue : UpValue.Closed(environment), proto, description, 1);
|
|
|
upValues.Add(upValue);
|
|
|
}
|
|
|
+
|
|
|
+ IsClosure = true;
|
|
|
}
|
|
|
|
|
|
public Chunk Proto => proto;
|
|
|
public ReadOnlySpan<UpValue> UpValues => upValues.AsSpan();
|
|
|
|
|
|
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
+ internal LuaValue GetUpValue(int index)
|
|
|
+ {
|
|
|
+ return upValues[index].GetValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
+ internal void SetUpValue(int index, LuaValue value)
|
|
|
+ {
|
|
|
+ upValues[index].SetValue(value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
static UpValue GetUpValueFromDescription(LuaState state, UpValue envUpValue, Chunk proto, UpValueInfo description, int depth)
|
|
|
{
|
|
|
if (description.IsInRegister)
|