當前位置: 首頁>>代碼示例>>C#>>正文


C# Script.LoadString方法代碼示例

本文整理匯總了C#中System.Script.LoadString方法的典型用法代碼示例。如果您正苦於以下問題:C# Script.LoadString方法的具體用法?C# Script.LoadString怎麽用?C# Script.LoadString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Script的用法示例。


在下文中一共展示了Script.LoadString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Script_RunString

		private DynValue Script_RunString(string script)
		{
			Script s1 = new Script();
			DynValue v1 = s1.LoadString(script);

			using (MemoryStream ms = new MemoryStream())
			{
				s1.Dump(v1, ms);
				ms.Seek(0, SeekOrigin.Begin);

				Script s2 = new Script();
				DynValue func = s2.LoadStream(ms);
				return func.Function.Call();
			}
		}
開發者ID:cyecp,項目名稱:moonsharp,代碼行數:15,代碼來源:BinaryDumpTests.cs

示例2: PrintTest2

		public void PrintTest2()
		{
			string script = @"
				t = {};
				m = {};

				function m.__tostring()
					return 'ciao';
				end

				setmetatable(t, m);

				print(t, 1);
			";
			string printed = null;

			Script S = new Script();
			DynValue main = S.LoadString(script);

			S.Options.DebugPrint = s =>
			{
				printed = s;
			};

			S.Call(main);

			Assert.AreEqual("ciao\t1", printed);
		}
開發者ID:cyecp,項目名稱:moonsharp,代碼行數:28,代碼來源:StringLibTests.cs

示例3: ParsingTest

		public void ParsingTest()
		{
			Script S = new Script(CoreModules.None);
			DynValue res = S.LoadString(@"
				t = {'a', 'b', 'c', ['d'] = 'f', ['e'] = 5, [65] = true, [true] = false}
				function myFunc()
				  return 'one', 'two'
				end

				print('Table Test 1:')
				for k,v in pairs(t) do
				  print(tostring(k) .. ' / ' .. tostring(v))
				end
				print('Table Test 2:')
				for X,X in pairs(t) do
				  print(tostring(X) .. ' / ' .. tostring(X))
				end
				print('Function Test 1:')
				v1,v2 = myFunc()
				print(v1)
				print(v2)
				print('Function Test 2:')
				v,v = myFunc()
				print(v)
				print(v)
				");			
		}
開發者ID:InfectedBytes,項目名稱:moonsharp,代碼行數:27,代碼來源:SimpleTests.cs

示例4: PrintTest1

		public void PrintTest1()
		{
			string script = @"
				print('ciao', 1);
			";
			string printed = null;

			Script S = new Script();
			DynValue main = S.LoadString(script);

			S.Options.DebugPrint = s =>
			{
				printed = s;
			};

			S.Call(main);

			Assert.AreEqual("ciao\t1", printed);
		}
開發者ID:cyecp,項目名稱:moonsharp,代碼行數:19,代碼來源:StringLibTests.cs


注:本文中的System.Script.LoadString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。