Board index FlightGear Development Nasal

Is there a way to call out to Nasal functions from C++ code?

Nasal is the scripting language of FlightGear.

Is there a way to call out to Nasal functions from C++ code?

Postby chriscalef » Sat Feb 15, 2020 1:46 am

I'm just wondering, because I'd like to do things like start the KA50 engines from the C++ side, not sure how that would best be done.

Thanks!
chriscalef
 
Posts: 279
Joined: Wed Feb 20, 2013 10:28 pm

Re: Is there a way to call out to Nasal functions from C++ c

Postby Hooray » Sat Feb 15, 2020 10:26 am

Yes, that's possible - see the cppbind article.
But I don't think that's what you need, you will probably want to look at fgcommands, properties and specifically emesary i.e. all you need is a wrapper on top of the Nasal bindings and invoke those.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Is there a way to call out to Nasal functions from C++ c

Postby chriscalef » Sat Feb 15, 2020 5:15 pm

Hmm, yeah my short term problem was solved by setting "/controls/engines/engine/magnetos" to 1. But I'm still way back at the beginning of the learning curve re: all things Nasal.
chriscalef
 
Posts: 279
Joined: Wed Feb 20, 2013 10:28 pm

Re: Is there a way to call out to Nasal functions from C++ c

Postby Hooray » Sun Feb 16, 2020 2:25 pm

That's a bit too low-level for my taste, i.e. not really scalable - I would definitely recommend looking at fgcommands and/or Emesary to encapsulate aircraft-specific Nasal code.
In fact, the lazy way would be to use Nasal to load a panel/aircraft bindings and procedurally wrap all bindings by registering them as fgcommands, that way you end up with a mechanism that also works over TCP/IP (props/telnet) or from C++ (SGCommandMgr).

Once you got the hang of fgcommands, you will probably appreciate the power of using Emesary notifications, which can also be registered as fgcommands.

Ideally, in a perfect world, aircraft bindings would not contain any Nasal "blobs" at all but would work via fgcommands only - embedding Nasal blobs all over the place comes with the same flexibility and power that Nasal embedded inside GUI dialogs brings with it, but also suffers from the same long-term issues.

Again, using ~50 lines of Nasal it should be fairly easy to write a helper function that opens a panel/cockpit to read out all Nasal blobs and wrap them as dedicated fgcommands that would then be aircraft specific.

This kind of setup would also work well for anything involving Phi/FGQCanvas or multi-instance setups (FSWeekend/LinuxTag)

Using Nasal "as is" is problematic for a variety of reasons, as you'll figure out once you try to support more complex aircraft/startup routines

Besides, there is a "checklists" subsystem which supports execution of checklists, in conjunction with the fgcommand/Emesary approach, you could literally execute checklists remotely - no matter if "remote" is in some piece of Nasal code, C++ or inside another thread/process
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests