AsyncEmbeddedScript allow libpath

This commit is contained in:
2021-10-25 20:28:24 -04:00
parent a41afc2036
commit 4ab78fb3f4
4 changed files with 14 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import sys.io.File;
import haxe.io.Path; import haxe.io.Path;
#end #end
import kiss.Kiss; import kiss.Kiss;
import kiss.Prelude;
import kiss.cloner.Cloner; import kiss.cloner.Cloner;
typedef Continuation = () -> Void; typedef Continuation = () -> Void;
@@ -40,7 +41,7 @@ class AsyncEmbeddedScript {
public function new() {} public function new() {}
#if macro #if macro
public static function build(dslFile:String, scriptFile:String):Array<Field> { public static function build(dslHaxelib:String, dslFile:String, scriptFile:String):Array<Field> {
var k = Kiss.defaultKissState(); var k = Kiss.defaultKissState();
var classPath = Context.getPosInfos(Context.currentPos()).file; var classPath = Context.getPosInfos(Context.currentPos()).file;
@@ -50,11 +51,15 @@ class AsyncEmbeddedScript {
var commandList:Array<Expr> = []; var commandList:Array<Expr> = [];
if (dslHaxelib.length > 0) {
dslFile = Path.join([Prelude.libPath(dslHaxelib), dslFile]);
}
// This brings in the DSL's functions and global variables. // This brings in the DSL's functions and global variables.
// As a side-effect, it also fills the KissState with the macros and reader macros that make the DSL syntax // As a side-effect, it also fills the KissState with the macros and reader macros that make the DSL syntax
classFields = classFields.concat(Kiss.build(dslFile, k)); classFields = classFields.concat(Kiss.build(dslFile, k));
scriptFile = Path.join([loadingDirectory, scriptFile]);
scriptFile = Path.join([loadingDirectory, scriptFile]);
Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> {
var expr = Kiss.readerExpToHaxeExpr(nextExp, k); var expr = Kiss.readerExpToHaxeExpr(nextExp, k);

View File

@@ -199,7 +199,12 @@ class Kiss {
if (loadingDirectory == null) if (loadingDirectory == null)
loadingDirectory = k.loadingDirectory; loadingDirectory = k.loadingDirectory;
var fullPath = Path.join([loadingDirectory, kissFile]); var fullPath = if (Path.isAbsolute(kissFile)) {
kissFile;
} else {
Path.join([loadingDirectory, kissFile]);
};
if (k.loadedFiles.exists(fullPath)) { if (k.loadedFiles.exists(fullPath)) {
return k.loadedFiles[fullPath]; return k.loadedFiles[fullPath];
} }

View File

@@ -24,7 +24,7 @@
(updateContent state.text))) (updateContent state.text)))
(var &mut :Map<Int,Int> editTimeoutHandles (new Map)) (var &mut :Map<Int,Int> editTimeoutHandles (new Map))
(var EDIT_TIMEOUT_MILLI 1000) (var EDIT_TIMEOUT_MILLI 2000)
(function :Void addEditTimeout [idx :Void->Void handler] (function :Void addEditTimeout [idx :Void->Void handler]
(whenLet [activeTimeoutForIndex (dictGet editTimeoutHandles idx)] (whenLet [activeTimeoutForIndex (dictGet editTimeoutHandles idx)]
(window.clearTimeout activeTimeoutForIndex)) (window.clearTimeout activeTimeoutForIndex))