|
@@ -15,6 +15,7 @@ public abstract partial class LuaFunction
|
|
|
ChunkName = context.ChunkName ?? LuaState.DefaultChunkName,
|
|
ChunkName = context.ChunkName ?? LuaState.DefaultChunkName,
|
|
|
RootChunkName = context.RootChunkName ?? LuaState.DefaultChunkName,
|
|
RootChunkName = context.RootChunkName ?? LuaState.DefaultChunkName,
|
|
|
VariableArgumentCount = this is Closure closure ? context.ArgumentCount - closure.Proto.ParameterCount : 0,
|
|
VariableArgumentCount = this is Closure closure ? context.ArgumentCount - closure.Proto.ParameterCount : 0,
|
|
|
|
|
+ Function = this,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
state.PushCallStackFrame(frame);
|
|
state.PushCallStackFrame(frame);
|
|
@@ -30,38 +31,4 @@ public abstract partial class LuaFunction
|
|
|
|
|
|
|
|
public virtual string Name => GetType().Name;
|
|
public virtual string Name => GetType().Name;
|
|
|
protected abstract ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken);
|
|
protected abstract ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken);
|
|
|
-
|
|
|
|
|
- protected void ThrowIfArgumentNotExists(LuaFunctionExecutionContext context, int index)
|
|
|
|
|
- {
|
|
|
|
|
- if (context.ArgumentCount <= index)
|
|
|
|
|
- {
|
|
|
|
|
- LuaRuntimeException.BadArgument(context.State.GetTracebacks(), index + 1, Name);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected LuaValue ReadArgument(LuaFunctionExecutionContext context, int index)
|
|
|
|
|
- {
|
|
|
|
|
- ThrowIfArgumentNotExists(context, index);
|
|
|
|
|
- return context.Arguments[index];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- protected T ReadArgument<T>(LuaFunctionExecutionContext context, int index)
|
|
|
|
|
- {
|
|
|
|
|
- ThrowIfArgumentNotExists(context, index);
|
|
|
|
|
-
|
|
|
|
|
- var arg = context.Arguments[index];
|
|
|
|
|
- if (!arg.TryRead<T>(out var argValue))
|
|
|
|
|
- {
|
|
|
|
|
- if (LuaValue.TryGetLuaValueType(typeof(T), out var type))
|
|
|
|
|
- {
|
|
|
|
|
- LuaRuntimeException.BadArgument(context.State.GetTracebacks(), 1, Name, type.ToString(), arg.Type.ToString());
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- LuaRuntimeException.BadArgument(context.State.GetTracebacks(), 1, Name, typeof(T).Name, arg.Type.ToString());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return argValue;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|