Lua file I/O

All discussions & material related to Command's Lua interface

Moderators: michaelm75au, angster, RoryAndersonCDT, MOD_Command

Post Reply
wyskass
Posts: 105
Joined: Tue Mar 08, 2022 2:45 am

Lua file I/O

Post by wyskass »

It looks like many standard Lua library functions are not exposed through CMO.
Is including additional libraries not possible?
Or even basic file I/O?
Just wanted to know, because I had a idea to have unit statuses exported to a CSV or a DB as I play to have stats available in spreadsheet.
If not the unit export functions in JSON format will do the job, just requiring an extra transformation step.
Thanks
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Lua file I/O

Post by KnightHawk75 »

Access to .io and if memory serves some of the other lua functions that are removed requires you to purchase and use the Professional version. The reason given is security precautions of allowing the basic version direct access to the file system (ie an evil author would have access to write something outside the cmo install etc). Pro users are unlikely to clog support with "something deleted my something something file on me.", no mater if it was actually the case or not), and authors can't write malicious or just code that goes horribly wrong in our scenes for the general public).

For storage without pro you can use attachments, a folder structure with pre-made files to read from, and the flexible scene key-store within lua itself that will be resaved inside each save where you can store a string value of nearly any length (which allows you save lua tables you create\update from memory).

workaround(s):
You can of course in the console open and run something that dumps to the screen to copy and paste, or you can look in or maybe build something external to parse/keep reparsing your lua session log for the same data if you are writing at some interval.
You could build something that tracks and displays the data too you inside the game as well, remember the SpecialMessage string supports html 4.0 and css of (mshtml of ie8/9 time frame), so if you want to take the time you can display table data without too much trouble in a message to yourself or the user.
I think there is an example floating around from me in Lua Legion called "pretty fuel table" or something like that. Another user had pretty slick way of drawing the elevation view from a point and heading selection that displaying as special message.
wyskass
Posts: 105
Joined: Tue Mar 08, 2022 2:45 am

Re: Lua file I/O

Post by wyskass »

Yea, that's true about the security issue. Once could package a small executable in the .scen xml and then execute on the users system, and there you have a nice attack vector.
But, was comparing to XPlane, where Lua and add-ons have much more access to system.

I suppose there are some clever other ways of using Lua as you mentioned.
Am also trying to hack the mapping system, to access my own local map server. Thought I could just re-configure the sources, but may have to spoof urls. (Yes, I know there are custom overlays, but this would be more dynamic)
wsxtgly
Posts: 13
Joined: Wed Feb 21, 2018 4:53 am

Re: Lua file I/O

Post by wsxtgly »

KnightHawk75 wrote: Sun Apr 17, 2022 2:44 am Access to .io and if memory serves some of the other lua functions that are removed requires you to purchase and use the Professional version. The reason given is security precautions of allowing the basic version direct access to the file system (ie an evil author would have access to write something outside the cmo install etc). Pro users are unlikely to clog support with "something deleted my something something file on me.", no mater if it was actually the case or not), and authors can't write malicious or just code that goes horribly wrong in our scenes for the general public).

For storage without pro you can use attachments, a folder structure with pre-made files to read from, and the flexible scene key-store within lua itself that will be resaved inside each save where you can store a string value of nearly any length (which allows you save lua tables you create\update from memory).

workaround(s):
You can of course in the console open and run something that dumps to the screen to copy and paste, or you can look in or maybe build something external to parse/keep reparsing your lua session log for the same data if you are writing at some interval.
You could build something that tracks and displays the data too you inside the game as well, remember the SpecialMessage string supports html 4.0 and css of (mshtml of ie8/9 time frame), so if you want to take the time you can display table data without too much trouble in a message to yourself or the user.
I think there is an example floating around from me in Lua Legion called "pretty fuel table" or something like that. Another user had pretty slick way of drawing the elevation view from a point and heading selection that displaying as special message.
hi,can you give me a link about you mentioned lua "pretty fuel table" and "drawing the elevation" code ? thanks.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Lua file I/O

Post by KnightHawk75 »

So I did the searching for you... cause I remember what to sort of search for (key to using the site search feature).


Pretty fuel table example from me:
https://www.matrixgames.com/forums/view ... fuel+table

NASH 1.0 by musurca - Drawing framwork for special messages, elevations/pov demo'd:
https://www.matrixgames.com/forums/view ... w+graphics
https://github.com/musurca/NASH/release ... H_v1.0.zip
wsxtgly
Posts: 13
Joined: Wed Feb 21, 2018 4:53 am

Re: Lua file I/O

Post by wsxtgly »

Thanks a lot !
Post Reply

Return to “Lua Legion”