[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: what is the role of the `seed` field in the Lua global state?
- From: 云风 <cloudwu@...>
- Date: Thu, 12 Mar 2020 23:03:21 +0800
> 在 2020年3月12日，22:39，Luiz Henrique de Figueiredo <firstname.lastname@example.org> 写道：
>> Is there any way to specify a seed when I create a new lua VM ? It's
>> very useful for reproduction of bugs .
>> If the seed is always random, the order of table iteration would be
>> different every time.
> Setting the seed is not enough to ensure reproduction of execution: if
> your table contains functions or userdata as keys, then the order is
> undefined because Lua uses memory addresses to compute key hashes when
> keys are functions and userdata.
I can use my own lua_Alloc to manage the memory addresses. For example, map a fixed virtual address space as the memory heap.
On the other hand, avoiding to use userdata or functions as the key is easy, but strings are always used as the keys.
The point is that we can find a way to reduce that uncertainty, but the seed of lua vm is random generated . It’s out of control :(