Updating Lua plugins

Have a question about using Celestia? Check here first for FAQs and helpful advice.
Forum rules
Please help to make this forum more useful by checking the FAQs before posting! Keep it clean, keep it civil, keep it truthful, stay on topic, be responsible, share your knowledge.
Avatar
Topic author
SevenSpheres
Moderator
Posts: 826
Joined: 08.10.2019
With us: 5 years 1 month

Updating Lua plugins

Post #1by SevenSpheres » 12.10.2019, 00:34

Sometime after version 1.7 Celestia will drop support for Lua 5.1, so all Lua plugins need to be updated to the latest version (5.3 or maybe 5.4). I've tried to update the Lua Edu Tools by replacing "table.getn(foo)" with "#foo". When I did this in Celestia 1.6.2-beta1 (which doesn't support Lua 5.1) I saw this:

luabug.png


Obviously some other code needs to change, but I don't know what that is. Can someone who knows more about Lua help with this?
My Addons: viewtopic.php?f=23&t=19978 • Discord server admin
Celestia versions: 1.5.1, 1.6.1, 1.6.2, 1.7.0, and some unofficial versions like Celestia-ED

Avatar
Lafuente_Astronomy
Moderator
Posts: 726
Joined: 04.08.2018
Age: 26
With us: 6 years 3 months
Location: Cebu City, Cebu Province, Philippines
Contact:

Post #2by Lafuente_Astronomy » 12.10.2019, 00:49

You may refer to Gironde. He had a hand in developing the LUA, I think
Official Administrator of the Celestia Discord Server.
Invite: https://discordapp.com/invite/WEWDcJh
If you don't have a Discord account, register here: https://discordapp.com/register
Have a blessed day.

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #3by Janus » 12.10.2019, 07:44

I have been working on restoring getn since the # symbol annoys me.

However, in my research I came across an actual reason to restore it.

getn works with lua tables, # does not.

Which means that as long as you use generic arrays, everything is fine.
If you use tables however, it does not.
I can not say anyone ever will or will not use tables, but a difference is a difference.
The code for # walks the array to count, where getn retrieves the size from the structure itself.
getn works the same regardless of the type, # does not.
Plenty of reason for me to keep the former, while leaving but ignoring the latter.


Janus.

EDIT: added for quick reference.
https://stackoverflow.com/questions/31452871/tabl ... n-i-get-the-length-of-an-array

Avatar
gironde M
Posts: 851
Joined: 16.12.2016
Age: 72
With us: 7 years 11 months
Location: Montigny-Les-Metz, France

Post #4by gironde » 12.10.2019, 08:49

LUT5 has been tested with celestia 1.6.1 and celestia EP V3 (1.7.0 5229 from the Russian Celestia website). The executables (32 bits) are mounted with LUA 5.1.
The lua modules of LUT5 use the table statement: getn (your_table).

Celestia 1.6.2 installer (32 / 64bit) is mounted in its beta version 1 with lua 5.2 / lua 5.3.
First observation: the installer does not leave the choice between 32 or 64 bits; if you have a 64-bit PC, it will install the 64-bit version. I found that it did not suit me because to test my achievements in lua, I use DECODA debugger that works only 32 bits.

Then: once celestia 1.6.2 64 bit installed, it seems to work very well. When I copied my extras and lua_applications, I got an error message about table: getn (). I searched all the getn and replaced them with # to comply with lua5.1, 5.2, 5.3.
Once done, I restarted clestia 1.6.2 64 bits and now loading files stops after a while without message.

The change of getn by #, I did it also in my old versions celestia 1.6.1 and celestia EP V3. In its versions, everything works correctly with #.

Why celestia 1.6.2 (64 bits) crashes at loading, I do not know either because.

For the problem of Janus:
Maybe Janus uses other types of lua tables for which change by # is not appropriate. I do not know.
The image of Janus shows a disturbance in celestia's display at the top left but not in his menu lua_applications. Is there not a font problem? Does this problem occur only with the change by #?

onetwothree
Site Admin
Posts: 706
Joined: 22.09.2018
With us: 6 years 2 months

Post #5by onetwothree » 12.10.2019, 13:47

Both getn and # are crap:

Code: Select all

function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

