load and execute all ~/.fgfs/Nasal/*.nas files in alphabetic order after
the $FG_ROOT/Nasal/*.nas ones are done. This allows to use props.Node etc. immediately, without requirement for settimer(func{}, 0) constructions. Rationale: - clean separation of local additions (and hacks :-) from standard files - users might not have write permission to $FG_ROOT/Nasal/ or shouldn't have to su to root for writing Nasal code
This commit is contained in:
parent
bff5a62666
commit
bf050c012f
1 changed files with 29 additions and 0 deletions
|
@ -110,3 +110,32 @@ printlog = func(level, args...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Load and execute ~/.fgfs/Nasal/*.nas files in alphabetic order
|
||||||
|
# after all $FG_ROOT/Nasal/*.nas files were loaded.
|
||||||
|
#
|
||||||
|
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
|
var path = getprop("/sim/fg-home") ~ "/Nasal";
|
||||||
|
if ((var dir = directory(path)) == nil) return;
|
||||||
|
foreach (var file; sort(dir, cmp)) {
|
||||||
|
if (substr(file, -4) != ".nas") continue;
|
||||||
|
|
||||||
|
var module = substr(file, 0, size(file) - 4);
|
||||||
|
file = path ~ "/" ~ file;
|
||||||
|
printlog("info", ">>> executing local Nasal file ", file);
|
||||||
|
|
||||||
|
if (!contains(globals, module)) var locals = globals[module] = {};
|
||||||
|
elsif (typeof(globals[module]) == "hash") var locals = globals[module];
|
||||||
|
else var locals = {};
|
||||||
|
|
||||||
|
var err = [];
|
||||||
|
var code = call(func { compile(io.readfile(file), file) }, nil, err);
|
||||||
|
if (size(err)) {
|
||||||
|
print(file ~ ": " ~ err[0]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
call(bind(code, globals), nil, nil, locals, err);
|
||||||
|
debug.printerror(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue