Added Script.fromString
This commit is contained in:
@@ -148,6 +148,22 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
return new DummyScript(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a script from the specified asset path. The language is automatically determined.
|
||||
* @param path Path in assets
|
||||
*/
|
||||
public static function fromString(code:String, ext:String, path:String):Script {
|
||||
return switch(ext.toLowerCase()) {
|
||||
case "hx" | "hscript" | "hsc" | "hxs":
|
||||
new HScript(path).loadFromString(code);
|
||||
case "lua":
|
||||
Logs.trace("Lua is not supported in this engine. Use HScript instead.", ERROR);
|
||||
new DummyScript(path).loadFromString(code);
|
||||
default:
|
||||
new DummyScript(path).loadFromString(code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the script class.
|
||||
* @param path
|
||||
@@ -224,6 +240,14 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the code from a string, doesnt really work after the script has been loaded
|
||||
* @param code The code.
|
||||
*/
|
||||
public function loadFromString(code:String) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a script's parent object so that its properties can be accessed easily. Ex: Passing `PlayState.instance` will allow `boyfriend` to be typed instead of `PlayState.instance.boyfriend`.
|
||||
* @param variable Parent variable.
|
||||
|
||||
Reference in New Issue
Block a user