Page 1 of 1
Reading a file in a Lua script
Posted: 20.03.2020, 15:23
by NASA_SimGuy
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.
Posted: 20.03.2020, 15:37
by onetwothree
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.
Posted: 20.03.2020, 15:53
by selden
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:
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.
Posted: 20.03.2020, 16:42
by NASA_SimGuy
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.
Posted: 20.03.2020, 17:15
by selden
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.
Posted: 20.03.2020, 18:07
by NASA_SimGuy
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.
Posted: 20.03.2020, 18:30
by selden
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.
Posted: 20.03.2020, 18:36
by onetwothree
what do you see and what do you do on celestia:requestsystemaccess() execution?
Reading a file in a Lua script
Posted: 20.03.2020, 19:03
by NASA_SimGuy
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?
Posted: 20.03.2020, 19:22
by selden
@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#requestsystemaccessTo 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:
- first of image insert help
- second image insert help
- third image insert help
Reading a file in a Lua script
Posted: 23.03.2020, 12:16
by NASA_SimGuy
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.
Posted: 23.03.2020, 16:08
by selden
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.