string.nas: remove forgotten debug message
props.nas: replace some "arg[*]" by named args aircraft.nas: load aircraft data only if the file exists (to avoid warning) debug.nas: no space before colon & fixed comment & cosmetics
This commit is contained in:
parent
c23971dcca
commit
917cace77c
4 changed files with 26 additions and 24 deletions
|
@ -411,8 +411,10 @@ var data = {
|
|||
setlistener("/sim/signals/exit", func { me._save_() });
|
||||
},
|
||||
load : func {
|
||||
printlog("warn", "trying to load aircraft data from ", me.path, " (OK if not found)");
|
||||
io.read_properties(me.path, props.globals);
|
||||
if (io.stat(me.path) != nil) {
|
||||
printlog("info", "loading aircraft data from ", me.path);
|
||||
io.read_properties(me.path, props.globals);
|
||||
}
|
||||
},
|
||||
save : func(v = nil) {
|
||||
me.loopid += 1;
|
||||
|
|
|
@ -222,7 +222,7 @@ var string = func(o) {
|
|||
var k = keys(o);
|
||||
var s = "";
|
||||
forindex (var i; k)
|
||||
s ~= (i == 0 ? "" : ", ") ~ _dump_key(k[i]) ~ " : " ~ debug.string(o[k[i]]);
|
||||
s ~= (i == 0 ? "" : ", ") ~ _dump_key(k[i]) ~ ": " ~ debug.string(o[k[i]]);
|
||||
return _brace("{") ~ " " ~ s ~ " " ~ _brace("}");
|
||||
|
||||
} elsif (t == "ghost") {
|
||||
|
@ -292,17 +292,17 @@ var proptrace = func(root = "/", frames = 1) {
|
|||
|
||||
|
||||
##
|
||||
# Executes function fun with repeat times prints execution
|
||||
# Executes function fn with repeat times prints execution
|
||||
# time in seconds. Examples:
|
||||
#
|
||||
# var test = func { getprop("/sim/aircraft"); }
|
||||
# debug.benchmark("test()/2", test, 1000);
|
||||
# debug.benchmark("test()/2", func setprop("/sim/aircraft", ""), 1000);
|
||||
#
|
||||
var benchmark = func(label, fun, repeat = 1) {
|
||||
var benchmark = func(label, fn, repeat = 1) {
|
||||
var start = systime();
|
||||
for (var i = 0; i < repeat; i += 1)
|
||||
fun();
|
||||
fn();
|
||||
print(_bench(sprintf(" %s --> %.6f s ", label, systime() - start)));
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,8 @@ var exit = func fgcommand("exit");
|
|||
# code that catches "exceptions" (by a die() call or errors). The Nasal
|
||||
# code doesn't abort in this case. Example:
|
||||
#
|
||||
# call(func { possibly_buggy() }, nil, var err = []);
|
||||
# var possibly_buggy = func { ... }
|
||||
# call(possibly_buggy, nil, var err = []);
|
||||
# debug.printerror(err);
|
||||
#
|
||||
var printerror = func(err) {
|
||||
|
|
|
@ -171,17 +171,17 @@ var copy = func(src, dest, attr = 0) {
|
|||
# Utility. Turns any ghosts it finds (either solo, or in an
|
||||
# array) into Node objects.
|
||||
#
|
||||
var wrap = func {
|
||||
argtype = typeof(arg[0]);
|
||||
var wrap = func(node) {
|
||||
var argtype = typeof(node);
|
||||
if(argtype == "ghost") {
|
||||
return wrapNode(arg[0]);
|
||||
return wrapNode(node);
|
||||
} elsif(argtype == "vector") {
|
||||
v = arg[0];
|
||||
n = size(v);
|
||||
var v = node;
|
||||
var n = size(v);
|
||||
for(i=0; i<n; i+=1) { v[i] = wrapNode(v[i]); }
|
||||
return v;
|
||||
}
|
||||
return arg[0];
|
||||
return node;
|
||||
}
|
||||
|
||||
##
|
||||
|
@ -189,7 +189,7 @@ var wrap = func {
|
|||
# Node object and its _g (ghost) field set to the specified object.
|
||||
# Nasal's literal syntax can be pleasingly terse. I like that. :)
|
||||
#
|
||||
var wrapNode = func { { parents : [Node], _g : arg[0] } }
|
||||
var wrapNode = func(node) { { parents : [Node], _g : node } }
|
||||
|
||||
##
|
||||
# Global property tree. Set once at initialization. Is that OK?
|
||||
|
@ -204,16 +204,16 @@ var globals = wrapNode(_globals());
|
|||
# path under each node of that name to set (e.g. "throttle"), arg[2]
|
||||
# is the value.
|
||||
#
|
||||
var setAll = func {
|
||||
node = props.globals.getNode(arg[0]);
|
||||
if(node == nil) { return; }
|
||||
name = node.getName();
|
||||
var setAll = func(base, child, value) {
|
||||
var node = props.globals.getNode(base);
|
||||
if(node == nil) return;
|
||||
var name = node.getName();
|
||||
node = node.getParent();
|
||||
if(node == nil) { return; }
|
||||
children = node.getChildren();
|
||||
foreach(c; children) {
|
||||
if(c.getName() == name) {
|
||||
c.getNode(arg[1], 1).setValue(arg[2]); }}
|
||||
if(node == nil) return;
|
||||
var children = node.getChildren();
|
||||
foreach(c; children)
|
||||
if(c.getName() == name)
|
||||
c.getNode(child, 1).setValue(value);
|
||||
}
|
||||
|
||||
##
|
||||
|
|
|
@ -145,7 +145,6 @@ match = func(str, patt) {
|
|||
continue;
|
||||
|
||||
} elsif (patt[p] == `[`) {
|
||||
print("**setsize**");
|
||||
setsize(var x = [], 256);
|
||||
var invert = 0;
|
||||
if ((p += 1) < size(patt) and patt[p] == `^`) {
|
||||
|
|
Loading…
Reference in a new issue