Post #13by Joe » 08.10.2018, 09:20
From Lua 5.1 to 5.2, there has been a big jump between the two versions, which makes the hooking/wrapping between Celestia and Lua 5.2 quite a challenging task. Although, from Lua 5.2 to 5.3, it is a smooth upgrading between the two versions, the fixes on Lua 5.3 with Celestia are not automatic.
1. I have had a test over the latest Celestia 1.7 branch and I am quite confident that the fixes on Lua 5.2 is complete and robust, but I am not sure those fixes are all equally applicable to Lua 5.3.
2. Because table.getn() is no longer available in Lua5.2 onward, we have to write our own getn() function in celx and lua scripts.
3 . Accroding to lua manual, math.mod was renamed to math.fmod in lua 5.2.
4. In lua 5.3, the following functions are deprecated in the mathematical library: atan2, cosh, sinh, tanh, pow, frexp, and ldexp. We can replace math.pow(x,y) with x^y, math.atan2 with math.atan (which now accepts one or two parameters), math.ldexp(x,exp) with x * 2.0^exp. For the other operations, we can either use an external library or implement them in Lua.
5. As lua 5.2 and 5.3 onward, "unpack" has moved to table.unpack, as a result we need following line in the beginning of a lua programme
if this programme has previously used unpack:
unpack = table.unpack
6 From Lua 5.2, goto statement is added. As a result, celestia:goto() has to be defined otherwise.
7. From Lua 5.3, string.format for converting float values into integer values (%d or %x) is no longer as tolerant as Lua 5.2. It requires that float values to be converted first into integer %d or %x using math.floor (or math.ceil).
For example, the function rgb2hex(r,g,b) in file z-dist.tdsx, for Lua 5.3, it must be coded like this:
local hex = string.format("#%.2x%.2x%.2x", math.floor(r), math.floor(g), math.floor(b))
But for Lua 5.2, it can be tolerant the following code:
local hex = string.format("#%.2x%.2x%.2x", r, g, b)
8. From Lua 5.2, string.gfind() is replaced by string.gmatch()
9. With Lua 5.1:
date = celestia:tdbtoutc(time);
systime = os.time({year=date.year, month=date.month, day=date.day, hour=date.hour, min=date.minute, sec=date.seconds});
With Lua 5.2/5.3:
date = celestia:tdbtoutc(time);
systime = os.time({year=date.year, month=date.month, day=date.day, hour=date.hour, min=date.minute, sec=math.floor(date.seconds)});
Joe