Problem with File I/O

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Message
Author
The Artful Dodger
Posts: 204
Joined: Sat Jul 09, 2022 3:20 pm

Problem with File I/O

#1 Post by The Artful Dodger »

Hello, all:

I was just starting to add a feature to my instrument that requires me to save information in a file and then read it when the instrument starts. Here's the code:

Code: Select all

-- Open a file for read and test that it worked.
fh, err = io.open("E:AircraftVSpeeds.txt")
--
if (err) then
print("OOPS"); return; end
--
-- line by line.
--
line = fh:read()
if line ~= nil then
	print (line)
end
--
fh:close()
It's a very simple program and I frequently use that idea to test a concept. But this time it threw an error that i cannot solve: ERROR - logic.lua:2: attempt to index a nil value (global 'io'). I've used the same set of instructions in SciTE (LUA IDE) and it works a treat so I am lost.

Any help would be most appreciated.

Sparky

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Problem with File I/O

#2 Post by Ralph »

File IO isn't possible/enabled, for various reasons.

The Artful Dodger
Posts: 204
Joined: Sat Jul 09, 2022 3:20 pm

Re: Problem with File I/O

#3 Post by The Artful Dodger »

But that's part of LUA. I have been planning on using this for a long time. In fact, you yourself suggested it on Friday, 2 September at 0112, under "A Question Please", you said: You can read the name of the aircraft, then pick from your own made list of data according to the aircraft you're flying." That's exactly what I am doing and now, after all this time, you tell me I can't do what you suggested?
That's not fair. There must be a way you can allow me to use all of LUA. That's like selling a car but without the steering wheel! You have got to fix this.

Sparky

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Problem with File I/O

#4 Post by Keith Baxter »

Hi,

I/O is restricted due to security reasons. We have been down this path before many times.

To do what you want use persist_add()
https://siminnovations.com/wiki/index.p ... ersist_add

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

The Artful Dodger
Posts: 204
Joined: Sat Jul 09, 2022 3:20 pm

Re: Problem with File I/O

#5 Post by The Artful Dodger »

Hi, Keith :
Pardon my ignorance but what kind of "security reason" do I cause by reading a data file in my instrument's folder, right along side of the logic.lua file?
I looked at the "persistence" functions last night and I don't see how they can work in my application. But I'll look again. But please tell me the security problems - even if you have to send me a PM to do it.

Thanks.

Sparky

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Problem with File I/O

#6 Post by SimPassion »

The Artful Dodger wrote: Sun Oct 23, 2022 6:36 pm Hello, all:

I was just starting to add a feature to my instrument that requires me to save information in a file and then read it when the instrument starts. Here's the code:

Code: Select all

-- Open a file for read and test that it worked.
fh, err = io.open("E:AircraftVSpeeds.txt")
--
if (err) then
print("OOPS"); return; end
--
-- line by line.
--
line = fh:read()
if line ~= nil then
	print (line)
end
--
fh:close()
It's a very simple program and I frequently use that idea to test a concept. But this time it threw an error that i cannot solve: ERROR - logic.lua:2: attempt to index a nil value (global 'io'). I've used the same set of instructions in SciTE (LUA IDE) and it works a treat so I am lost.

Any help would be most appreciated.

Sparky
If it's only a matter of data reading, why not use static data feature, many of us already using it ?
https://siminnovations.com/wiki/index.p ... _data_load
 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Problem with File I/O

#7 Post by Sling »

As Keith has already said we have been down this path before. AM does not support every Lua feature. You at least haven’t really started with it yet but I spent a lot of time implementing Lua I/O into an instrument back when it was not disabled. When a newer version came out suddenly the I/O was not working. Hence the previous discussions on this.

Surely you understand the security issue related to being able to read / write any file on your computer from an instrument script.

User avatar
Corjan
Posts: 2936
Joined: Thu Nov 19, 2015 9:04 am

Re: Problem with File I/O

#8 Post by Corjan »

Hi,


It is not a security reason, it is a compatibility one.

Since instruments and panels can run on many different platforms (iPad, Android, Windows, Mac, Linux), allowing unregulated file can break compatibility. Same goes for fonts, we don't rely on system fonts.


Corjan

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Problem with File I/O

#9 Post by Ralph »

Well... I wouldn't want any instrument I download potentially messing around in my files as well :)

The Artful Dodger
Posts: 204
Joined: Sat Jul 09, 2022 3:20 pm

Re: Problem with File I/O

#10 Post by The Artful Dodger »

You under estimate the quality of my programming!
Sparky

Post Reply