|
@@ -15,7 +15,7 @@ public sealed class Closure : LuaFunction
|
|
|
for (int i = 0; i < proto.UpValues.Length; i++)
|
|
for (int i = 0; i < proto.UpValues.Length; i++)
|
|
|
{
|
|
{
|
|
|
var description = proto.UpValues[i];
|
|
var description = proto.UpValues[i];
|
|
|
- var upValue = GetUpValueFromDescription(state, environment == null ? state.EnvUpValue : UpValue.Closed(state.CurrentThread, environment), proto, description);
|
|
|
|
|
|
|
+ var upValue = GetUpValueFromDescription(state, environment == null ? state.EnvUpValue : UpValue.Closed(environment), proto, description, 1);
|
|
|
upValues.Add(upValue);
|
|
upValues.Add(upValue);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -30,12 +30,14 @@ public sealed class Closure : LuaFunction
|
|
|
return LuaVirtualMachine.ExecuteClosureAsync(context.State, this, context.State.CurrentThread.GetCurrentFrame(), buffer, cancellationToken);
|
|
return LuaVirtualMachine.ExecuteClosureAsync(context.State, this, context.State.CurrentThread.GetCurrentFrame(), buffer, cancellationToken);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static UpValue GetUpValueFromDescription(LuaState state, UpValue envUpValue, Chunk proto, UpValueInfo description)
|
|
|
|
|
|
|
+ static UpValue GetUpValueFromDescription(LuaState state, UpValue envUpValue, Chunk proto, UpValueInfo description, int depth)
|
|
|
{
|
|
{
|
|
|
if (description.IsInRegister)
|
|
if (description.IsInRegister)
|
|
|
{
|
|
{
|
|
|
var thread = state.CurrentThread;
|
|
var thread = state.CurrentThread;
|
|
|
- return state.GetOrAddUpValue(thread, thread.GetCurrentFrame().Base + description.Index);
|
|
|
|
|
|
|
+ var callStack = thread.GetCallStackFrames();
|
|
|
|
|
+ var frame = callStack[^depth];
|
|
|
|
|
+ return state.GetOrAddUpValue(thread, frame.Base + description.Index);
|
|
|
}
|
|
}
|
|
|
else if (description.Index == -1) // -1 is global environment
|
|
else if (description.Index == -1) // -1 is global environment
|
|
|
{
|
|
{
|
|
@@ -43,7 +45,7 @@ public sealed class Closure : LuaFunction
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- return GetUpValueFromDescription(state, envUpValue, proto.Parent!, proto.Parent!.UpValues[description.Index]);
|
|
|
|
|
|
|
+ return GetUpValueFromDescription(state, envUpValue, proto.Parent!, proto.Parent!.UpValues[description.Index], depth + 1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|