From b35bf51fa0e6e4ebec7328e853e3d5817eeba1af Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Tue, 17 Sep 2019 21:06:39 +0100 Subject: [PATCH] src/Scripting/NasalSys.cxx: Optionally prefix all Nasal output with Nasal file:line. Depends on /sim/nasal-log-file-line. E.g. enable with: --prop:/sim/nasal-log-file-line=1. --- src/Scripting/NasalSys.cxx | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 578e2a2a6..536fee391 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -503,11 +503,28 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args) return naNum(result); } + +struct SimNasalLogFileLine : SGPropertyChangeListener +{ + SimNasalLogFileLine() { + SGPropertyNode* node = fgGetNode("/sim/nasal-log-file-line", true /*create*/); + node->addChangeListener(this, true /*initial*/); + } + virtual void valueChanged(SGPropertyNode* node) { + _file_line = node->getIntValue(); + } + + static bool _file_line; +}; + +bool SimNasalLogFileLine::_file_line = false; + // print() extension function. Concatenates and prints its arguments // to the FlightGear log. Uses the highest log level (SG_ALERT), to // make sure it appears. Is there better way to do this? static naRef f_print(naContext c, naRef me, int argc, naRef* args) { + static SimNasalLogFileLine snlfl; string buf; int n = argc; for(int i=0; i