Board index FlightGear Development Nasal

Spoken GCA

Nasal is the scripting language of FlightGear.

Re: Spoken GCA

Postby Hooray » Sat Mar 10, 2018 1:59 pm

I am aware of that, the point was wrapping $FG_HOME/Export/Addons/ADDON-ID
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11162
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Sat Mar 10, 2018 5:12 pm

Ah, right, I misunderstood what you meant. Well, in order to be useful, one would need either:
  1. to have Nasal function(s) to create a directory if it doesn't already exist;
  2. or to make addon.storagePath automatically create the dir when non-existent (but it would be a side effect and would slow down the thing a little bit).
Is there something like in (a) already available (looking at io.nas, I don't see anything resembling)?

P.S.: we are polluting the Spoken GCA thread with this discussion...
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Sat Mar 10, 2018 5:30 pm

IIRC, Tom exposed most of the SGPath APIs via cppbind (at the time,i.e. things may have become out of sync meanwhile): https://sourceforge.net/p/flightgear/fl ... SGPath.cxx

Specifically, see: https://sourceforge.net/p/flightgear/fl ... h.cxx#l144

This is all made available via the os.path namespace: https://sourceforge.net/p/flightgear/fl ... h.cxx#l148

Wiki documentation (created by Red Leader) is at: http://wiki.flightgear.org/Nasal_library/os.path
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11162
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Sat Mar 10, 2018 9:20 pm

Thanks for the pointers. It's not very user-friendly, but works...

The following code checks if /home/me/.fgfs/Export/foobarXXX and /tmp/foobarXXX are existing dirs, and if not creates them if possible. It rightfully refuses to create the second one as per FG security policy.
Code: Select all
foreach (var d; ["/home/me/.fgfs/Export", "/tmp"]) {
  var dirToCreate = os.path.new(d);
  dirToCreate.append("foobarXXX");
  var dummy = os.path.new(dirToCreate.str);
  dummy.append("dummy");

  if (!dirToCreate.isDir()) {
    if (!dirToCreate.exists()) {
      dummy.create_dir();
    } else {
      print(dirToCreate.str ~ " exists but is not a directory!");
    }
  }
}

I'll add addon.storagePath, or some similarly-named data member.
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Sun Mar 11, 2018 8:20 am

I believe we can do something along the lines of getprop("/sim/fg-home"); to get the OS/user-specific $FG_HOME location
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11162
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Sun Mar 11, 2018 10:49 am

With commit 9a044a474bd now in 'next', it's easier than that for add-on developers:

  1. Create the add-on-specific storage dir if it doesn't already exist, and return its path (UTF-8 string):
    Code: Select all
    storageDir = addon.createStorageDir();

    Typically, you'll do this in the add-on main() function (at least, early enough) if your add-on uses the storage dir.
  2. At any time, you can get a path to the add-on-specific storage dir (UTF-8 string) with:
    Code: Select all
    storageDir = addon.storagePath

    (this doesn't check for existence nor type of $FG_HOME/Export/Addons/ADDON_ID, so has no overhead as compared to createStorageDir(), which could otherwise do the job).
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby Hooray » Sun Mar 11, 2018 10:51 am

I guess we could use something getOrCreateStorageDir() here to make it more obvious what this is doing and simplify the API at the same time ?
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11162
Joined: Tue Mar 25, 2008 8:40 am

Re: Spoken GCA

Postby rominet » Sun Mar 11, 2018 2:39 pm

addon.storagePath is consistent in naming scheme with addon.basePath. addon.createStorageDir() has a little overhead as compared to addon.storagePath, because it has to stat() the path. Merging them would inflict the overhead penalty on every call, therefore I prefer this API: you call addon.createStorageDir() once if you need it (for instance at add-on startup), and all other times you use addon.storagePath.
rominet
 
Posts: 550
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Re: Spoken GCA

Postby rleibner » Mon Mar 12, 2018 10:38 pm

Hooray wrote in Wed Mar 07, 2018 9:05 pm:my impression here is that you may be running into other places (subsystems) that don't have any addon support ...
It would be best to identify such bugs and report them here so that we can take a look - I believe that rominet has already fixed a few of those (e.g. bindings and UI dialogs).
,,,

I'd love to take the task. But please be more specific and suggest a place that is worth.
And may be is a good idea to open a new topic/thread keeping this one to SpokenGCA/PAR stuff. :wink:
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 222
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: 2180.3.0
OS: Ubuntu 17.10

Re: Spoken GCA

Postby Hooray » Tue Mar 13, 2018 5:56 pm

I don't have any specific idea here - the posting was just to say that you've been using the addon framework for things that were never designed with addons in mind, so that it is possible that you are running into code that may not yet being executed from addons
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11162
Joined: Tue Mar 25, 2008 8:40 am

Previous

Return to Nasal

Who is online

Users browsing this forum: No registered users and 0 guests