Beispiel #1
0
		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();
			}
		}
Beispiel #2
0
		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);
		}
Beispiel #3
0
		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)
				");			
		}
Beispiel #4
0
		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);
		}