move load_nasal to io module
This commit is contained in:
parent
62cc0f457c
commit
56eef9c69f
1 changed files with 0 additions and 34 deletions
|
@ -32,10 +32,6 @@
|
|||
# <verb>ose is by default 1, and suppressed the
|
||||
# node's refcounter if 0.
|
||||
#
|
||||
# debug.load_nasal(<file> [, <module>])) ... load and run Nasal file (under namespace
|
||||
# <module> if defined, or the basename
|
||||
# otherwise)
|
||||
#
|
||||
# debug.benchmark(<label:string>, <func> [<args>])
|
||||
# ... calls function with optional args and
|
||||
# prints execution time in seconds,
|
||||
|
@ -343,36 +339,6 @@ if (getprop("/sim/logging/priority") != "alert") {
|
|||
|
||||
|
||||
|
||||
##
|
||||
# Loads Nasal file into namespace and executes it. The namespace
|
||||
# (module name) is taken from the optional second argument, or
|
||||
# derived from the Nasal file's name.
|
||||
#
|
||||
# Usage: debug.load_nasal(<filename> [, <modulename>]);
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# debug.load_nasal(getprop("/sim/fg-root") ~ "/Local/test.nas");
|
||||
# debug.load_nasal("/tmp/foo.nas", "test");
|
||||
#
|
||||
var load_nasal = func(file, module = nil) {
|
||||
if (module == nil)
|
||||
module = split(".", split("/", file)[-1])[0];
|
||||
|
||||
if (!contains(globals, module))
|
||||
globals[module] = {};
|
||||
|
||||
var err = [];
|
||||
printlog("info", "loading ", file, " into namespace ", module);
|
||||
var code = call(func { compile(io.readfile(file), file) }, nil, err);
|
||||
if (size(err))
|
||||
return print(file ~ ": " ~ err[0]);
|
||||
|
||||
call(bind(code, globals), nil, nil, globals[module], err);
|
||||
printerror(err);
|
||||
}
|
||||
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
isalnum = globals["string"].isalnum;
|
||||
isalpha = globals["string"].isalpha;
|
||||
|
|
Loading…
Add table
Reference in a new issue