当前位置: 首页>>代码示例>>C#>>正文


C# CallbackArguments.AsType方法代码示例

本文整理汇总了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());
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:28,代码来源:StringModule.cs

示例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;
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:32,代码来源:TableModule.cs

示例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));
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:7,代码来源:MathModule.cs

示例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;
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:7,代码来源:DebugModule.cs

示例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));
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:9,代码来源:StringModule.cs

示例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);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:10,代码来源:OsTimeModule.cs

示例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;
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:12,代码来源:Bit32Module.cs

示例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;
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:17,代码来源:TableIteratorsModule.cs

示例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;
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:15,代码来源:MetaTableModule.cs

示例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);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:7,代码来源:MetaTableModule.cs

示例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);
			}
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:28,代码来源:DynamicModule.cs

示例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;
				}
			}
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:26,代码来源:OsSystemModule.cs

示例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]);
		}
开发者ID:RainsSoft,项目名称:moonsharp,代码行数:7,代码来源:CoroutineModule.cs

示例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);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:16,代码来源:Bit32Module.cs

示例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;
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:9,代码来源:MetaTableModule.cs


注:本文中的CallbackArguments.AsType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。