本文整理汇总了C#中CallbackArguments.AsType方法的典型用法代码示例。如果您正苦于以下问题:C# CallbackArguments.AsType方法的具体用法?C# CallbackArguments.AsType怎么用?C# CallbackArguments.AsType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CallbackArguments
的用法示例。
在下文中一共展示了CallbackArguments.AsType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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));
}
示例4: 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;
}
示例5: PerformByteLike
public static DynValue @byte(ScriptExecutionContext executionContext, CallbackArguments args)
{
var vs = args.AsType(0, "byte", DataType.String, false);
var vi = args.AsType(1, "byte", DataType.Number, true);
var vj = args.AsType(2, "byte", DataType.Number, true);
return PerformByteLike(vs, vi, vj,
i => Unicode2Ascii(i));
}
示例6: difftime
public static DynValue difftime(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue t2 = args.AsType(0, "difftime", DataType.Number, false);
DynValue t1 = args.AsType(1, "difftime", DataType.Number, true);
if (t1.IsNil())
return DynValue.NewNumber(t2.Number);
return DynValue.NewNumber(t2.Number - t1.Number);
}
示例7: Bitwise
public static uint Bitwise(string funcName, CallbackArguments args, Func<uint, uint, uint> accumFunc)
{
uint accum = ToUInt32(args.AsType(0, funcName, DataType.Number, false));
for (int i = 1; i < args.Count; i++)
{
uint vv = ToUInt32(args.AsType(i, funcName, DataType.Number, false));
accum = accumFunc(accum, vv);
}
return accum;
}
示例8: __next_i
// __next_i (table [, index])
// -------------------------------------------------------------------------------------------------------------------
// Allows a program to traverse all fields of an array. index is an integer number
public static DynValue __next_i(ScriptExecutionContext executionContext, CallbackArguments args)
{
var table = args.AsType(0, "!!next_i!!", DataType.Table);
var index = args.AsType(1, "!!next_i!!", DataType.Number);
var idx = ((int) index.Number) + 1;
var val = table.Table.Get(idx);
if (val.Type != DataType.Nil)
{
return DynValue.NewTuple(DynValue.NewNumber(idx), val);
}
return DynValue.Nil;
}
示例9: setmetatable
public static DynValue setmetatable(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue table = args.AsType(0, "setmetatable", DataType.Table);
DynValue metatable = args.AsType(1, "setmetatable", DataType.Table, true);
DynValue curmeta = executionContext.GetMetamethod(table, "__metatable");
if (curmeta != null)
{
throw new ScriptRuntimeException("cannot change a protected metatable");
}
table.Table.MetaTable = metatable.Table;
return table;
}
示例10: 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);
}
示例11: 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);
}
}
示例12: 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;
}
}
}
示例13: 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]);
}
示例14: extract
public static DynValue extract(ScriptExecutionContext executionContext, CallbackArguments args)
{
DynValue v_v = args.AsType(0, "extract", DataType.Number);
uint v = ToUInt32(v_v);
DynValue v_pos = args.AsType(1, "extract", DataType.Number);
DynValue v_width = args.AsType(2, "extract", DataType.Number, true);
int pos = (int)v_pos.Number;
int width = (v_width).IsNilOrNan() ? 1 : (int)v_width.Number;
ValidatePosWidth("extract", 2, pos, width);
uint res = (v >> pos) & NBitMask(width);
return DynValue.NewNumber(res);
}
示例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;
}