Board index FlightGear Development Nasal

Triggering XML bindings from Nasal

Nasal is the scripting language of FlightGear.

Triggering XML bindings from Nasal

Postby ludomotico » Mon May 11, 2020 8:55 am

Is there any way to trigger bindings defined in a XML from Nasal?

I'd like to trigger this XML action from Nasal: https://github.com/c172p-team/c172p/blo ... .xml#L1326 (this action, and the other 16 actions defined below it)

I'm not sure whether I follow the logic of the action defined as a set of bindings. Running the same logic in Nasal or Javascript (my real goal, using Phi) is a lot of work prune to bugs, and in any case it will involve replicating logic that does the same thing in different languages. In fact, the action is already duplicated in the XML declaring the animation of the object and the XML of a dialog.

One possible solution to prevent duplication is triggering the action using some Nasal function. Is it possible?
User avatar
ludomotico
 
Posts: 1096
Joined: Tue Apr 24, 2012 1:01 pm
Version: git
OS: Debian GNU/Linux

Re: Triggering XML bindings from Nasal

Postby Hooray » Mon May 11, 2020 10:06 am

Yes, all you need is a handle to the xml file, then you can use standard property APIs to process all relevant tags in a loop and compile all bindings to invoke the corresponding fgcommand

I have previously posted such code here, when Torsten mentioned that he ran into issues supporting pui dialogs via Phi due to nasal, i ended up using the same method to dynamically translate a subset of pui/xml to canvas (pui2canvas), you can still find the corresponding code on the wiki, and it can probably reused as is, or at least easily adapted.

If you're going to write your own code, be sure to use call() for exception handling purposes, so that you can put all bindings into a vector and then run all bindings via a loop, without broken bindings breaking other ones (again, see the pui2canvas article for a demo)
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: 11771
Joined: Tue Mar 25, 2008 8:40 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest