Dear devs, can you share your patches for Lua?

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
User avatar
hhrhhr
Inserter
Inserter
Posts: 36
Joined: Mon Feb 18, 2019 11:02 pm
Contact:

Dear devs, can you share your patches for Lua?

Post by hhrhhr »

from help:
Factorio API wrote:Libraries and functions
2. New functions
pairs()

In standard Lua, the order of iteration when using pairs() is arbitrary. Because Factorio has to be deterministic, this was changed in Factorio's version of Lua. Factorio's iteration order when using next(), which pairs() uses for iteration, depends on the insertion order: Keys inserted first are iterated first. However, Factorio also guarantees that the first 1024 numbered keys are iterated from 1-1024, regardless of insertion order. This means that in usual usage, pairs() does not have any drawbacks compared to ipairs().
Interesting things highlighted.
In Lua 5.2+, the iteration order is not deterministic, which leads to different results after each cycle. LuaJIT uses hashes to sort, but the order is always the same.

Example of pairs() output:

Code: Select all

+--------------+---------------+---------------+
!              ! Factorio      ! LuaJIT        !
! local t = {} +---------------+---------------+
! t.aaaa  = 1  ! [500]     = 5 ! [2000]    = 7 !
! t.aa    = 2  ! [1000]    = 3 ! [1000]    = 3 !
! t[1000] = 3  ! ["aaaa"]  = 1 ! ["aaaa"]  = 1 !
! t.a     = 4  ! ["aa"]    = 2 ! ["aa"]    = 2 !
! t[500]  = 5  ! ["a"]     = 4 ! [500]     = 5 !
! t.aaaaa = 6  ! ["aaaaa"] = 6 ! ["a"]     = 4 !
! t[2000] = 7  ! [2000]    = 7 ! ["aaaaa"] = 6 !
+--------------+---------------+---------------+
These changes are very interesting. Is there any way to see them in the form of code / patches / algorithms?

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Dear devs, can you share your patches for Lua?

Post by posila »

Code is here: https://github.com/Rseding91/Factorio-Lua
Unfortunatelly, you'll have to diff it against original Lua 5.2.1 yourself.

User avatar
hhrhhr
Inserter
Inserter
Posts: 36
Joined: Mon Feb 18, 2019 11:02 pm
Contact:

Re: Dear devs, can you share your patches for Lua?

Post by hhrhhr »

Thank you, I will study and understand.

Post Reply

Return to “Technical Help”