diff --git a/Nasal/globals.nas b/Nasal/globals.nas index 4be967a86..273611797 100644 --- a/Nasal/globals.nas +++ b/Nasal/globals.nas @@ -27,6 +27,15 @@ var L2GAL = 1 / GAL2L; # container for local variables, so as not to clutter the global namespace var __ = {}; +## +# Aborts execution if 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); - diff --git a/Nasal/io.nas b/Nasal/io.nas index 179af84aa..b27e2aa36 100644 --- a/Nasal/io.nas +++ b/Nasal/io.nas @@ -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 { } })(); }); -