Board index FlightGear Support Hardware

joystick-xml-file: meaning of __js0</module>

Joysticks, pedals, monitors.

joystick-xml-file: meaning of __js0</module>

Postby deltamike » Wed Mar 07, 2018 9:29 pm

Hello,
in my file -> joystick-configuration created xml-file (Thrustmaster-T16000M.xml) I find several entries of the following sort:
Code: Select all
  <button n="5">
    <desc type="string">Custom</desc>
    <repeatable type="bool">true</repeatable>
    <binding>
      <command type="string">nasal</command>
      <script type="string">controls.adjMixture(0.25)</script>
      <module type="string">__js0</module>
    </binding>
  </button>

I try to understand what the line
Code: Select all
<module type="string">__js0</module>

is meaning or necessary for.
I suppose it has something to do with namespaces as I found __js0 in http://wiki.flightgear.org/Nasal_Namespaces_in-depth
but I couldn't find a definition for the <module> xml-tag.
Thanks for any help,
deltamike
deltamike
 
Posts: 3
Joined: Wed Mar 07, 2018 9:00 pm

Re: joystick-xml-file: meaning of __js0</module>

Postby Hooray » Wed Mar 07, 2018 10:59 pm

yes, correct - it's a Nasal namespace
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: 11309
Joined: Tue Mar 25, 2008 8:40 am

Re: joystick-xml-file: meaning of __js0</module>

Postby deltamike » Thu Mar 08, 2018 9:41 am

But why sometimes there is a namespace given, sometimes not?
For example for another button in the same file:
Code: Select all
  <button n="4">
    <desc type="string">Elevator Trim Down</desc>
    <binding>
      <command type="string">nasal</command>
      <script type="string">controls.elevatorTrim(1);</script>
    </binding>
    <repeatable type="double">1</repeatable>
  </button>

When creating my own bindings, how do I know if / which namespace is necessary?
Is module==namespace?
Is there somewhere some advice how to deal with declarations of modules / namespaces in joystick configuration xml files?
deltamike
 
Posts: 3
Joined: Wed Mar 07, 2018 9:00 pm

Re: joystick-xml-file: meaning of __js0</module>

Postby Hooray » Fri Mar 09, 2018 2:46 pm

the example you cited above IS using a dedicated namespace qualifier - i.e. the controls part is the namespace (referring to controls.nas in $FG_ROOT/Nasal)
I'd suggest read up a little more on Nasal namespaces
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: 11309
Joined: Tue Mar 25, 2008 8:40 am

Re: joystick-xml-file: meaning of __js0</module>

Postby deltamike » Sat Mar 10, 2018 7:38 pm

I understand, controls is a namespace, and that in controls.adjMixture(0.25) it's used as namespace qualifier.
But what about my first example:
Are there TWO namespaces at the same time?
Code: Select all
<script type="string">controls.adjMixture(0.25)</script>
<module type="string">__js0</module>

One is controls and the other is __js0?
What is that __js0 namespace (or module) used for and why is it necessary in the binding definition of controls.adjMixture(0.25) but not in controls.elevatorTrim(1) ?
deltamike
 
Posts: 3
Joined: Wed Mar 07, 2018 9:00 pm

Re: joystick-xml-file: meaning of __js0</module>

Postby Hooray » Sat Mar 10, 2018 7:55 pm

There's rather extensive documentation about Nasal namespaces to be found in the wiki, as well as really tons information about configuring joysticks.
Personally, I have never owned a single joystick, so I am probably not in a good position to respond here with any authority.

However, with that being said, I believe that the <module> tag is used to specify the execution namespace (module/context) of the binding (basically, specifying the binding's environment)

Basically, I would expect the binding to be dynamically compiled INTO and called AS PART of the specified module.
Thus, this should be unrelated to joysticks, i.e. is a part of the implementation of the nasal fgcommand

I just checked the implementation of the FGNasalSys class, and it's apparently in line with my assumption: https://sourceforge.net/p/flightgear/fl ... .cxx#l1336

The implementation of handleCommand() can be seen here: https://sourceforge.net/p/flightgear/fl ... .cxx#l1299

The comment says:

Code: Select all
    // Commands can be run "in" a module.  Make sure that module
    // exists, and set it up as the local variables hash for the
    // command.

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: 11309
Joined: Tue Mar 25, 2008 8:40 am


Return to Hardware

Who is online

Users browsing this forum: No registered users and 1 guest