Example #1
0
		private void testScript_Click(object sender, EventArgs e) {
			scriptValidatedValue.Visible = false;
			if (scriptTypeValue.Text == "Lua") {
				Lua lua = new Lua();
				lua.RegisterMarkedMethodsOf(this);
				//add some variables so we can pass tests
				lua["item"] = Items.ItemFactory.CreateItem(ObjectId.Parse("5383dc8531b6bd11c4095993"));

				if (byPassTestValue.Visible) {
					ScriptError = !byPassTestValue.Checked;
				}
				else {
					try {
						lua.DoString(scriptValue.Text);
						ScriptError = false;
						scriptValidatedValue.Visible = true;
					}
					catch (LuaException lex) {
						MessageBox.Show(lex.Message, "Lua Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
						ScriptError = true;
					}
				}
			}
			else {
				if (byPassTestValue.Visible) {
					ScriptError = !byPassTestValue.Checked;
				}
				ScriptEngine engine = new ScriptEngine();
				ScriptMethods host = new ScriptMethods();
				host.DataSet.Add("player", Character.NPCUtils.CreateNPC(1));
				host.DataSet.Add("npc", Character.NPCUtils.CreateNPC(1));
				Roslyn.Scripting.Session session = engine.CreateSession(host, host.GetType());
				new[]
					   {
						 typeof (Type).Assembly,
						 typeof (ICollection).Assembly,
						 typeof (Console).Assembly,
						 typeof (RoslynScript).Assembly,
						 typeof (IEnumerable<>).Assembly,
						 typeof (IQueryable).Assembly,
						 typeof (ScriptMethods).Assembly,
						 typeof(IActor).Assembly,
						 typeof(Character.Character).Assembly,
						 typeof(NPC).Assembly,
						 typeof(Room).Assembly,
						 typeof(Commands.CommandParser).Assembly,
						 typeof(Interfaces.Message).Assembly,
						 GetType().Assembly
					}.ToList().ForEach(asm => session.AddReference(asm));

				//Import common namespaces
				new[]
						{
						 "System", "System.Linq", "System.Object", "System.Collections", "System.Collections.Generic",
						 "System.Text", "System.Threading.Tasks", "System.IO",
						 "Character", "Rooms", "Items", "Commands", "ClientHandling", "Triggers"
					 }.ToList().ForEach(ns => session.ImportNamespace(ns));
				try {
					var result = session.CompileSubmission<object>(scriptValue.Text);
					ScriptError = false;
					scriptValidatedValue.Visible = true;
				}
				catch (Exception ex) {
					MessageBox.Show("Errors found in script:\n " + ex.Message, "Script Errors", MessageBoxButtons.OK);
				}
			}
		}
Example #2
0
        private void testScript_Click(object sender, EventArgs e) {
            Lua lua = new Lua();
            lua.RegisterMarkedMethodsOf(this);
            //add some variables so we can pass tests
            lua["item"] = Items.ItemFactory.CreateItem(ObjectId.Parse("5383dc8531b6bd11c4095993"));

            if (byPassTestValue.Visible) {
                ScriptError = !byPassTestValue.Checked;
            }
            else {
                try {
                    lua.DoString(scriptValue.Text);
                    ScriptError = false;
                    scriptValidatedValue.Visible = true;
                }
                catch (LuaException lex) {
                    MessageBox.Show(lex.Message, "Lua Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ScriptError = true;
                    scriptValidatedValue.Visible = false;
                }
            }
        }