This is just a fork to run on my engine and support previous Psych 0.7.3 mods, without errors and in conjunction with Hscript Iris. SScript versión "7.7.0".
Only use it if you absolutely have to. Otherwise, use hscript-iris or hscript.
Original README (click to expand)
SScript is an easy to use Haxe script tool that aims to be simple while supporting all Haxe structures.
If you have an issue with SScript or have a suggestion, you can always open an issue here. However, pull requests are NOT welcome and will be ignored.
haxelib install SScript
Enter this command in command prompt to get the latest release from Haxe library.
haxelib git SScript https://github.com/ThomasDarkson/SScript.git
Enter this command in command prompt to get the latest git release from Github. Git releases have the latest features but they are unstable and can cause problems.
After installing SScript, don't forget to add it to your Haxe project.
Add this to Project.xml to add SScript to your OpenFL project:
<haxelibname="SScript"/>Add this to build.hxml to add SScript to your Haxe build.
-lib SScriptTo use SScript, you will need a file or a script. Using a file is recommended.
varscript:tea.SScript= {}; // Create a new SScript classscript.doScript(" function returnRandom():Float return Math.random() * 100;"); // Implement the scriptvarcall=script.call('returnRandom');
varrandomNumber:Float=call.returnValue; // Access the returned value with returnValuevarscript:tea.SScript=newtea.SScript("script.hx"); // Has the same contents with the script abovevarrandomNumber:Float=script.call('returnRandom').returnValue;SScript supports both ?. and ?? syntaxes including ??=.
importtea.SScript;
classMain {
staticfunctionmain()
{
varscript:SScript= {};
script.doScript(" var string:String = null; trace(string.length); // Throws an error trace(string?.length); // Doesn't throw an error and returns null trace(string ?? 'ss'); // Returns 'ss'; trace(string ??= 'ss'); // Returns 'ss' and assigns it to `string` variable");
}
}You can create a class extending SScript to customize it better.
classSScriptExextendstea.SScript
{ overridefunctionpreset():Void
{
super.preset();
// Only use 'set', 'setClass' or 'setClassString' in preset// Macro classes are not allowed to be setsetClass(StringTools);
set('NaN', Math.NaN);
setClassString('sys.io.File');
}
}Extend other functions only if you know what you're doing.
You can call methods and receive their return value from Tea's using call function.
It needs one obligatory argument (function name) and one optional argument (function arguments array).
using call will return a structure that contains the return value, if calling has been successful, exceptions if it did not, called function name and script file name of the Tea.
Example:
vartea:tea.SScript= {};
tea.doScript(' function method() { return 2 + 2; }');
varcall=tea.call('method');
trace(call.returnValue); // 4tea.doScript(' function method() { var num:Int = 1.1; return num; }')
varcall=tea.call('method');
trace(call.returnValue, call.exceptions[0]); // null, Float should be IntWith SScript, you can set variables to all running Tea's. Example:
vartea:tea.SScript= {};
tea.set('variable', 1);
tea.doScript(' function returnVar() { return variable + variable2; }');
tea.SScript.globalVariables.set('variable2', 2);
trace(tea.call('returnVar').returnValue); // 3Special object is an object that'll get checked if a variable is not found in a Tea. A special object cannot be a basic type like Int, Float, String, Array and Bool.
Special objects are useful for OpenFL and Flixel states.
Example:
importtea.SScript;
classPlayStateextendsflixel.FlxState {
varsprite:flixel.FlxSprite;
overridefunctioncreate()
{
sprite=newflixel.FlxSprite();
varnewScript:SScript=newSScript();
newScript.setSpecialObject(this);
newScript.doScript("sprite.visible = false;");
}
}