Reading a file in a Lua script

All about writing scripts for Celestia in Lua and the .cel system
Topic author
NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Reading a file in a Lua script

Post #1by NASA_SimGuy » 20.03.2020, 15:23

I want to read a large events file in my.celx script. I will use this to print event text to the screen during a "spacecraft" trajectory flight. I noticed that the io.open will not work because the io.dll is not included in Celestia. Is there a "work around" to getting my large text file into a Lua script? Should I attempt to install the io.dll myself. I installed socket.dll many years ago and it worked.

onetwothree
Site Admin
Posts: 704
Joined: 22.09.2018
With us: 5 years 7 months

Post #2by onetwothree » 20.03.2020, 15:37

without all required information the answer is "i don't know". what celestia version do you use? what operation system (i assume windows as you are talking about dll). our builds of 1.6.2 beta and 1.7 don't require any additional dlls.
Last edited by onetwothree on 20.03.2020, 18:33, edited 1 time in total.

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Post #3by selden » 20.03.2020, 15:53

Lua io. routines are working for me with both 1.6.1 and 1.7 without the presence of an explicit io.dll.

I'm assuming you've included this statement in your CelX script:

Code: Select all

celestia:requestsystemaccess()


I might have asked this before, but what version of Celestia are you running? 1.6.1, 1.6.2, 1.7? If it's 1.7, then you might not have the most recent binaries.

Another thing to check is the version of lua51.dll that you have. For example, how large is your lua51.dll? Mine for 1.7 is 358KB.
And here's its md5 checksum:

Code: Select all

Algorithm : MD5
Hash      : ACF6330A105FDC128009FD089F2C499F
Path      : C:\MyPrograms\Celestia_1.7.0\lua51.dll


FWIW, I'm using the 3rd party Win10 utility "Winaero Tweaker" to get convenient RMB menu options like checksum calculators.
Selden

Topic author
NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Post #4by NASA_SimGuy » 20.03.2020, 16:42

my lua5.1.dll is 236kbytes. I am using Celetstia 1.6.1.

I tried celestia:requestsystemaccess() but I received the same io error.

I wasn't aware that any version is more recent than 1.6.1. Is there an installer of do I have to build it? Maybe my quaternions will work with the new verison 1.7. I went to the download page and I only see 1.6.1 available.

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Post #5by selden » 20.03.2020, 17:15

Unfortunately, 1.7 is still in "pre-alpha" mode and has quite a few changes and, well, bugs. I suggest it would not be appropriate to use 1.7 while trying to develop "production code" since it'd be rather difficult to separate bugs in your code from bugs or changes in Celestia.

My copy of lua51.dll that accompanies Celestia v1.6.1 is 236 KB also, and its MD5 checksum is

Code: Select all

Algorithm : MD5
Hash      : 09819D1BEEF0F0BEEC849B6FD3581247
Path      : C:\MyPrograms\Celestia\lua5.1.dll


Where is your copy of Celestia installed?
(FWIW, I just now verified that I can use io. when running Celestia from a non-priv'd account, so privileges shouldn't be an issue.)

Now I'm wondering if the problem is caused by Celestia having been installed in the Windows directory "Program Files (x86)".
Windows is getting more and more protective about actions which affect its system directories. That's one of the reasons why I created my own separate directory named 'C:\MyPrograms\" (note no space) into which I install 3rd party software like Celestia.

Topic author
NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Post #6by NASA_SimGuy » 20.03.2020, 18:07

I moved "C:\Program Files (x86)\Celestia" to MyDocuments and I still get the io error.

I added celestia:requestsystemaccess() at the top but I get the error.

I right clicked on the Celestia Desktop short cut and ran it "As Administrator" but I get the error.

Did you have to add the line: require "io" when you successfully got 1.6.1 working? I get a dialog box "attempt to index global 'io' (a nil value)

Can you show me your line of test code.

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Post #7by selden » 20.03.2020, 18:30

Sorry, at this point I don't know what might be going wrong :(

Here's a zip of a CelX Addon which does file i/o (to read .csv files) that I recently updated and have been using with no problems. I'm guessing that it'll fail for you. :(

nroutes_v1.5.zip
nroutes reads csv files
(12.9 KiB) Downloaded 234 times
Selden

onetwothree
Site Admin
Posts: 704
Joined: 22.09.2018
With us: 5 years 7 months

Post #8by onetwothree » 20.03.2020, 18:36

what do you see and what do you do on celestia:requestsystemaccess() execution?

Topic author
NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Reading a file in a Lua script

Post #9by NASA_SimGuy » 20.03.2020, 19:03

Sorry, onetwothree. My celestia:requestsystemaccess statement was ambiguous. I placed the celestia:requestsystemaccess statement at the top of my script. I still am getting the same missing io error.
There was no error on the line where I added celestia:requestsystemaccess.

Thanks Seldon, for the zip file. It appears that my code is similar to yours.

I attempted to run the script twice. Celestia warned me first, then allowed me to continue. See my screen shots.

Well, I don't know how to insert images so I'll type it:
This script requests permission to read/write files
and execute external programs. Allowing this can be dangerous.
Do you trust the script and want to allow this?

yes? No?

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Post #10by selden » 20.03.2020, 19:22

@SimGuy:

Yup, that's the appropriate on-screen prompt.

Sorry, I previously forgot to mention that you actually need two lines in order for i/o to be allowed:

Code: Select all

celestia:requestsystemaccess()
wait(0)

Without the wait, I doubt it'll work. I dunno if that's your problem, though.

For details, see https://en.wikibooks.org/wiki/Celestia/Celx_Scrip ... x_celestia#requestsystemaccess

To insert a picture, while working on a post, you should select the option "Full Editor & Preview" down at the bottom of the "Quick Reply" window. The editor page provides two ways to insert an image. In both cases, you still need to select the option "insert inline" for it to actually show up.

See screengrabs below, which were inserted using this method:

insert image (1).png
first of image insert help

insert image (2).png
second image insert help

insert image (3).png
third image insert help
Selden

Topic author
NASA_SimGuy
Posts: 24
Joined: 18.10.2018
With us: 5 years 6 months

Reading a file in a Lua script

Post #11by NASA_SimGuy » 23.03.2020, 12:16

The 'wait(0)' fixed my problem. I also modified the celestia.cfg so I don't get the nag message.

I am testing the attachment process with my nag message.
Thanks again for you help.
Attachments
IMG_6718.jpg

Avatar
selden
Developer
Posts: 10190
Joined: 04.09.2002
With us: 21 years 8 months
Location: NY, USA

Post #12by selden » 23.03.2020, 16:08

Thanks for letting us know that lacking the wait() caused the problem! That's a relief, since it'd be very frustrating otherwise.

Best of luck with getting your Quaternions to work as they should.
Selden


Return to “Scripting”