Jump to content
The simFlight Network Forums

Lua Libraries


Recommended Posts

Have found much use for Lua programs.

Have been creating them creating them using Notepad.

Just got an standalone Development tool to help with creating them.

Looking for the 3 libraries - ipc, event and logic - so that i could add their location to the tool's settings and the compiler is able to find them.

Where can i find those libraries?

Thanks in advance.

Link to comment
Share on other sites

Looking for the 3 libraries - ipc, event and logic - so that i could add their location to the tool's settings and the compiler is able to find them.

All of the Lua libraries supported in FSUIPC -- both the standard ones and the ones I've added -- are built into FSUIPC and preloaded into your Lua process before it is executed. There's no need to refer to them anywhere else/

Pete

Link to comment
Share on other sites

Pete -

Thanks.

Here is my situation -

I am trying to compile my lua scripts before i place them in the FS Modules directory so that i can check for syntax and logic correctness.

However, the compiler - luac.exe - throws an error each time it encounters, for example, an ipc.macro() call - and I think i understand why - its because the ipc.macro() function is not a part of the core lua implementation. Its looking for the ipc libraries in this case.

Hence my earlier question of where I could access them. I understand that for the runtime, those libraries are already included in your FSUIPC implementation and i dont need to do anything else to use them.

Your help is much appreciated.

regards,

CPJ

Link to comment
Share on other sites

I am trying to compile my lua scripts before i place them in the FS Modules directory so that i can check for syntax and logic correctness.

Well the error messages provided by the compiler are, as far as I know, the same as the ones put into the FSUIPC log (or the Lua program's own log, if you enable Lua logging in FSUIPC options) when FSUIPC's built-in Lua compiler tries to load the programs, so I don't think you achieve anything extra. Do let me know if I'm wrong though, and perhaps i might have to work out a way of providing dummy libraries.

Regards

Pete

Link to comment
Share on other sites

Pete:

You are absolutely right. The messages are the same.

Perhaps the only reason I am even wanting to do this via an development environment is because some of my Lua programs are long and with complex logic. For example, i wrote my own EGT gauge simulation that i use to drive a phidgets servo. It works well.

But to get that done I had to load and exit MSFS several times becuase of the number of errors that would creep or changes i would need to make.

The reason for that being the case is that changes made to Lua scripts are not recognized by FSUIPC till it loads afresh. So i have to exit MSFS and reload each time i make a change.

Thats why i wanted to do the compiles outside and ensure everything works before i even load them up the first time.

Dummy libs will be a great help.

regards,

Jois

Link to comment
Share on other sites

But to get that done I had to load and exit MSFS several times becuase of the number of errors that would creep or changes i would need to make.

The reason for that being the case is that changes made to Lua scripts are not recognized by FSUIPC till it loads afresh. So i have to exit MSFS and reload each time i make a change.

No, that is incorrect. The Lua file scan is performed every time you press one of the "Reload" buttons on the Buttons, Keys, or Axes tabs. The same applies to Macro files.

Thats why i wanted to do the compiles outside and ensure everything works before i even load them up the first time.

I've developed lots of Lua programs for my own cockpit and i've never had to reload FS.

Dummy libs will be a great help.

At present i wouldn't even know how to start on that (would you?), and I don't want to undertake unnecessary work.

BTW if you are using FSUIPC4 you can use the FSUIPC4 Log Console window to view the results of loading your Lua programs in real time -- without the Lua logging option, of course (that only works on files).

Regards

Pete

Link to comment
Share on other sites

No, that is incorrect. The Lua file scan is performed every time you press one of the "Reload" buttons on the Buttons, Keys, or Axes tabs. The same applies to Macro files.

Pete, please help me with this a little bit. I am not sure i understand it. What is a "Reload" button? A button setup to force a scan?

If this is indeed the case, let me try it. That will ease some of the pain.

Of course, the power of being able to debug complex logic via an development environment where once can use callstacks, breakpoints, variables watches is always better, but i dont want to trouble you with more work.

One way i thought you could provide your libraries without giving it away in full is provide user libraries containing only function call stubs in it. That way the compiler will have the function available and wont throw an error.

Yes, full scale debugging wont be possible but one will at least know if the script compiles correctly.

Just a thought... will think more about it tonite.

On the other hand, please do help me with the "reload" you referred in your post. That should ease a lot of the pain.

I am not using FSUIPC4 - i am on 3.9.

As always, many thanks.

Regards,

CPJ

Link to comment
Share on other sites

Pete, please help me with this a little bit. I am not sure i understand it. What is a "Reload" button? A button setup to force a scan?

If you go to the Buttons & Switches tab, in FSUIPC options, or the Keys tab, you will see an ordinary Windows-type dialogue button which you can use to reload all those types of assignments (relevant to the Tab). Because macro files and Lua files might be implicated in such assignments, those are reloaded too.

I'm amazed that you've got as far as developing Lua programs for FSUIPC, but have never had cause to change some edited assignment in the INI file and used the reload button to reload it!?

Of course, the power of being able to debug complex logic via an development environment where once can use callstacks, breakpoints, variables watches is always better, but i dont want to trouble you with more work.

Lua provides ways for you to do all that via the Debug library. A basic use of the debug library is made in the supplied ipcDebug.lua file. I'm not going to start messing about inside the Lua code itself to add more than what they provide, which looks certainly most adequate. Combine that with the Logging facilities and you should be well away. Lua doesn't provide a step-by-step trace or inspection capability, you have to build what you want into your program I think.

One way i thought you could provide your libraries without giving it away in full

What does that mean? There are no such libraries, at least as such -- the routines you call via ipc. are just more elaborate and thread-safe entries to the same routines in FSUIPC which can be called by C/C++ programs. They are intrinsic parts of FSUIPC. There's no way there's anything more to "give away" than already published in the sources in the FSUIPC SDK!! And they cannot possibly actually do anything outside of FSUIPC!

I think all you need to do is make a file called ipc.lua and include in it dummy functions with all the names in. They don't need to do anything. You then have to add

require "ipc"

I think this uses the built-in "loadlib" function, which I've not tested. But it should work okay. it's Lua code, not mine.

BTW according to the "Programming in Lua" book it is good practice to do this for any libraries you require even if you know they are effectively built-in or pre-loaded.

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.