teal definitions cleanup

This commit is contained in:
BlackMATov
2025-11-07 23:26:45 +07:00
parent ecdbfe660f
commit 07902eb184
4 changed files with 90 additions and 73 deletions

View File

@@ -1,5 +1,5 @@
{
"[json][jsonc][lua][markdown][yaml]": {
"[json][jsonc][lua][markdown][teal][yaml]": {
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,

View File

@@ -60,6 +60,7 @@
- [Chunk](#chunk)
- [Builder](#builder)
- [Changelog](#changelog)
- [vX.X.X](#vxxx)
- [v1.4.0](#v140)
- [v1.3.0](#v130)
- [v1.2.0](#v120)
@@ -1305,6 +1306,10 @@ builder_mt:destruction_policy :: id -> builder
## Changelog
### vX.X.X
- Added basic [Teal](https://github.com/teal-language) type definitions, thanks to [@p0sel0k](https://github.com/p0sel0k)
### v1.4.0
- Improved query execution performance by caching some internal calculations
@@ -1944,7 +1949,7 @@ function evolved.builder_mt:internal() end
#### `evolved.builder_mt:default`
```lua
---@param default evolved.component
---@param default evolved.default
---@return evolved.builder builder
function evolved.builder_mt:default(default) end
```

View File

@@ -1,85 +1,90 @@
-- evolved.d.tl
-- evolve.lua ver.: 1.4
-- Teal declaration file for the public API of evolved.lua
local record Evolved
interface Id end
local record Evolved
type Entity = Id
type Fragment = Id
type Query = Id
type System = Id
record ID
end
interface EachState end
interface ExecuteState end
type Entity = ID
type Fragment = ID
type Query = ID
type System = ID
type Component = any
type EachIterator = function(state?: EachState): Fragment, any
type ExecuteIterator = function(state?: ExecuteState): Chunk, { Entity }, integer
type Storage = { Component }
record EachState
end
record ExecuteState
end
type EachIterator = function(state?: EachState): (Fragment, Component)
type ExecuteIterator = function(state?: ExecuteState): (Chunk, { Entity }, integer)
type Execute = function(chunk: Chunk, entity_list: { Entity }, entity_count: integer)
type Prologue = function()
type Epilogue = function()
type SetHook<T> = function(entity: Entity, fragment: Fragment, new: T, old?: T)
type AssignHook<T> = function(entity: Entity, fragment: Fragment, new: T, old?: T)
type InsertHook<T> = function(entity: Entity, fragment: Fragment, new: T)
type RemoveHook<T> = function(entity: Entity, fragment: Fragment, component: T)
record Chunk
interface Chunk
alive: function(self: Chunk): boolean
empty: function(self: Chunk): boolean
has: function(self: Chunk, fragment: Fragment): boolean
has_all: function(self: Chunk, ...: Fragment): boolean
has_any: function(self: Chunk, ...: Fragment): boolean
entities: function(self: Chunk): ({ Entity }, integer)
fragments: function(self: Chunk): ({ Fragment }, integer)
components: function(self: Chunk, ...: Fragment): Storage...
entities: function(self: Chunk): { Entity }, integer
fragments: function(self: Chunk): { Fragment }, integer
components: function(self: Chunk)
components: function<C1>(self: Chunk, f1: Fragment): { C1 }
components: function<C1, C2>(self: Chunk, f1: Fragment, f2: Fragment): { C1 }, { C2 }
components: function<C1, C2, C3>(self: Chunk, f1: Fragment, f2: Fragment, f3: Fragment): { C1 }, { C2 }, { C3 }
components: function<C1, C2, C3, C4>(self: Chunk, f1: Fragment, f2: Fragment, f3: Fragment, f4: Fragment): { C1 }, { C2 }, { C3 }, { C4 }
end
record Builder
interface Builder
build: function(self: Builder, prefab?: Entity): Entity
multi_build: function(self: Builder, entity_count: integer, prefab?: Entity): ({ Entity }, integer)
multi_build: function(self: Builder, entity_count: integer, prefab?: Entity): { Entity }, integer
spawn: function(self: Builder): Entity
multi_spawn: function(self: Builder, entity_count: integer): ({ Entity }, integer)
multi_spawn: function(self: Builder, entity_count: integer): { Entity }, integer
clone: function(self: Builder, prefab: Entity): Entity
multi_clone: function(self: Builder, entity_count: integer, prefab: Entity): ({ Entity }, integer)
multi_clone: function(self: Builder, entity_count: integer, prefab: Entity): { Entity }, integer
has: function(self: Builder, fragment: Fragment): boolean
has_all: function(self: Builder, ...: Fragment): boolean
has_any: function(self: Builder, ...: Fragment): boolean
get: function(self: Builder, ...: Fragment): Component...
set: function<T>(self: Builder, fragment: Fragment, component?: T): Builder
get: function(self: Builder)
get: function<C1>(self: Builder, f1: Fragment): C1 | nil
get: function<C1, C2>(self: Builder, f1: Fragment, f2: Fragment): C1 | nil, C2 | nil
get: function<C1, C2, C3>(self: Builder, f1: Fragment, f2: Fragment, f3: Fragment): C1 | nil, C2 | nil, C3 | nil
get: function<C1, C2, C3, C4>(self: Builder, f1: Fragment, f2: Fragment, f3: Fragment, f4: Fragment): C1 | nil, C2 | nil, C3 | nil, C4 | nil
set: function<Component>(self: Builder, fragment: Fragment, component?: Component): Builder
remove: function(self: Builder, ...: Fragment): Builder
clear: function(self: Builder): Builder
tag: function(self: Builder): Builder
name: function(self: Builder, name: string): Builder
unique: function(self: Builder): Builder
explicit: function(self: Builder): Builder
internal: function(self: Builder): Builder
default: function<T>(self: Builder, default: T): Builder
duplicate: function<T>(self: Builder, duplicate: function(T): T): Builder
default: function<Component>(self: Builder, default: Component): Builder
duplicate: function<Component>(self: Builder, duplicate: function(Component): Component): Builder
prefab: function(self: Builder): Builder
disabled: function(self: Builder): Builder
include: function(self: Builder, ...: Fragment): Builder
exclude: function(self: Builder, ...: Fragment): Builder
require: function(self: Builder, ...: Fragment): Builder
on_set: function<T>(self: Builder, on_set: SetHook<T>): Builder
on_assign: function<T>(self: Builder, on_assign: AssignHook<T>): Builder
on_insert: function<T>(self: Builder, on_insert: InsertHook<T>): Builder
on_remove: function<T>(self: Builder, on_remove: RemoveHook<T>): Builder
on_set: function<Component>(self: Builder, on_set: function(Entity, Fragment, ? Component, ? Component)): Builder
on_assign: function<Component>(self: Builder, on_assign: function(Entity, Fragment, ? Component, ? Component)): Builder
on_insert: function<Component>(self: Builder, on_insert: function(Entity, Fragment, ? Component)): Builder
on_remove: function<Component>(self: Builder, on_remove: function(Entity, Fragment, ? Component)): Builder
group: function(self: Builder, group: System): Builder
query: function(self: Builder, query: Query): Builder
execute: function(self: Builder, execute: Execute): Builder
prologue: function(self: Builder, prologue: Prologue): Builder
epilogue: function(self: Builder, epilogue: Epilogue): Builder
destruction_policy: function(self: Builder, policy: ID): Builder
execute: function(self: Builder, execute: function(Chunk, {Entity}, integer)): Builder
prologue: function(self: Builder, prologue: function()): Builder
epilogue: function(self: Builder, epilogue: function()): Builder
destruction_policy: function(self: Builder, destruction_policy: Id): Builder
end
TAG: Fragment
@@ -112,24 +117,24 @@ local record Evolved
EPILOGUE: Fragment
DESTRUCTION_POLICY: Fragment
DESTRUCTION_POLICY_DESTROY_ENTITY: ID
DESTRUCTION_POLICY_REMOVE_FRAGMENT: ID
DESTRUCTION_POLICY_DESTROY_ENTITY: Id
DESTRUCTION_POLICY_REMOVE_FRAGMENT: Id
id: function(count?: integer): ID...
name: function(...: ID): string...
id: function(count?: integer): Id...
name: function(...: Id): string...
pack: function(primary: integer, secondary: integer): ID
unpack: function(id: ID): (integer, integer)
pack: function(primary: integer, secondary: integer): Id
unpack: function(id: Id): integer, integer
defer: function(): boolean
commit: function(): boolean
cancel: function(): boolean
spawn: function(components?: { Fragment: Component }): Entity
multi_spawn: function(entity_count: integer, components?: { Fragment: Component }): ({ Entity }, integer)
spawn: function(components?: { Fragment: any }): Entity
multi_spawn: function(entity_count: integer, components?: { Fragment: any }): { Entity }, integer
clone: function(prefab: Entity, components?: { Fragment: Component }): Entity
multi_clone: function(entity_count: integer, prefab: Entity, components?: { Fragment: Component }): ({ Entity }, integer)
clone: function(prefab: Entity, components?: { Fragment: any }): Entity
multi_clone: function(entity_count: integer, prefab: Entity, components?: { Fragment: any }): { Entity }, integer
alive: function(entity: Entity): boolean
alive_all: function(...: Entity): boolean
@@ -143,26 +148,33 @@ local record Evolved
has_all: function(entity: Entity, ...: Fragment): boolean
has_any: function(entity: Entity, ...: Fragment): boolean
get: function(entity: Entity, ...: Fragment): Component...
set: function<T>(entity: Entity, fragment: Fragment, component?: T)
get: function(entity: Entity)
get: function<C1>(entity: Entity, f1: Fragment): C1 | nil
get: function<C1, C2>(entity: Entity, f1: Fragment, f2: Fragment): C1 | nil, C2 | nil
get: function<C1, C2, C3>(entity: Entity, f1: Fragment, f2: Fragment, f3: Fragment): C1 | nil, C2 | nil, C3 | nil
get: function<C1, C2, C3, C4>(entity: Entity, f1: Fragment, f2: Fragment, f3: Fragment, f4: Fragment): C1 | nil, C2 | nil, C3 | nil, C4 | nil
set: function<Component>(entity: Entity, fragment: Fragment, component?: Component)
remove: function(entity: Entity, ...: Fragment)
clear: function(...: Entity)
destroy: function(...: Entity)
batch_set: function<T>(query: Query, fragment: Fragment, component?: T)
batch_set: function<Component>(query: Query, fragment: Fragment, component?: Component)
batch_remove: function(query: Query, ...: Fragment)
batch_clear: function(...: Query)
batch_destroy: function(...: Query)
each: function(entity: Entity): (EachIterator, EachState)
execute: function(query: Query): (ExecuteIterator, ExecuteState)
locate: function(entity: Entity): (Chunk, integer)
each: function(entity: Entity): EachIterator, EachState | nil
execute: function(query: Query): ExecuteIterator, ExecuteState | nil
locate: function(entity: Entity): Chunk | nil, integer
process: function(...: System)
debug_mode: function(yesno: boolean)
collect_garbage: function()
chunk: function(fragment: Fragment, ...: Fragment): (Chunk, { Entity }, integer)
chunk: function(fragment: Fragment, ...: Fragment): Chunk, { Entity }, integer
builder: function(): Builder
end

View File

@@ -52,7 +52,7 @@ local evolved = {
--- entity: evolved.entity,
--- fragment: evolved.fragment,
--- new_component: evolved.component,
--- old_component?: evolved.component)
--- old_component: evolved.component)
---@alias evolved.assign_hook fun(
--- entity: evolved.entity,
@@ -68,7 +68,7 @@ local evolved = {
---@alias evolved.remove_hook fun(
--- entity: evolved.entity,
--- fragment: evolved.fragment,
--- component: evolved.component)
--- old_component: evolved.component)
---@class (exact) evolved.each_state
---@field package [1] integer structural_changes
@@ -6183,7 +6183,7 @@ function __builder_mt:internal()
return self:set(__INTERNAL)
end
---@param default evolved.component
---@param default evolved.default
---@return evolved.builder builder
function __builder_mt:default(default)
return self:set(__DEFAULT, default)