PixInsight Forum (historical)
PixInsight => General => Topic started by: David Serrano on 2007 September 26 14:33:45
-
I think this is a real bug, but it can perfectly be a misunderstanding on my side:
#include <pjsr/DataType.jsh>
var tmp;
Settings.write ("FOO/bar", DataType_UInt8, 42);
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
console.writeln ("read 1 ok, tmp (",tmp,")");
Settings.remove ("FOO");
// this read should fail...
tmp = Settings.read ("FOO/bar", DataType_UInt8);
// ...thus, this conditional should be false
if (Settings.lastReadOK)
console.writeln ("read 2 ok, tmp (",tmp,")");
Settings.remove ("FOO/bar"); // another try...
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
console.writeln ("read 3 ok, tmp (",tmp,")");
Settings.remove ("FOO/*"); // and just another one
tmp = Settings.read ("FOO/bar", DataType_UInt8);
if (Settings.lastReadOK)
console.writeln ("read 4 ok, tmp (",tmp,")");
Processing script file: /home/hue/foo.js
read 1 ok, tmp (42)
read 2 ok, tmp (null)
read 3 ok, tmp (null)
read 4 ok, tmp (null)
-
No bug here: Settings.lastReadOK is a method, not a property:
Boolean Settings.lastReadOK()
Thus, the result of a conditional construct such as:
if ( Settings.lastReadOK )
is always true, since indeed the Settings object has a lastReadOK item defined.
The correct code is:
if ( Settings.lastReadOK() )
Having said that, I realize that I made a design mistake because lastReadOK should be a read-only static property instead of a static method of Settings. This is the problem when one switches between C++ and JavaScript too quickly :lol:
I think this problem should be corrected now that we don't have a lot of scripts out there using lastReadOK(), so how about turning this method into a property in the next release?
-
so how about turning this method into a property in the next release?
Fine, no objections here.
I'm moving this thread to another, more appropriate place.