added the new evolved.depth function

This commit is contained in:
BlackMATov
2025-12-28 06:36:11 +07:00
parent 72fc524fe0
commit 723a65ca7f
6 changed files with 117 additions and 11 deletions

27
.vscode/launch.json vendored
View File

@@ -10,6 +10,24 @@
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.2)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.2",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.3)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.3",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.4)",
"type": "lua-local",
@@ -19,6 +37,15 @@
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (lua5.5)",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.5",
"file": "${workspaceFolder}/develop/all.lua"
}
},
{
"name": "Launch Evolved All (luajit)",
"type": "lua-local",

View File

@@ -644,6 +644,10 @@ Now we know that structural changes are not allowed during iteration, but what i
---@return boolean started
function evolved.defer() end
---@return integer depth
---@nodiscard
function evolved.depth() end
---@return boolean committed
function evolved.commit() end
@@ -651,7 +655,7 @@ function evolved.commit() end
function evolved.cancel() end
```
The [`evolved.defer`](#evolveddefer) function starts a deferred scope. This means that all changes made inside the scope will be queued and applied after leaving the scope. The [`evolved.commit`](#evolvedcommit) function closes the last deferred scope and applies all queued changes. These functions can be nested, so you can start a new deferred scope inside an existing one. The [`evolved.commit`](#evolvedcommit) function will apply all queued changes only when the last deferred scope is closed.
The [`evolved.defer`](#evolveddefer) function starts a deferred scope. This means that all changes made inside the scope will be queued and applied after leaving the scope. The [`evolved.commit`](#evolvedcommit) function closes the last deferred scope and applies all queued changes. These functions can be nested, so you can start a new deferred scope inside an existing one. The [`evolved.commit`](#evolvedcommit) function will apply all queued changes only when the last deferred scope is closed. The [`evolved.depth`](#evolveddepth) function returns the current depth of deferred scopes. If there are no deferred scopes, it returns `0`.
```lua
local evolved = require 'evolved'
@@ -1185,6 +1189,7 @@ pack :: integer, integer -> id
unpack :: id -> integer, integer
defer :: boolean
depth :: integer
commit :: boolean
cancel :: boolean
@@ -1310,6 +1315,7 @@ builder_mt:destruction_policy :: id -> builder
### vX.X.X
- Significant performance improvements of the [`evolved.REQUIRES`](#evolvedrequires) fragment trait
- Added the new [`evolved.depth`](#evolveddepth) function that returns the current depth of deferred scopes
### v1.5.0
@@ -1451,6 +1457,14 @@ function evolved.unpack(id) end
function evolved.defer() end
```
### `evolved.depth`
```lua
---@return integer depth
---@nodiscard
function evolved.depth() end
```
### `evolved.commit`
```lua

View File

@@ -9,8 +9,7 @@
## Thoughts
- We can return deferred status from modifying operations and spawn/clone methods.
- We should have a way to not copy components on deferred spawn/clone.
- We should have a way to not copy components on deferred spawn/clone
## Known Issues

View File

@@ -1,6 +1,7 @@
require 'develop.testing.build_tests'
require 'develop.testing.cancel_tests'
require 'develop.testing.clone_tests'
require 'develop.testing.depth_tests'
require 'develop.testing.destroy_tests'
require 'develop.testing.locate_tests'
require 'develop.testing.main_tests'

View File

@@ -0,0 +1,65 @@
local evo = require 'evolved'
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.cancel())
assert(evo.depth() == 1)
assert(evo.cancel())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.commit())
assert(evo.depth() == 1)
assert(evo.commit())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.cancel())
assert(evo.depth() == 1)
assert(evo.commit())
assert(evo.depth() == 0)
end
do
assert(evo.depth() == 0)
assert(evo.defer())
assert(evo.depth() == 1)
assert(not evo.defer())
assert(evo.depth() == 2)
assert(not evo.commit())
assert(evo.depth() == 1)
assert(evo.cancel())
assert(evo.depth() == 0)
end

View File

@@ -800,6 +800,7 @@ local __evolved_pack
local __evolved_unpack
local __evolved_defer
local __evolved_depth
local __evolved_commit
local __evolved_cancel
@@ -2750,10 +2751,6 @@ function __chunk_set(old_chunk, fragment, component)
local new_chunk = __chunk_with_fragment(old_chunk, fragment)
if not new_chunk then
return
end
if old_chunk == new_chunk then
local old_chunk_has_setup_hooks = old_chunk.__has_setup_hooks
local old_chunk_has_assign_hooks = old_chunk.__has_assign_hooks
@@ -3854,6 +3851,12 @@ function __evolved_defer()
return __defer_depth == 1
end
---@return integer depth
---@nodiscard
function __evolved_depth()
return __defer_depth
end
---@return boolean committed
function __evolved_commit()
if __defer_depth <= 0 then
@@ -4297,10 +4300,6 @@ function __evolved_set(entity, fragment, component)
local new_chunk = __chunk_with_fragment(old_chunk, fragment)
if not new_chunk then
return
end
__evolved_defer()
if old_chunk == new_chunk then
@@ -6298,6 +6297,7 @@ evolved.pack = __evolved_pack
evolved.unpack = __evolved_unpack
evolved.defer = __evolved_defer
evolved.depth = __evolved_depth
evolved.commit = __evolved_commit
evolved.cancel = __evolved_cancel