mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-13 03:29:08 +07:00
non-jit lua compatibility
This commit is contained in:
@@ -142,8 +142,8 @@ for _ = 1, 100 do
|
||||
end
|
||||
|
||||
assert(e1.chunk == e2.chunk)
|
||||
assert(evo.registry.has_all(e1, unpack(insert_fragments)))
|
||||
assert(evo.registry.has_all(e2, unpack(insert_fragments)))
|
||||
assert(evo.registry.has_all(e1, evo.compat.unpack(insert_fragments)))
|
||||
assert(evo.registry.has_all(e2, evo.compat.unpack(insert_fragments)))
|
||||
|
||||
shuffle_array(remove_fragments)
|
||||
for _, f in ipairs(remove_fragments) do
|
||||
@@ -160,8 +160,8 @@ for _ = 1, 100 do
|
||||
end
|
||||
|
||||
assert(e1.chunk == e2.chunk)
|
||||
assert(not evo.registry.has_any(e1, unpack(remove_fragments)))
|
||||
assert(not evo.registry.has_any(e2, unpack(remove_fragments)))
|
||||
assert(not evo.registry.has_any(e1, evo.compat.unpack(remove_fragments)))
|
||||
assert(not evo.registry.has_any(e2, evo.compat.unpack(remove_fragments)))
|
||||
|
||||
if e1.chunk ~= nil then
|
||||
for f, _ in pairs(e1.chunk.components) do
|
||||
|
||||
6
evolved/compat.lua
Normal file
6
evolved/compat.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
---@class evolved.compat
|
||||
local compat = {}
|
||||
|
||||
compat.unpack = unpack or table.unpack
|
||||
|
||||
return compat
|
||||
@@ -1,4 +1,5 @@
|
||||
return {
|
||||
compat = require 'evolved.compat',
|
||||
idpools = require 'evolved.idpools',
|
||||
registry = require 'evolved.registry',
|
||||
singles = require 'evolved.singles',
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
local bit = require 'bit'
|
||||
|
||||
---@class evolved.idpools
|
||||
local idpools = {}
|
||||
|
||||
@@ -23,7 +21,9 @@ end
|
||||
---@return integer index
|
||||
---@return integer version
|
||||
function idpools.unpack_id(id)
|
||||
return bit.band(id, 0xFFFFF), bit.rshift(id, 20)
|
||||
local index = id % 0x100000
|
||||
local version = (id - index) / 0x100000
|
||||
return index, version
|
||||
end
|
||||
|
||||
---@param idpool evolved.idpool
|
||||
@@ -32,26 +32,30 @@ end
|
||||
function idpools.acquire_id(idpool)
|
||||
if idpool.available_index ~= 0 then
|
||||
local index = idpool.available_index
|
||||
local version = bit.band(idpool.acquired_ids[index], 0x7FF00000)
|
||||
idpool.available_index = bit.band(idpool.acquired_ids[index], 0xFFFFF)
|
||||
idpool.acquired_ids[index] = index + version
|
||||
return idpool.acquired_ids[index]
|
||||
local available_id = idpool.acquired_ids[index]
|
||||
idpool.available_index = available_id % 0x100000
|
||||
local version = available_id - idpool.available_index
|
||||
local acquired_id = index + version
|
||||
idpool.acquired_ids[index] = acquired_id
|
||||
return acquired_id
|
||||
end
|
||||
|
||||
if #idpool.acquired_ids == 0xFFFFF then
|
||||
error('id index overflow', 2)
|
||||
end
|
||||
|
||||
local index, version = #idpool.acquired_ids + 1, 0x100000
|
||||
idpool.acquired_ids[index] = index + version
|
||||
return idpool.acquired_ids[index]
|
||||
local index = #idpool.acquired_ids + 1
|
||||
local version = 0x100000
|
||||
local acquired_id = index + version
|
||||
idpool.acquired_ids[index] = acquired_id
|
||||
return acquired_id
|
||||
end
|
||||
|
||||
---@param idpool evolved.idpool
|
||||
---@param id integer
|
||||
function idpools.release_id(idpool, id)
|
||||
local index = bit.band(id, 0xFFFFF)
|
||||
local version = bit.band(id, 0x7FF00000)
|
||||
local index = id % 0x100000
|
||||
local version = id - index
|
||||
|
||||
if idpool.acquired_ids[index] ~= id then
|
||||
error('id is not acquired or already released', 2)
|
||||
@@ -70,7 +74,7 @@ end
|
||||
---@return boolean
|
||||
---@nodiscard
|
||||
function idpools.is_id_alive(idpool, id)
|
||||
local index = bit.band(id, 0xFFFFF)
|
||||
local index = id % 0x100000
|
||||
return idpool.acquired_ids[index] == id
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local compat = require 'evolved.compat'
|
||||
local idpools = require 'evolved.idpools'
|
||||
|
||||
---@class evolved.registry
|
||||
@@ -452,7 +453,7 @@ function registry.execute(query)
|
||||
local matched_chunk_stack = {}
|
||||
|
||||
for _, main_fragment_chunk in ipairs(main_fragment_chunks) do
|
||||
if __chunk_has_all_fragments(main_fragment_chunk, unpack(query.fragments)) then
|
||||
if __chunk_has_all_fragments(main_fragment_chunk, compat.unpack(query.fragments)) then
|
||||
matched_chunk_stack[#matched_chunk_stack + 1] = main_fragment_chunk
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user