1
0
Fork 0

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:
mfranz 2008-08-14 22:13:25 +00:00
parent c23971dcca
commit 917cace77c
4 changed files with 26 additions and 24 deletions

View file

@ -411,8 +411,10 @@ var data = {
setlistener("/sim/signals/exit", func { me._save_() }); setlistener("/sim/signals/exit", func { me._save_() });
}, },
load : func { load : func {
printlog("warn", "trying to load aircraft data from ", me.path, " (OK if not found)"); if (io.stat(me.path) != nil) {
io.read_properties(me.path, props.globals); printlog("info", "loading aircraft data from ", me.path);
io.read_properties(me.path, props.globals);
}
}, },
save : func(v = nil) { save : func(v = nil) {
me.loopid += 1; me.loopid += 1;

View file

@ -222,7 +222,7 @@ var string = func(o) {
var k = keys(o); var k = keys(o);
var s = ""; var s = "";
forindex (var i; k) 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("}"); return _brace("{") ~ " " ~ s ~ " " ~ _brace("}");
} elsif (t == "ghost") { } 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: # time in seconds. Examples:
# #
# var test = func { getprop("/sim/aircraft"); } # var test = func { getprop("/sim/aircraft"); }
# debug.benchmark("test()/2", test, 1000); # debug.benchmark("test()/2", test, 1000);
# debug.benchmark("test()/2", func setprop("/sim/aircraft", ""), 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(); var start = systime();
for (var i = 0; i < repeat; i += 1) for (var i = 0; i < repeat; i += 1)
fun(); fn();
print(_bench(sprintf(" %s --> %.6f s ", label, systime() - start))); 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 that catches "exceptions" (by a die() call or errors). The Nasal
# code doesn't abort in this case. Example: # 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); # debug.printerror(err);
# #
var printerror = func(err) { var printerror = func(err) {

View file

@ -171,17 +171,17 @@ var copy = func(src, dest, attr = 0) {
# Utility. Turns any ghosts it finds (either solo, or in an # Utility. Turns any ghosts it finds (either solo, or in an
# array) into Node objects. # array) into Node objects.
# #
var wrap = func { var wrap = func(node) {
argtype = typeof(arg[0]); var argtype = typeof(node);
if(argtype == "ghost") { if(argtype == "ghost") {
return wrapNode(arg[0]); return wrapNode(node);
} elsif(argtype == "vector") { } elsif(argtype == "vector") {
v = arg[0]; var v = node;
n = size(v); var n = size(v);
for(i=0; i<n; i+=1) { v[i] = wrapNode(v[i]); } for(i=0; i<n; i+=1) { v[i] = wrapNode(v[i]); }
return v; 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. # Node object and its _g (ghost) field set to the specified object.
# Nasal's literal syntax can be pleasingly terse. I like that. :) # 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? # 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] # path under each node of that name to set (e.g. "throttle"), arg[2]
# is the value. # is the value.
# #
var setAll = func { var setAll = func(base, child, value) {
node = props.globals.getNode(arg[0]); var node = props.globals.getNode(base);
if(node == nil) { return; } if(node == nil) return;
name = node.getName(); var name = node.getName();
node = node.getParent(); node = node.getParent();
if(node == nil) { return; } if(node == nil) return;
children = node.getChildren(); var children = node.getChildren();
foreach(c; children) { foreach(c; children)
if(c.getName() == name) { if(c.getName() == name)
c.getNode(arg[1], 1).setValue(arg[2]); }} c.getNode(child, 1).setValue(value);
} }
## ##

View file

@ -145,7 +145,6 @@ match = func(str, patt) {
continue; continue;
} elsif (patt[p] == `[`) { } elsif (patt[p] == `[`) {
print("**setsize**");
setsize(var x = [], 256); setsize(var x = [], 256);
var invert = 0; var invert = 0;
if ((p += 1) < size(patt) and patt[p] == `^`) { if ((p += 1) < size(patt) and patt[p] == `^`) {