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


C# DynValue类代码示例

本文整理汇总了C#中DynValue的典型用法代码示例。如果您正苦于以下问题:C# DynValue类的具体用法?C# DynValue怎么用?C# DynValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DynValue类属于命名空间,在下文中一共展示了DynValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LiteralExpression

		public LiteralExpression(ScriptLoadingContext lcontext, Token t)
			: base(lcontext)
		{
			switch (t.Type)
			{
				case TokenType.Number:
				case TokenType.Number_Hex:
				case TokenType.Number_HexFloat:
					m_Value = DynValue.NewNumber(t.GetNumberValue()).AsReadOnly();
					break;
				case TokenType.String:
				case TokenType.String_Long:
					m_Value = DynValue.NewString(t.Text).AsReadOnly();
					break;
				case TokenType.True:
					m_Value = DynValue.True;
					break;
				case TokenType.False:
					m_Value = DynValue.False;
					break;
				case TokenType.Nil:
					m_Value = DynValue.Nil;
					break;
				default:
					throw new InternalErrorException("type mismatch");
			}

			if (m_Value == null)
				throw new SyntaxErrorException(t, "unknown literal format near '{0}'", t.Text);

			lcontext.Lexer.Next();
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:32,代码来源:LiteralExpression.cs

示例2: PurifyFromNewLines

		private string PurifyFromNewLines(DynValue Value)
		{
			if (Value == null)
				return "";

			return Value.ToString().Replace('\n', ' ').Replace('\r', ' ');
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:7,代码来源:Instruction.cs

示例3: SetIndex

		public bool SetIndex(Script script, DynValue index, DynValue value, bool isDirectIndexing)
		{
			if (index.Type != DataType.String)
				throw new ScriptRuntimeException("string property was expected");

			lock (m_Lock)
			{
				switch (value.Type)
				{
					case DataType.Void:
					case DataType.Nil:
						m_Values.Remove(index.String);
						return true;
					case DataType.UserData:
						// HERE YOU CAN CHOOSE A DIFFERENT POLICY.. AND TRY TO SHARE IF NEEDED. DANGEROUS, THOUGH.
						throw new ScriptRuntimeException("Cannot share a value of type {0}", value.Type.ToErrorTypeString());
					case DataType.ClrFunction:
						// HERE YOU CAN CHOOSE A DIFFERENT POLICY.. AND TRY TO SHARE IF NEEDED. DANGEROUS, THOUGH.
						throw new ScriptRuntimeException("Cannot share a value of type {0}", value.Type.ToErrorTypeString());
					case DataType.Boolean:
					case DataType.Number:
					case DataType.String:
						m_Values[index.String] = value.Clone();
						return true;
					case DataType.Function:
					case DataType.Table:
					case DataType.Tuple:
					case DataType.Thread:
					case DataType.TailCallRequest:
					case DataType.YieldRequest:
					default:
						throw new ScriptRuntimeException("Cannot share a value of type {0}", value.Type.ToErrorTypeString());
				}
			}
		}
开发者ID:RainsSoft,项目名称:moonsharp,代码行数:35,代码来源:Program.cs

示例4: FromLuaRange

		public static StringRange FromLuaRange(DynValue start, DynValue end, int? defaultEnd = null)
		{
			int i = start.IsNil() ? 1 : (int)start.Number;
			int j = end.IsNil() ? (defaultEnd ?? i) : (int)end.Number;

			return new StringRange(i, j);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:7,代码来源:StringRange.cs

示例5: DynAssertValue

		private static void DynAssertValue(object reference, DynValue dynValue)
		{
			if (reference == (object)DataType.Void)
			{
				Assert.AreEqual(DataType.Void, dynValue.Type);
			}
			else if (reference == null)
			{
				Assert.AreEqual(DataType.Nil, dynValue.Type);
			}
			else if (reference is double)
			{
				Assert.AreEqual(DataType.Number, dynValue.Type);
				Assert.AreEqual((double)reference, dynValue.Number);
			}
			else if (reference is int)
			{
				Assert.AreEqual(DataType.Number, dynValue.Type);
				Assert.AreEqual((int)reference, dynValue.Number);
			}
			else if (reference is string)
			{
				Assert.AreEqual(DataType.String, dynValue.Type);
				Assert.AreEqual((string)reference, dynValue.String);
			}
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:26,代码来源:Utils.cs

示例6: Call

		public DynValue Call(DynValue function, DynValue[] args)
		{
			List<Processor> coroutinesStack = m_Parent != null ? m_Parent.m_CoroutinesStack : this.m_CoroutinesStack;

			if (coroutinesStack.Count > 0 && coroutinesStack[coroutinesStack.Count - 1] != this)
				return coroutinesStack[coroutinesStack.Count - 1].Call(function, args);

			EnterProcessor();

			try
			{
				var stopwatch = this.m_Script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Execution);

				m_CanYield = false;

				try
				{
					int entrypoint = PushClrToScriptStackFrame(CallStackItemFlags.CallEntryPoint, function, args);
					return Processing_Loop(entrypoint);
				}
				finally
				{
					m_CanYield = true;

					if (stopwatch != null)
						stopwatch.Dispose();
				}
			}
			finally
			{
				LeaveProcessor();
			}
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:33,代码来源:Processor.cs

示例7: GetGlobalSymbol

        private DynValue GetGlobalSymbol(DynValue dynValue, string name)
        {
            if (dynValue.Type != DataType.Table)
                throw new InvalidOperationException(string.Format("_ENV is not a table but a {0}", dynValue.Type));

            return dynValue.Table.Get(name);
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:7,代码来源:Processor_Scope.cs

示例8: SetGlobalSymbol

        private void SetGlobalSymbol(DynValue dynValue, string name, DynValue value)
        {
            if (dynValue.Type != DataType.Table)
                throw new InvalidOperationException(string.Format("_ENV is not a table but a {0}", dynValue.Type));

            dynValue.Table.Set(name, value ?? DynValue.Nil);
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:7,代码来源:Processor_Scope.cs

示例9: PushClrToScriptStackFrame

		// pushes all what's required to perform a clr-to-script function call. function can be null if it's already
		// at vstack top.
		private int PushClrToScriptStackFrame(CallStackItemFlags flags, DynValue function, DynValue[] args)
		{
			if (function == null) 
				function = m_ValueStack.Peek();
			else
				m_ValueStack.Push(function);  // func val

			args = Internal_AdjustTuple(args);

			for (int i = 0; i < args.Length; i++)
				m_ValueStack.Push(args[i]);

			m_ValueStack.Push(DynValue.NewNumber(args.Length));  // func args count

			m_ExecutionStack.Push(new CallStackItem()
			{
				BasePointer = m_ValueStack.Count,
				Debug_EntryPoint = function.Function.EntryPointByteCodeLocation,
				ReturnAddress = -1,
				ClosureScope = function.Function.ClosureContext,
				CallingSourceRef = SourceRef.GetClrLocation(),
				Flags = flags
			});

			return function.Function.EntryPointByteCodeLocation;
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:28,代码来源:Processor.cs

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

示例11: Internal_InvokeUnaryMetaMethod

        private int Internal_InvokeUnaryMetaMethod(DynValue op1, string eventName, int instructionPtr)
        {
            DynValue m = null;

            if (op1.Type == DataType.UserData)
            {
                m = op1.UserData.Descriptor.MetaIndex(m_Script, op1.UserData.Object, eventName);
            }

            if (m == null)
            {
                var op1_MetaTable = GetMetatable(op1);

                if (op1_MetaTable != null)
                {
                    var meta1 = op1_MetaTable.RawGet(eventName);
                    if (meta1 != null && meta1.IsNotNil())
                        m = meta1;
                }
            }

            if (m != null)
            {
                m_ValueStack.Push(m);
                m_ValueStack.Push(op1);
                return Internal_ExecCall(1, instructionPtr);
            }
            return -1;
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:29,代码来源:Processor_UtilityFunctions.cs

示例12: CreateEntry

 public cZipArchiveEntry CreateEntry(string name, DynValue compression)
 {
     if (compression.IsNotNil())
         return new cZipArchiveEntry(zip.CreateEntry(name, compression.ToObject<CompressionLevel>()));
     else
         return new cZipArchiveEntry(zip.CreateEntry(name));
 }
开发者ID:DevanFerreira,项目名称:myBot,代码行数:7,代码来源:cZipArchive.cs

示例13: ConcatOnNonString

 /// <summary>
 ///     Creates a ScriptRuntimeException with a predefined error message specifying that
 ///     a concat operation was attempted on non-strings
 /// </summary>
 /// <param name="l">The left operand.</param>
 /// <param name="r">The right operand.</param>
 /// <returns>The exception to be raised.</returns>
 /// <exception cref="InternalErrorException">If both are numbers or strings</exception>
 public static ScriptRuntimeException ConcatOnNonString(DynValue l, DynValue r)
 {
     if (l.Type != DataType.Number && l.Type != DataType.String)
         return new ScriptRuntimeException("attempt to concatenate a {0} value", l.Type.ToLuaTypeString());
     if (r != null && r.Type != DataType.Number && r.Type != DataType.String)
         return new ScriptRuntimeException("attempt to concatenate a {0} value", r.Type.ToLuaTypeString());
     throw new InternalErrorException("ConcatOnNonString - both are numbers/strings");
 }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:16,代码来源:ScriptRuntimeException.cs

示例14: SetIndex

		/// <summary>
		/// Performs an "index" "set" operation.
		/// </summary>
		/// <param name="script">The script originating the request</param>
		/// <param name="obj">The object (null if a static request is done)</param>
		/// <param name="index">The index.</param>
		/// <param name="value">The value to be set</param>
		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
		/// <returns></returns>
		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isDirectIndexing)
		{
			IUserDataType u = obj as IUserDataType;

			if (u != null)
				return u.SetIndex(script, index, value, isDirectIndexing);

			return false;
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:18,代码来源:AutoDescribingUserDataDescriptor.cs

示例15: SetIndex

		/// <summary>
		/// Performs an "index" "set" operation.
		/// </summary>
		/// <param name="script">The script originating the request</param>
		/// <param name="obj">The object (null if a static request is done)</param>
		/// <param name="index">The index.</param>
		/// <param name="value">The value to be set</param>
		/// <param name="isDirectIndexing">If set to true, it's indexed with a name, if false it's indexed through brackets.</param>
		/// <returns></returns>
		public bool SetIndex(Script script, object obj, DynValue index, DynValue value, bool isNameIndex)
		{
			foreach (IUserDataDescriptor dd in m_Descriptors)
			{
				if (dd.SetIndex(script, obj, index, value, isNameIndex))
					return true;
			}
			return false;
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:18,代码来源:CompositeUserDataDescriptor.cs


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