Author Topic: Is there a way for a PJSR script to know its own location?  (Read 5140 times)

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Is there a way for a PJSR script to know its own location?
« 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

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: Is there a way for a PJSR script to know its own location?
« Reply #1 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.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: Is there a way for a PJSR script to know its own location?
« Reply #2 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

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: Is there a way for a PJSR script to know its own location?
« Reply #3 on: 2012 September 02 07:48:37 »

Well that's a bummer. Knowing Juan he probably implemented something like that then.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Is there a way for a PJSR script to know its own location?
« Reply #4 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.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: Is there a way for a PJSR script to know its own location?
« Reply #5 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  ;)