local array = {5, "text", {"more text", 463, "even more text"}, "more text"}
array[10] = 1;
print(#array)
print(table.getn(array))
print(tablelength(array))


With luajit I have:

Code: Select all

4
4
5


# works with continuous "arrays" only. getn was deprecated in 5.1, so it's barely legal in 5.1 syntax.

To answer the question "why we want to use lua5.3 or later":
The last release was Lua 5.1.5, released on 17 Feb 2012. There will be no further releases of Lua 5.1.

LuaJIT provides support for 5.1 syntax but it's not actively maintained, the latest update was 9 months ago.

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #6by Janus » 12.10.2019, 16:00

Speaking strictly for myself and no one else.
I am patching getn back in to the lua 5.3 library I use.

Then I will have a personal lua fork to go with my personal celestia fork.
Actually, I will use this fork in all my stuff where I have lua as my script.
I had no intention of forking more than celestia since I dislike QT, but it looks like that has changed.

I know I am the minority, but I prefer clarity and readability over shorthand.
Visual flow during analyses is important to understanding logic.
getn makes sense visually, # is just noise, to me at least.

I will put my code when I have it done, and made a place to put it.


Janus.

Avatar
Topic author
SevenSpheres
Moderator
Posts: 826
Joined: 08.10.2019
With us: 5 years 1 month

Post #7by SevenSpheres » 12.10.2019, 17:36

Janus, gironde, onetwothree:

Can I just have a list of things I need to change, like "change x to y"? I really don't know much about Lua.
My Addons: viewtopic.php?f=23&t=19978 • Discord server admin
Celestia versions: 1.5.1, 1.6.1, 1.6.2, 1.7.0, and some unofficial versions like Celestia-ED

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #8by Janus » 12.10.2019, 17:57

@SevenSpheres

The best place to learn about LUA, is https://www.lua.org, which has good guides and documentation.
You can find lists of additions and deprecations there by looking through release notes.

I am not a good guide to lua, or large project programming in general really, I tend to make my own tools.
Just like in my own fork I use local to the project copies of support libraries because I like to know the exact state when I compile.
I also sometimes struggle since cmake is incompatible with my setup.

The LUA function I am adding back is because I dislike what replaces it, which does not visually or mentally flow for me.
There is zero requirement for anyone else to use it even if they use my fork.


Janus.

Avatar
Topic author
SevenSpheres
Moderator
Posts: 826
Joined: 08.10.2019
With us: 5 years 1 month

Post #9by SevenSpheres » 12.10.2019, 18:40

Janus:

On lua.org I don't see any changelogs or guides for updating old scripts. (That doesn't mean there aren't any, I may have just missed them.) Do you know where I can find either of these?
My Addons: viewtopic.php?f=23&t=19978 • Discord server admin
Celestia versions: 1.5.1, 1.6.1, 1.6.2, 1.7.0, and some unofficial versions like Celestia-ED

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #10by Janus » 12.10.2019, 18:49

I always look in the source packs first.

The manual.html files in them are good place to start.
Start by grabbing the sources for the last releases of 5.0/5.1/5.2/5.3, deprecations are listed inside.


Janus.

onetwothree
Site Admin
Posts: 706
Joined: 22.09.2018
With us: 6 years 2 months

Post #11by onetwothree » 12.10.2019, 18:56

SevenSpheres wrote:On lua.org I don't see any changelogs or guides for updating old scripts.

Check a document called Lua X.Y Reference Manual, section Incompatibilities with the Previous Version,

https://www.lua.org/manual/5.1/manual.html#7
https://www.lua.org/manual/5.2/manual.html#8
https://www.lua.org/manual/5.3/manual.html#8

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #12by Janus » 12.10.2019, 19:02

@onetwothree
Better answer than mine.


Janus.

Avatar
gironde M
Posts: 851
Joined: 16.12.2016
Age: 72
With us: 7 years 11 months
Location: Montigny-Les-Metz, France

Post #13by gironde » 13.10.2019, 07:05

For my part, I dropped the site https://www.lua.org/manual/5.1 because it is very difficult to learn a programming language in a foreign language. I found this:
https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/
It's in French.
The replacement of table.getn () with # is noted in this tutorial.

I agree with janus, table.getn () was much more talk than #

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #14by Janus » 13.10.2019, 15:12

I think I have chased down all the bits of getn.
I should have Lua 5.3 with getn restored today.

Once I have finished getting my existing VS project files to work with the latest commit, I will post exes for people to test.
This may take a few days as I juggle work.
A current customer asked if I could over clock their equipment by upping the mains frequency.
I treated it as him asking humorously.


Janus.

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 3 months

Post #15by Janus » 14.10.2019, 18:24

Okay, question for the crowd.

Restoring getn is involved.
Its function is dependent on internal structures which have changed.
getn treats tables and arrays the same, # only works on arrays.

My question is this.
Do I restore just the name, which is mostly straightforward, but will leave getn working just like #.
Or do I continue and fully restore the getn functionality.

I ask because the only real difference is that getn returns the size of tables reliably, which # does not.
Is that difference worth the effort, or possible impact on lua speed if there is any.



Janus.


Return to “Help Central”