mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
Merge branch 'feature/pairs' into dev
This commit is contained in:
14
README.md
14
README.md
@@ -147,16 +147,15 @@ function evolved.alive_any(...) end
|
|||||||
Sometimes (for debugging purposes, for example), it is necessary to extract the index and version from an identifier or to pack them back into an identifier. The [`evolved.pack`](#evolvedpack) and [`evolved.unpack`](#evolvedunpack) functions can be used for this purpose.
|
Sometimes (for debugging purposes, for example), it is necessary to extract the index and version from an identifier or to pack them back into an identifier. The [`evolved.pack`](#evolvedpack) and [`evolved.unpack`](#evolvedunpack) functions can be used for this purpose.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
---@param primary integer
|
---@param index integer
|
||||||
---@param secondary integer
|
---@param version integer
|
||||||
---@return evolved.id id
|
---@return evolved.id id
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function evolved.pack(primary, secondary) end
|
function evolved.pack(index, version) end
|
||||||
|
|
||||||
---@param id evolved.id
|
---@param id evolved.id
|
||||||
---@return integer primary
|
---@return integer primary
|
||||||
---@return integer secondary
|
---@return integer secondary
|
||||||
---@return integer options
|
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function evolved.unpack(id) end
|
function evolved.unpack(id) end
|
||||||
```
|
```
|
||||||
@@ -1304,11 +1303,11 @@ function evolved.name(...) end
|
|||||||
### `evolved.pack`
|
### `evolved.pack`
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
---@param primary integer
|
---@param index integer
|
||||||
---@param secondary integer
|
---@param version integer
|
||||||
---@return evolved.id id
|
---@return evolved.id id
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function evolved.pack(primary, secondary) end
|
function evolved.pack(index, version) end
|
||||||
```
|
```
|
||||||
|
|
||||||
### `evolved.unpack`
|
### `evolved.unpack`
|
||||||
@@ -1317,7 +1316,6 @@ function evolved.pack(primary, secondary) end
|
|||||||
---@param id evolved.id
|
---@param id evolved.id
|
||||||
---@return integer primary
|
---@return integer primary
|
||||||
---@return integer secondary
|
---@return integer secondary
|
||||||
---@return integer options
|
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function evolved.unpack(id) end
|
function evolved.unpack(id) end
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -13,21 +13,8 @@ for _ = 1, 1000 do
|
|||||||
local initial_secondary = math.random(1, 2 ^ 20 - 1)
|
local initial_secondary = math.random(1, 2 ^ 20 - 1)
|
||||||
|
|
||||||
local packed_id = evo.pack(initial_primary, initial_secondary)
|
local packed_id = evo.pack(initial_primary, initial_secondary)
|
||||||
local unpacked_primary, unpacked_secondary, unpacked_options = evo.unpack(packed_id)
|
local unpacked_primary, unpacked_secondary = evo.unpack(packed_id)
|
||||||
|
|
||||||
assert(initial_primary == unpacked_primary)
|
assert(initial_primary == unpacked_primary)
|
||||||
assert(initial_secondary == unpacked_secondary)
|
assert(initial_secondary == unpacked_secondary)
|
||||||
assert(0 == unpacked_options)
|
|
||||||
end
|
|
||||||
|
|
||||||
for _ = 1, 1000 do
|
|
||||||
local initial_primary = math.random(1, 2 ^ 31 - 1)
|
|
||||||
local initial_secondary = math.random(1, 2 ^ 31 - 1)
|
|
||||||
|
|
||||||
local packed_id = evo.pack(initial_primary, initial_secondary)
|
|
||||||
local unpacked_primary, unpacked_secondary, unpacked_options = evo.unpack(packed_id)
|
|
||||||
|
|
||||||
assert(initial_primary % 2 ^ 20 == unpacked_primary)
|
|
||||||
assert(initial_secondary % 2 ^ 20 == unpacked_secondary)
|
|
||||||
assert(0 == unpacked_options)
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ local evo = require 'evolved'
|
|||||||
do
|
do
|
||||||
local id = evo.id()
|
local id = evo.id()
|
||||||
|
|
||||||
local index, version, options = evo.unpack(id)
|
local index, version = evo.unpack(id)
|
||||||
assert(evo.name(id) == string.format('$%d#%d:%d:%d', id, index, version, options))
|
assert(evo.name(id) == string.format('$%d#%d:%d', id, index, version))
|
||||||
|
|
||||||
evo.set(id, evo.NAME, 'hello')
|
evo.set(id, evo.NAME, 'hello')
|
||||||
assert(evo.name(id) == 'hello')
|
assert(evo.name(id) == 'hello')
|
||||||
@@ -13,7 +13,7 @@ do
|
|||||||
assert(evo.name(id) == 'world')
|
assert(evo.name(id) == 'world')
|
||||||
|
|
||||||
evo.destroy(id)
|
evo.destroy(id)
|
||||||
assert(evo.name(id) == string.format('$%d#%d:%d:%d', id, index, version, options))
|
assert(evo.name(id) == string.format('$%d#%d:%d', id, index, version))
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
448
evolved.lua
448
evolved.lua
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user