• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# System.Script类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: LoadChunk

		internal static int LoadChunk(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
		{
			ScriptLoadingContext lcontext = CreateLoadingContext(script, source);
			try
			{
				Statement stat;

				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
					stat = new ChunkStatement(lcontext, globalContext);

				int beginIp = -1;

				//var srcref = new SourceRef(source.SourceID);

				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
				using (bytecode.EnterSource(null))
				{
					bytecode.Emit_Nop(string.Format("Begin chunk {0}", source.Name));
					beginIp = bytecode.GetJumpPointForLastInstruction();
					stat.Compile(bytecode);
					bytecode.Emit_Nop(string.Format("End chunk {0}", source.Name));
				}

				//Debug_DumpByteCode(bytecode, source.SourceID);

				return beginIp;
			}
			catch (SyntaxErrorException ex)
			{
				ex.DecorateMessage(script);
				throw;
			}
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:33,代码来源:Loader_Fast.cs


示例2: GetSigOpCount

		public void GetSigOpCount()
		{
			// Test CScript::GetSigOpCount()
			Script s1 = new Script();
			Assert.Equal(s1.GetSigOpCount(false), 0U);
			Assert.Equal(s1.GetSigOpCount(true), 0U);

			uint160 dummy = new uint160(0);
			s1 = s1 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + OpcodeType.OP_2 + OpcodeType.OP_CHECKMULTISIG;
			Assert.Equal(s1.GetSigOpCount(true), 2U);
			s1 = s1 + OpcodeType.OP_IF + OpcodeType.OP_CHECKSIG + OpcodeType.OP_ENDIF;
			Assert.Equal(s1.GetSigOpCount(true), 3U);
			Assert.Equal(s1.GetSigOpCount(false), 21U);

			Script p2sh = PayToScriptHashTemplate.Instance.GenerateScriptPubKey(s1);
			Script scriptSig = PayToScriptHashTemplate.Instance.GenerateScriptSig(new[] { (Op)OpcodeType.OP_0 }, s1);
			Assert.Equal(p2sh.GetSigOpCount(scriptSig), 3U);

			PubKey[] keys = Enumerable.Range(0, 3).Select(_ => new Key(true).PubKey).ToArray();

			Script s2 = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(1, keys);
			Assert.Equal(s2.GetSigOpCount(true), 3U);
			Assert.Equal(s2.GetSigOpCount(false), 20U);

			p2sh = PayToScriptHashTemplate.Instance.GenerateScriptPubKey(s2);
			Assert.Equal(p2sh.GetSigOpCount(true), 0U);
			Assert.Equal(p2sh.GetSigOpCount(false), 0U);
			Script scriptSig2 = new Script();
			scriptSig2 = scriptSig2 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + s2.ToBytes();
			Assert.Equal(p2sh.GetSigOpCount(scriptSig2), 3U);
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:31,代码来源:sigopcount_tests.cs


示例3: ReadScript

		private bool ReadScript(Script script)
		{
			try
			{
				var data = TxNullDataTemplate.Instance.ExtractScriptPubKeyParameters(script);
				if(data == null)
					return false;
				BitcoinStream stream = new BitcoinStream(data);
				ushort marker = 0;
				stream.ReadWrite(ref marker);
				if(marker != Tag)
					return false;
				stream.ReadWrite(ref _Version);
				if(_Version != 1)
					return false;

				ulong quantityCount = 0;
				stream.ReadWriteAsVarInt(ref quantityCount);
				Quantities = new ulong[quantityCount];

				for(ulong i = 0 ; i < quantityCount ; i++)
				{
					Quantities[i] = ReadLEB128(stream);
					if(Quantities[i] > MAX_QUANTITY)
						return false;
				}

				stream.ReadWriteAsVarString(ref _Metadata);
				return true;
			}
			catch(Exception)
			{
				return false;
			}
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:35,代码来源:ColorMarker.cs


示例4: Set

 public override void Set(Script script, Scope scope, object obj, object value)
 {
     if (_isMethod)
     {
         throw new Exception("The left-hand side of an assignment must be a variable, property or indexer.");
     }
     else
     {
         Type t = obj.GetType();
         PropertyInfo result = t.GetProperty(_name);
         if (result != null)
         {
             if (!result.CanWrite)
             {
                 throw new FieldAccessException("Cannot modify the value of " + _name + ", it is read-only.");
             }
             result.GetSetMethod().Invoke(obj, new[] {value});
         }
         else
         {
             FieldInfo[] fi = t.GetFields();
             for (int i = 0; i < fi.Length; i++)
             {
                 if (fi[i].Name == _name)
                 {
                     fi[i].SetValue(obj, value);
                     return;
                 }
             }
         }
     }
 }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:32,代码来源:TypeFunctionToken.cs


示例5: Execute

        public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
        {
            if (unknown == null)
            {
                throw new NullReferenceException("obj cannot be null...");
            }

            if (unknown is object[])
            {
                // We are assuming that the tokens count is 1, and that it gives us a number.
                if (_tokens.Count == 1)
                {
                    // Evaluate.
                    object id = new Chunk(_tokens[0], script).Evaluate(scope);
                    if (id != null && id is Number)
                    {
                        return ((object[]) unknown)[((Number) id).GetValue<int>()];
                    }
                    else
                    {
                        throw new Exception("For a array of type object[], the key must be a number!");
                    }
                }
                throw new Exception(":O");
            }
            else
            {
                Type type = (unknown is Type) ? (Type) unknown : unknown.GetType();
                return Invoke(script, scope, unknown, type, (type == typeof(String)) ? "Chars" : "Item",
                              _tokens, new List<string>());
            }
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:32,代码来源:ArrayAccessToken.cs


示例6: Execute

        public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
        {
            if (unknown == null && previousToken != null)
            {
                // Cannot execute.
                throw new NullReferenceException("obj cannot be null...");
            }
            else if (unknown == null && previousToken == null)
            {
                // Check our list of "functions".
                if (scope.Functions.Contains(_name))
                {
                    return scope.Functions.Invoke(script, scope, _name, _arguments);
                }
                else if (script.Engine != null && script.Engine.Functions.Contains(_name))
                {
                    return script.Engine.Functions.Invoke(script, scope, _name, _arguments);
                }
                else
                {
                    throw new Exception(String.Format("No function named {0}...", _name));
                }
            }

            Type type = (unknown is Type) ? (Type) unknown : unknown.GetType();

            return _isMethod
                       ? Invoke(script, scope, unknown, type, _name, _arguments, _generics)
                       : FieldInvoke(unknown, _name, type);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:30,代码来源:TypeFunctionToken.cs


示例7: Do

		void Do(string code, Action<DynValue, RegCollMethods> asserts)
		{
			try
			{
				UserData.RegisterType<RegCollMethods>();
				UserData.RegisterType<RegCollItem>();
				UserData.RegisterType(typeof(IList<>));

				Script s = new Script();

				var obj = new RegCollMethods();
				s.Globals["o"] = obj;
				s.Globals["ctor"] = UserData.CreateStatic<RegCollItem>();

				DynValue res = s.DoString(code);

				asserts(res, obj);
			}
			catch (ScriptRuntimeException ex)
			{
				Debug.WriteLine(ex.DecoratedMessage);
				throw;
			}
			finally
			{
				UserData.UnregisterType<RegCollMethods>();
				UserData.UnregisterType<RegCollItem>();
				UserData.UnregisterType<Array>();
				UserData.UnregisterType(typeof(IList<>));
				UserData.UnregisterType(typeof(IList<RegCollItem>));
				UserData.UnregisterType(typeof(IList<int>));
				//UserData.UnregisterType<IEnumerable>();
			}
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:34,代码来源:CollectionsBaseInterfGenRegisteredTests.cs


示例8: TailCallFromCLR

		public void TailCallFromCLR()
		{
			string script = @"
				function getResult(x)
					return 156*x;  
				end

				return clrtail(9)";


			Script S = new Script();

			S.Globals.Set("clrtail", DynValue.NewCallback((xc, a) =>
			{
				DynValue fn = S.Globals.Get("getResult");
				DynValue k3 = DynValue.NewNumber(a[0].Number / 3);

				return DynValue.NewTailCallReq(fn, k3);
			}));

			var res = S.DoString(script);

			Assert.AreEqual(DataType.Number, res.Type);
			Assert.AreEqual(468, res.Number);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:25,代码来源:TailCallTests.cs


示例9: LoadFunction

		internal static int LoadFunction(Script script, SourceCode source, ByteCode bytecode, Table globalContext)
		{
			ScriptLoadingContext lcontext = CreateLoadingContext(script, source);

			try
			{
				FunctionDefinitionExpression fnx;

				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.AstCreation))
					fnx = new FunctionDefinitionExpression(lcontext, globalContext);

				int beginIp = -1;

				//var srcref = new SourceRef(source.SourceID);

				using (script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Compilation))
				using (bytecode.EnterSource(null))
				{
					bytecode.Emit_Nop(string.Format("Begin function {0}", source.Name));
					beginIp = fnx.CompileBody(bytecode, source.Name);
					bytecode.Emit_Nop(string.Format("End function {0}", source.Name));
				}

				//Debug_DumpByteCode(bytecode, source.SourceID);

				return beginIp;
			}
			catch (SyntaxErrorException ex)
			{
				ex.DecorateMessage(script);
				throw;
			}

		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:34,代码来源:Loader_Fast.cs


示例10: CombineScriptSig

		public override Script CombineScriptSig(Script scriptPubKey, Script a, Script b)
		{
			var para = PayToMultiSigTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey);
			// Combine all the signatures we've got:
			var aSigs = PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(a);
			if(aSigs == null)
				return b;
			var bSigs = PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(b);
			if(bSigs == null)
				return a;
			int pubkeyCount = 0;
			TransactionSignature[] sigs = new TransactionSignature[para.PubKeys.Length];
			for(int i = 0 ; i < para.PubKeys.Length ; i++)
			{
				var aSig = i < aSigs.Length ? aSigs[i] : null;
				var bSig = i < bSigs.Length ? bSigs[i] : null;
				var sig = aSig ?? bSig;
				if(sig != null)
				{
					sigs[pubkeyCount] = sig; 
					pubkeyCount++;
				}
				if(pubkeyCount == para.SignatureCount)
					break;
			}
			if(pubkeyCount == para.SignatureCount)
				sigs = sigs.Where(s => s != null && s != TransactionSignature.Empty).ToArray();
			return PayToMultiSigTemplate.Instance.GenerateScriptSig(sigs);
		}		
开发者ID:knocte,项目名称:NBitcoin,代码行数:29,代码来源:P2MultiSigBuilderExtension.cs


示例11: Load

 public static void Load(Script script)
 {
     ScriptTable Table = script.CreateTable();
     Table.SetValue("encode", script.CreateFunction(new encode()));
     Table.SetValue("decode", script.CreateFunction(new decode(script)));
     script.SetObjectInternal("json", Table);
 }
开发者ID:Githubxplabs,项目名称:Scorpio-CSharp,代码行数:7,代码来源:LibraryJson.cs


示例12: LoadScript

        //////////////////////////////////////////////////////////////////////////
        public void LoadScript(DebugClient Client, Script Script)
        {
            _Client = Client;
            _Script = Script;

            this.BeginUpdate();
            this.Items.Clear();

            SourceValid = false;

            if (_Client != null && _Script != null)
            {
                string FullPath = _Client.Server.ResolveFilename(_Script.Filename);
                ReadLines(FullPath);
                SelectLine(Script.Line, true);
            }

            foreach (ColumnHeader Col in this.Columns)
            {
                Col.Width = -1;
            }
            this.EndUpdate();

            RefreshBreakpoints();
        }
开发者ID:segafan,项目名称:wme1_jankavan_tlc_edition-repo,代码行数:26,代码来源:ScriptViewer.cs


示例13: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            while ((++sourceCode).SpecialChar)
            {
            }
            if (sourceCode.Peek() != '{')
            {
                sourceCode.Throw(String.Format("Error parsing a 'do' statement, expected a '{' but got '{0}' instead.",
                                               sourceCode.Peek()));
            }
            List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});

            if (!sourceCode.SeekToNext("while"))
            {
                sourceCode.Throw("Error parsing a 'do' statement, was expecting a 'while' after the { } block.");
            }

            if (!sourceCode.SeekToNext('('))
            {
                sourceCode.Throw("Error parsing a 'do' statement, was expecting a '(' after 'while'.");
            }

            List<List<Token>> exitCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});

            return new DoWhileToken(code, exitCondition);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:26,代码来源:DoWhileBlockBuilder.cs


示例14: TableAddWithMetatable

		public void TableAddWithMetatable()
		{
			string script = @"    
				v1 = { 'aaaa' }
				v2 = { 'aaaaaa' } 

				meta = { }

				function meta.__add(t1, t2)
					local o1 = #t1[1];
					local o2 = #t2[1];
	
					return o1 * o2;
				end


				setmetatable(v1, meta);


				return(v1 + v2);";

			var S = new Script();
			Table globalCtx = S.Globals;

			globalCtx.RegisterModuleType<TableIteratorsModule>();
			globalCtx.RegisterModuleType<MetaTableModule>();

			DynValue res = S.DoString(script);

			Assert.AreEqual(DataType.Number, res.Type);
			Assert.AreEqual(24, res.Number);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:32,代码来源:MetatableTests.cs


示例15: Build

        public override Token Build(Token lastToken, ScriptEngine engine, Script script, ref SourceCode sourceCode)
        {
            // while (condition) { /* Code */ }
            sourceCode += 4; // The +1 comes from below.

            while ((++sourceCode).SpecialChar)
            {
            }

            if (sourceCode.CurrentCode != '(')
            {
                sourceCode.Throw("Error parsing a 'while' statement, was epexting a '(' after 'while'.");
            }

            List<List<Token>> exitCondition = engine.BuildTokensAdvanced(ref sourceCode, ref script, new[] {')'});

            if (!sourceCode.SeekToNext('{'))
            {
                sourceCode.Throw(String.Format("Unexpected char: '{0}'", sourceCode.CurrentCode));
            }

            List<List<List<Token>>> code = engine.BuildLongTokens(ref sourceCode, ref script, new[] {'}'});

            return new WhileLoopToken(exitCondition, code);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:25,代码来源:WhileBlockBuilder.cs


示例16: DocumentTabForm

        public DocumentTabForm(Script script)
        {
            if (script == null) throw new ArgumentNullException("script");

            Script = script;
            InitializeComponent();

            DockHandler = new DockContentHandler(this);
            DockHandler.DockAreas = DockAreas.Document;
            DockHandler.AllowEndUserDocking = false;

            Controls.Add(textEditor);

            textEditor.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            textEditor.Name = "textEditor";
            textEditor.BorderStyle = BorderStyle.Fixed3D;
            textEditor.ShowMatchingBracket = true;
            textEditor.SetHighlighting("lua");
            textEditor.ShowSpaces = true;
            textEditor.ShowTabs = true;
            textEditor.Dock = DockStyle.Fill;
            textEditor.Text = Script.Text;

            script.NameChanged += ScriptNameChanged;
            FormClosed += (sender, args) => {
                script.NameChanged -= ScriptNameChanged;
            };
            Text = Script.ShortName;
        }
开发者ID:hgabor,项目名称:kfirpgcreator,代码行数:29,代码来源:DocumentTabForm.cs


示例17: GetStandardFile

		private static DynValue GetStandardFile(Script S, StandardFileType file)
		{
			Table R = S.Registry;

			DynValue ff = R.Get("853BEAAF298648839E2C99D005E1DF94_STD_" + file.ToString());
			return ff;
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:7,代码来源:IoModule.cs


示例18: Compile

        /// <summary>
        /// Compiles a Script object to allow it to be Executed
        /// </summary>
        /// <param name="script">Script object to be compiled</param>
        public void Compile(Script script)
        {
            if (!compilerInfo.ContainsKey(script.Language))
                throw new Exception("Unknown or unsupported language");

            string providerName = compilerInfo[script.Language].CodeDomProviderType.FullName;
            CodeDomProvider provider;

            if (!compilers.ContainsKey(providerName))
            {
                provider = compilerInfo[script.Language].CreateProvider();
                compilers.Add(providerName, provider);
            }
            else
            {
                provider = compilers[providerName];
            }

            CompilerParameters parameters = new CompilerParameters(script.referencedAssemblies.ToArray())
            {
                GenerateExecutable = false,
                GenerateInMemory = true,
                OutputAssembly = rng.Next().ToString() + ".dll"
            };

            script.results = provider.CompileAssemblyFromSource(parameters, script.Source);

            script.Compiled = !script.results.Errors.HasErrors;

            if (script.Compiled)
            {
                script.assembly = script.results.CompiledAssembly;
            }
        }
开发者ID:Bart97,项目名称:BeemuSharp,代码行数:38,代码来源:ScriptHost.cs


示例19: Interop_Event_TwoObjects

		public void Interop_Event_TwoObjects()
		{
			int invocationCount = 0;
			UserData.RegisterType<SomeClass>();
			UserData.RegisterType<EventArgs>();

			Script s = new Script(CoreModules.None);

			var obj = new SomeClass();
			var obj2 = new SomeClass();
			s.Globals["myobj"] = obj;
			s.Globals["myobj2"] = obj2;
			s.Globals["ext"] = DynValue.NewCallback((c, a) => { invocationCount += 1; return DynValue.Void; });

			s.DoString(@"
				function handler(o, a)
					ext();
				end

				myobj.MyEvent.add(handler);
				");

			obj.Trigger_MyEvent();
			obj2.Trigger_MyEvent();

			Assert.AreEqual(1, invocationCount);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:27,代码来源:UserDataEventsTests.cs


示例20: Test_ConstIntFieldSetter

		public void Test_ConstIntFieldSetter(InteropAccessMode opt)
		{
			try
			{
				string script = @"    
				myobj.ConstIntProp = 1;
				return myobj.ConstIntProp;";

				Script S = new Script();

				SomeClass obj = new SomeClass() { IntProp = 321 };

				UserData.UnregisterType<SomeClass>();
				UserData.RegisterType<SomeClass>(opt);

				S.Globals.Set("myobj", UserData.Create(obj));

				DynValue res = S.DoString(script);

				Assert.AreEqual(DataType.Number, res.Type);
				Assert.AreEqual(115, res.Number);
			}
			catch (ScriptRuntimeException)
			{
				return;
			}

			Assert.Fail();
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:29,代码来源:UserDataFieldsTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# System.Signature类代码示例发布时间:2022-05-26
下一篇:
C# System.SByte类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap