public override void Initialize() { TShockAPI.Commands.ChatCommands.Add(new TShockAPI.Command("aliascmd", ChatCommand_GeneralCommand, "aliascmd") { AllowServer = true }); JScript.JScriptEngine.Initialize(); Configuration = Configuration.LoadConfigurationFromFile("tshock" + System.IO.Path.DirectorySeparatorChar + "SEconomy" + System.IO.Path.DirectorySeparatorChar + "AliasCmd.config.json"); foreach (string path in System.IO.Directory.EnumerateFiles("tshock" + System.IO.Path.DirectorySeparatorChar + "SEconomy", "*.js")) { TShockAPI.Log.ConsoleInfo(string.Format("aliascmd js: loading file {0}.", path)); scriptEngine.Run(System.IO.File.ReadAllText(path)); } ParseCommands(); }
void StartJsMods(ModManager m) { jintEngine.SetParameter("m", m); // TODO: javascript mod requirements foreach (var k in javascriptScripts) { try { jintEngine.Run(k.Value); Console.WriteLine("Loaded mod: {0}", k.Key); } catch { Console.WriteLine("Error in mod: {0}", k.Key); } } }
public string Execute(string Script, List<int> breakpoints = null) { System.Text.StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(Script)) { Jint.JintEngine engine = new Jint.JintEngine(); engine.AllowClr = true; engine.SetDebugMode(true); engine.DisableSecurity(); if (breakpoints != null) { foreach (var line in breakpoints) { engine.BreakPoints.Add(new Jint.Debugger.BreakPoint(line + 1, 1)); } engine.Break += engine_Break; } try { var result = engine.Run(Script, true); if (result != null) sb.Append(result.ToString()); } catch (Exception exc) { sb.Append("An error has occured, details:\r\n"); sb.Append(exc.Message); } sb.Append("\r\nDone"); } else { sb.Append("No script found to execute."); } return sb.ToString(); }
public void StaticMemberAfterUndefinedReference() { var engine = new Jint.JintEngine().AllowClr(); Assert.AreEqual(System.String.Format("{0}", 1), engine.Run("System.String.Format('{0}', 1)")); Assert.AreEqual("undefined", engine.Run("typeof thisIsNotDefined")); Assert.AreEqual(System.String.Format("{0}", 1), engine.Run("System.String.Format('{0}', 1)")); }
public void ShouldFindOverloadWithNullParam() { var box = new Box { Width = 10, Height = 20 }; var jint = new Jint.JintEngine() .SetDebugMode(true) .SetFunction("assert", new Action<object, object>(Assert.AreEqual)) .SetParameter("box", box); jint.Run(@" assert(1, Number(box.Foo(1))); assert(2, Number(box.Foo(2, null))); "); }
private void parseScriptFile(string filename) { //Clear neighboring room and mapfile strings eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; //Empty NPE list NPEs = new List<NPE>(); var engine = new Jint.JintEngine(); engine.DisableSecurity(); engine.SetDebugMode(true); engine.SetFunction("name",new Action<string>(setMapName)); engine.SetFunction("east", new Action<string>(setEastMapfile)); engine.SetFunction("west", new Action<string>(setWestMapfile)); engine.SetFunction("north", new Action<string>(setNorthMapfile)); engine.SetFunction("south", new Action<string>(setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(newNPE)); engine.SetFunction("addNPE", new Action<NPE>(addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(getFlag)); engine.SetFunction("setFlag", new Action<string>(setFlag)); engine.SetFunction("dialogue", new Action<string>(dialogue)); engine.SetFunction("battleTexture", new Action<string>(setBattleTexture)); engine.SetFunction("newEnemy", new NewEnemyDelegate(js_newEnemy)); engine.SetFunction("addRandomEncounter", new Action<object>(addRandomEncounter)); engine.SetFunction("battle", new Action<object, object>(battle)); engine.SetFunction("reloadMap", new Action(reloadMap)); engine.SetFunction("store", new Action<object, object>(store)); engine.SetFunction("newItem", new NewItemDelegate(js_newItem)); engine.SetFunction("save", new Action<object>(save)); engine.Run(File.ReadAllText(mapDirectory + filename)); }
private void parseScriptFile(string filename) { //Clear map script information mapName = "<name not set>"; eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; scriptFilename = filename; //Empty NPE list NPEs = new List<NPE>(); var engine = new Jint.JintEngine(); engine.DisableSecurity(); //Needed so the scripts can call methods on NPE objects. engine.SetDebugMode(true); engine.SetFunction("name", new Action<string>(setMapName)); engine.SetFunction("east", new Action<string>(setEastMapfile)); engine.SetFunction("west", new Action<string>(setWestMapfile)); engine.SetFunction("north", new Action<string>(setNorthMapfile)); engine.SetFunction("south", new Action<string>(setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(newNPE)); engine.SetFunction("addNPE", new Action<NPE>(addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(getFlag)); engine.SetFunction("setFlag", new Action<string>(setFlag)); engine.SetFunction("dialogue", new Action<string>(dialogue)); engine.SetFunction("save", new Action<Player>(save)); engine.Run(File.ReadAllText(MAP_DIRECTORY + filename)); }
/// <summary>Initializes the graph source</summary> /// <param name="scriptfile">Filename of a JavaScript file</param> public ScriptableWebGraphSource(string scriptfile) { string source = File.ReadAllText(scriptfile); _Script = new Jint.JintEngine(); _Script.Run(source); }
private void parseScriptFile(string filename) { //Clear map script information mapName = "<name not set>"; eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; scriptFilename = filename; //Empty NPE and random encounter lists NPEs = new List<NPE>(); randomEncounters = new List<Enemy>(); //Clear battle and music attributes battleTexture = null; overworldMusic = null; randomBattleMusic = null; var engine = new Jint.JintEngine(); engine.DisableSecurity(); //Needed so the scripts can call methods on NPE objects. engine.SetDebugMode(true); engine.SetFunction("name", new Action<string>(js_setMapName)); engine.SetFunction("battleTexture", new Action<string>(js_setBattleTexture)); engine.SetFunction("east", new Action<string>(js_setEastMapfile)); engine.SetFunction("west", new Action<string>(js_setWestMapfile)); engine.SetFunction("north", new Action<string>(js_setNorthMapfile)); engine.SetFunction("south", new Action<string>(js_setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(js_setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(js_newNPE)); engine.SetFunction("addNPE", new Action<NPE>(js_addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(js_getFlag)); engine.SetFunction("setFlag", new Action<string>(js_setFlag)); engine.SetFunction("dialogue", new Action<string>(js_dialogue)); engine.SetFunction("reloadMap", new Action(ReloadMap)); engine.SetFunction("save", new Action<Player>(js_save)); engine.SetFunction("newItem", new NewItemDelegate(js_newItem)); engine.SetFunction("addRandomEncounter", new Action<Enemy>(js_addRandomEncounter)); engine.SetFunction("newEnemy", new NewEnemyDelegate(js_newEnemy)); engine.SetFunction("battle", new Action<Player, Enemy, string>(js_battle)); engine.SetFunction("store", new Action<Player, ArrayList>(js_store)); engine.SetFunction("overworldMusic", new Action<string>(js_overworldMusic)); engine.SetFunction("randomBattleMusic", new Action<string>(js_randomBattleMusic)); engine.SetFunction("win", new Action(js_win)); engine.Run(File.ReadAllText(MAP_DIRECTORY + filename)); }
/// <summary> /// This function is called by the preprocesor after the code has been compiled from the preprocessing template /// </summary> /// <param name="scriptCode">The string with the javascript code</param> /// <returns>True if sucess, false if failed </returns> public string Run(string scriptCode) { return((bool)scriptEngine.Run(scriptCode) ? "true" : "false"); }