PixInsight Forum (historical)

Software Development => PCL and PJSR Development => Topic started by: bitli on 2012 September 02 00:32:13

Title: Is there a way for a PJSR script to know its own location?
Post by: bitli on 2012 September 02 00:32:13
Hi,
Is there a way for a script to know its own location?  I need to load some files that are in a location relative to the script.
thanks
-- bitli
Title: Re: Is there a way for a PJSR script to know its own location?
Post by: Nocturnal on 2012 September 02 06:24:03
I don't know how javascript does it but there is probably a __FILE__ macro like c/c++, python, perl and ruby, or something like that. Google would know. Juan probably re-implemented it but plain javascript most likely implements this.
Title: Re: Is there a way for a PJSR script to know its own location?
Post by: bitli on 2012 September 02 07:42:21
This is the original problem: there is no __FILE__ or equivallent in Javascript standard.
The nearest trickt is (new Error).filename, but PJSR does not implements the filename attribute.
So let's wait on Juan.
-- bitli
Title: Re: Is there a way for a PJSR script to know its own location?
Post by: Nocturnal on 2012 September 02 07:48:37

Well that's a bummer. Knowing Juan he probably implemented something like that then.
Title: Re: Is there a way for a PJSR script to know its own location?
Post by: Juan Conejero on 2012 September 04 02:27:30
Quote
Knowing Juan he probably implemented something like that then.

You know me well :)

The JavaScript runtime in PixInsight includes a preprocessor (similar to the standard C preprocessor), which provides a number of predefined macros. This script shows all of them:

Code: [Select]
/*
 * Predefined Macros in PJSR
 */
console.show();
console.writeln();
console.writeln( "*** Predefined Macros ***" );
console.writeln( #__FILE__ );        // Absolute path of the current script file
console.writeln( #__LINE__ );        // Current line number
console.writeln( #__DATE__ );        // Date of execution start
console.writeln( #__TIME__ );        // Local time of execution start
console.writeln( #__JS_VERSION__ );  // 100 * version of the JavaScript engine (185 in PI 1.7; 187 in PI 1.8)
console.writeln( #__PI_VERSION__ );  // Full PI Core version. Example: 01.08.00.0853
console.writeln( #__PI_MAJOR__ );    // PI Core version: major version number
console.writeln( #__PI_MINOR__ );    // PI Core version: minor version number
console.writeln( #__PI_RELEASE__ );  // PI Core version: release version number
console.writeln( #__PI_BUILD__ );    // PI Core version: build number
#ifdef __PI_BETA__
console.writeln( "Beta ", #__PI_BETA__ ); // PI Core version: beta version number, or undefined
#endif
#ifdef __PI_LE__
console.writeln( "Limited Edition" );     // Defined if this is a LE version
#endif
console.writeln( #__PI_LANG__ );     // PI Core version: language code, ISO 639.2
console.writeln( #__PI_CODENAME__ ); // PI Core version: Codename (1.7: Starbuck, 1.8: Ripley)
console.writeln( #__PI_PLATFORM__ ); // One of: LINUX, FREEBSD, MACOSX, MSWINDOWS
#ifgteq __PI_MINOR__ 8
console.writeln( #__PI_ARCH__ );     // *** New in 1.8: One of: x86, x86_64
#endif

And yes, the PJSR is undocumented. Hopefully this will change soon.
Title: Re: Is there a way for a PJSR script to know its own location?
Post by: bitli on 2012 September 04 02:39:28
Just what I need , thanks Juan
-- bitli
PS. At work I always complain that the user call for support before even reading the doc. A problem you don't have  ;)