Page 1 of 1

Updating Lua plugins

Posted: 12.10.2019, 00:34
by SevenSpheres
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?

Posted: 12.10.2019, 00:49
by Lafuente_Astronomy
You may refer to Gironde. He had a hand in developing the LUA, I think

Posted: 12.10.2019, 07:44
by Janus
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

Posted: 12.10.2019, 08:49
by gironde
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 #?

Posted: 12.10.2019, 13:47
by onetwothree
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.

Posted: 12.10.2019, 16:00
by Janus
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.

Posted: 12.10.2019, 17:36
by SevenSpheres
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.

Posted: 12.10.2019, 17:57
by Janus
@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.

Posted: 12.10.2019, 18:40
by SevenSpheres
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?

Posted: 12.10.2019, 18:49
by Janus
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.

Posted: 12.10.2019, 18:56
by onetwothree
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

Posted: 12.10.2019, 19:02
by Janus
@onetwothree
Better answer than mine.


Janus.

Posted: 13.10.2019, 07:05
by gironde
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 #

Posted: 13.10.2019, 15:12
by Janus
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.

Posted: 14.10.2019, 18:24
by Janus
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.