本文整理汇总了C#中CallbackArguments类的典型用法代码示例。如果您正苦于以下问题:C# CallbackArguments类的具体用法?C# CallbackArguments怎么用?C# CallbackArguments使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CallbackArguments类属于命名空间,在下文中一共展示了CallbackArguments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: create
public static DynValue create(ScriptExecutionContext executionContext, CallbackArguments args)
{
if (args[0].Type != DataType.Function && args[0].Type != DataType.ClrFunction)
args.AsType(0, "create", DataType.Function); // this throws
return executionContext.GetScript().CreateCoroutine(args[0]);
}
示例2: type
public static DynValue type(ScriptExecutionContext executionContext, CallbackArguments args)
{
if (args.Count < 1) throw ScriptRuntimeException.BadArgumentValueExpected(0, "type");
DynValue v = args[0];
return DynValue.NewString(v.Type.ToLuaTypeString());
}
示例3: setuservalue
public static DynValue setuservalue(ScriptExecutionContext executionContext, CallbackArguments args)
{
var v = args.AsType(0, "setuservalue", DataType.UserData, false);
var t = args.AsType(0, "setuservalue", DataType.Table, true);
return v.UserData.UserValue = t;
}
示例4: StringBuilder
public static DynValue @char(ScriptExecutionContext executionContext, CallbackArguments args)
{
var sb = new StringBuilder(args.Count);
for (var i = 0; i < args.Count; i++)
{
var v = args[i];
var d = 0d;
if (v.Type == DataType.String)
{
var nd = v.CastToNumber();
if (nd == null)
args.AsType(i, "char", DataType.Number, false);
else
d = nd.Value;
}
else
{
args.AsType(i, "char", DataType.Number, false);
d = v.Number;
}
sb.Append((char) (d));
}
return DynValue.NewString(sb.ToString());
}
示例5: rawget
public static DynValue rawget(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue table = args.AsType(0, "rawget", DataType.Table);
DynValue index = args[1];
return table.Table.Get(index);
}
示例6: eval
public static DynValue eval(ScriptExecutionContext executionContext, CallbackArguments args)
{
try
{
if (args[0].Type == DataType.UserData)
{
UserData ud = args[0].UserData;
if (ud.Object is DynamicExprWrapper)
{
return ((DynamicExprWrapper)ud.Object).Expr.Evaluate(executionContext);
}
else
{
throw ScriptRuntimeException.BadArgument(0, "dynamic.eval", "A userdata was passed, but was not a previously prepared expression.");
}
}
else
{
DynValue vs = args.AsType(0, "dynamic.eval", DataType.String, false);
DynamicExpression expr = executionContext.GetScript().CreateDynamicExpression(vs.String);
return expr.Evaluate(executionContext);
}
}
catch (SyntaxErrorException ex)
{
throw new ScriptRuntimeException(ex);
}
}
示例7: debug
public static DynValue debug(ScriptExecutionContext executionContext, CallbackArguments args)
{
var script = executionContext.GetScript();
if (script.Options.DebugInput == null)
throw new ScriptRuntimeException("debug.debug not supported on this platform/configuration");
var interpreter = new ReplInterpreter(script)
{
HandleDynamicExprs = false,
HandleClassicExprsSyntax = true
};
while (true)
{
var s = script.Options.DebugInput(interpreter.ClassicPrompt + " ");
try
{
var result = interpreter.Evaluate(s);
if (result != null && result.Type != DataType.Void)
script.Options.DebugPrint(string.Format("{0}", result));
}
catch (InterpreterException ex)
{
script.Options.DebugPrint(string.Format("{0}", ex.DecoratedMessage ?? ex.Message));
}
catch (Exception ex)
{
script.Options.DebugPrint(string.Format("{0}", ex.Message));
}
}
}
示例8: sort
public static DynValue sort(ScriptExecutionContext executionContext, CallbackArguments args)
{
var vlist = args.AsType(0, "sort", DataType.Table, false);
var lt = args[1];
if (lt.Type != DataType.Function && lt.Type != DataType.ClrFunction && lt.IsNotNil())
args.AsType(1, "sort", DataType.Function, true); // this throws
var end = GetTableLength(executionContext, vlist);
var values = new List<DynValue>();
for (var i = 1; i <= end; i++)
values.Add(vlist.Table.Get(i));
try
{
values.Sort((a, b) => SortComparer(executionContext, a, b, lt));
}
catch (InvalidOperationException ex)
{
if (ex.InnerException is ScriptRuntimeException)
throw ex.InnerException;
}
for (var i = 0; i < values.Count; i++)
{
vlist.Table.Set(i + 1, values[i]);
}
return vlist;
}
示例9: execute
public static DynValue execute(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue v = args.AsType(0, "execute", DataType.String, true);
if (v.IsNil())
{
return DynValue.NewBoolean(true);
}
else
{
try
{
int exitCode = Script.GlobalOptions.Platform.OS_Execute(v.String);
return DynValue.NewTuple(
DynValue.Nil,
DynValue.NewString("exit"),
DynValue.NewNumber(exitCode));
}
catch (Exception)
{
// +++ bad to swallow..
return DynValue.Nil;
}
}
}
示例10: SetErrorHandlerStrategy
private static DynValue SetErrorHandlerStrategy(string funcName,
ScriptExecutionContext executionContext,
CallbackArguments args,
DynValue handlerBeforeUnwind)
{
var v = args[0];
var a = new DynValue[args.Count - 1];
for (var i = 1; i < args.Count; i++)
a[i - 1] = args[i];
if (args[0].Type == DataType.ClrFunction)
{
try
{
var ret = args[0].Callback.Invoke(executionContext, a);
if (ret.Type == DataType.TailCallRequest)
{
if (ret.TailCallData.Continuation != null || ret.TailCallData.ErrorHandler != null)
throw new ScriptRuntimeException(
"the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.",
funcName);
return DynValue.NewTailCallReq(new TailCallData
{
Args = ret.TailCallData.Args,
Function = ret.TailCallData.Function,
Continuation = new CallbackFunction(pcall_continuation, funcName),
ErrorHandler = new CallbackFunction(pcall_onerror, funcName),
ErrorHandlerBeforeUnwind = handlerBeforeUnwind
});
}
if (ret.Type == DataType.YieldRequest)
{
throw new ScriptRuntimeException(
"the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.",
funcName);
}
return DynValue.NewTupleNested(DynValue.True, ret);
}
catch (ScriptRuntimeException ex)
{
executionContext.PerformMessageDecorationBeforeUnwind(handlerBeforeUnwind, ex);
return DynValue.NewTupleNested(DynValue.False, DynValue.NewString(ex.DecoratedMessage));
}
}
if (args[0].Type != DataType.Function)
{
return DynValue.NewTupleNested(DynValue.False,
DynValue.NewString("attempt to " + funcName + " a non-function"));
}
return DynValue.NewTailCallReq(new TailCallData
{
Args = a,
Function = v,
Continuation = new CallbackFunction(pcall_continuation, funcName),
ErrorHandler = new CallbackFunction(pcall_onerror, funcName),
ErrorHandlerBeforeUnwind = handlerBeforeUnwind
});
}
示例11: exec2n
private static DynValue exec2n(CallbackArguments args, string funcName, double defVal, Func<double, double, double> func)
{
DynValue arg = args.AsType(0, funcName, DataType.Number, false);
DynValue arg2 = args.AsType(1, funcName, DataType.Number, true);
return DynValue.NewNumber(func(arg.Number, arg2.IsNil() ? defVal : arg2.Number));
}
示例12: pairs
public static DynValue pairs(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue table = args[0];
DynValue meta = executionContext.GetMetamethodTailCall(table, "__pairs", args.GetArray());
return meta ?? DynValue.NewTuple(DynValue.NewCallback(next), table);
}
示例13: ipairs
public static DynValue ipairs(ScriptExecutionContext executionContext, CallbackArguments args)
{
var table = args[0];
var meta = executionContext.GetMetamethodTailCall(table, "__ipairs", args.GetArray());
return meta ?? DynValue.NewTuple(DynValue.NewCallback(__next_i), table, DynValue.NewNumber(0));
}
示例14: BuildArrayIndices
private static int[] BuildArrayIndices(CallbackArguments args, int count)
{
int[] indices = new int[count];
for (int i = 0; i < count; i++)
indices[i] = args.AsInt(i, "userdata_array_indexer");
return indices;
}
示例15: rawset
public static DynValue rawset(ScriptExecutionContext executionContext, CallbackArguments args)
{
var table = args.AsType(0, "rawset", DataType.Table);
var index = args[1];
table.Table.Set(index, args[2]);
return table;
}