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