Adds assert() for Nasal and fixes io.include internal marking
- A simple assert() function is added to the globals namespace. - io.include() marks the target namespace to avoid dependency loops. If the namespace is marked before the script to be included is compiled, a parse error leaves the target namespace marked while the script has not been loaded. This patch fixes this problem.
This commit is contained in:
parent
501f8ba881
commit
8b16a71d50
2 changed files with 10 additions and 4 deletions
|
@ -27,6 +27,15 @@ var L2GAL = 1 / GAL2L;
|
|||
# container for local variables, so as not to clutter the global namespace
|
||||
var __ = {};
|
||||
|
||||
##
|
||||
# Aborts execution if <condition> evaluates to false.
|
||||
# Prints an optional message if present, or just "assertion failed!"
|
||||
#
|
||||
var assert = func (condition, message=nil) {
|
||||
message != nil or (message = "assertion failed!");
|
||||
condition or die(message);
|
||||
}
|
||||
|
||||
##
|
||||
# Returns true if the first object is an instance of the second
|
||||
# (class) object. Example: isa(someObject, props.Node)
|
||||
|
@ -180,4 +189,3 @@ settimer(func {
|
|||
if(size(file) > 4 and substr(file, -4) == ".nas")
|
||||
io.load_nasal(path ~ "/" ~ file, substr(file, 0, size(file) - 4));
|
||||
}, 0);
|
||||
|
||||
|
|
|
@ -47,8 +47,6 @@ var include = func(file) {
|
|||
if (contains(ns, module))
|
||||
return;
|
||||
|
||||
ns[module] = "included";
|
||||
|
||||
var code = call(compile, [readfile(path), path], var err = []);
|
||||
if (size(err)) {
|
||||
if (find("Parse error:", err[0]) < 0)
|
||||
|
@ -57,6 +55,7 @@ var include = func(file) {
|
|||
die(sprintf("%s\n in included file: %s", err[0], path));
|
||||
}
|
||||
|
||||
ns[module] = "included";
|
||||
call(bind(code, ns, fn), [], nil, ns);
|
||||
}
|
||||
|
||||
|
@ -425,4 +424,3 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
|||
}
|
||||
})();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue