lua: write lua annotations for all queries and view one
CI / build (pull_request) Failing after 3m6s Details

This commit is contained in:
SeanOMik 2024-10-29 23:04:00 -04:00
parent 0e613bd216
commit 076676e486
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
11 changed files with 163 additions and 9 deletions

View File

@ -104,9 +104,10 @@ function on_update()
end
local pos_view = View.new(Transform)
local vone = world:view_one(cube_entity, pos_view)
local r = vone()
if r ~= nil then
local vone = world:view_one(cube_entity --[[@as Entity]], pos_view)
local r = vone() -- short hand for 'vone:get()'
if r then
---@type Transform
local pos = r[1]
print("Found cube entity at '" .. tostring(pos) .. "'")
end

View File

@ -38,14 +38,15 @@ function Not(val)
return NotQuery.new(val)
end
---Create a `OrQuery` filter that will allow results if any of the queries return something.
---Create a `AnyQuery` filter that will allow results if any of the queries return something.
---
---The queries are evaluated in the order they were provided.
---
---@see OrQuery
---@see AnyQuery
---@param ... Query
---@return OrQuery
function Or(...)
return OrQuery.new(...)
---@return AnyQuery
function Any(...)
return AnyQuery.new(...)
end
---Create a `TickOfQuery` for retrieving the tick of the resource or component on the entity.

View File

@ -0,0 +1,25 @@
---@meta
---An ECS filter that will return if any of the provided queries return.
---
---The queries are evaluated in the order they were provided. When a query or filter returns a value,
---that value will be returned.
---
---Use the utility function `Any(...)` to create a new query since its faster to
---write than this.
---
---@see Any
---@class AnyQuery: userdata
AnyQuery = {}
---Create a new AnyQuery.
---
---Use the utility function `Any(...)` to create a new query since its faster to
---write than this.
---
---@see Any
---@param ... Query The query to invert.
function AnyQuery:new(...) end
---An internal function used by the engine to retrieve the query result.
function AnyQuery:__lyra_internal_ecs_query_result(world, entity) end

View File

@ -0,0 +1,22 @@
---@meta
---An ECS filter that allows the query if the entity has the Component.
---
---Use the utility function `Has(...)` to create a new query since its faster to
---write than this.
---
---@see Has
---@class HasQuery: userdata
HasQuery = {}
---Create a new HasQuery.
---
---Use the utility function `Has(...)` to create a new query since its faster to
---write than this.
---
---@see Has
---@param val table|userdata The component to look for on the entity.
function HasQuery:new(val) end
---An internal function used by the engine to retrieve the query result.
function HasQuery:__lyra_internal_ecs_query_result(world, entity) end

View File

@ -1,3 +1,9 @@
require "view"
require "view_one"
require "changed"
require "res"
require "has"
require "any"
require "not"
require "optional"
require "tick_of"

View File

@ -0,0 +1,22 @@
---@meta
---An ECS filter that inverts the provided filter/query result.
---
---Use the utility function `Not(...)` to create a new query since its faster to
---write than this.
---
---@see Not
---@class NotQuery: userdata
NotQuery = {}
---Create a new NotQuery.
---
---Use the utility function `Not(...)` to create a new query since its faster to
---write than this.
---
---@see Not
---@param val Query The query to invert.
function NotQuery:new(val) end
---An internal function used by the engine to retrieve the query result.
function NotQuery:__lyra_internal_ecs_query_result(world, entity) end

View File

@ -0,0 +1,26 @@
---@meta
---An ECS query that ignores filters and queries that dont return anything.
---
---If the provided query returns nothing, this query will provide a `nil` value.
---The results of filters are essentially ignored, since it doesn't matter the result, this query
---will return. If the provided query has a result, this query will also return it.
---
---Use the utility function `Optional(...)` to create a new query since its faster to
---write than this.
---
---@see Optional
---@class OptionalQuery: userdata
OptionalQuery = {}
---Create a new OptionalQuery.
---
---Use the utility function `Optional(...)` to create a new query since its faster to
---write than this.
---
---@see Optional
---@param val Query The query to invert.
function OptionalQuery:new(val) end
---An internal function used by the engine to retrieve the query result.
function OptionalQuery:__lyra_internal_ecs_query_result(world, entity) end

View File

@ -0,0 +1,22 @@
---@meta
---An ECS query that returns the tick of the resource or component provided.
---
---Use the utility function `TickOf(...)` to create a new query since its faster to
---write than this.
---
---@see TickOf
---@class TickOfQuery: userdata
TickOfQuery = {}
---Create a new TickOfQuery.
---
---Use the utility function `TickOf(...)` to create a new query since its faster to
---write than this.
---
---@see TickOf
---@param val table|userdata The component or resource to retrieve the tick of.
function TickOfQuery:new(val) end
---An internal function used by the engine to retrieve the query result.
function TickOfQuery:__lyra_internal_ecs_query_result(world, entity) end

View File

@ -0,0 +1,19 @@
---@meta
---Results of a View over a single entity.
---@class ViewOneResult: userdata
ViewOneResult = {}
---Returns the results of the view over a single entity.
---
---@see ViewOneResult.__call
---@generic T...
---@return T...
function ViewOneResult:get() end
---Returns the results of the view over a single entity.
---
---@see ViewOneResult.get
---@generic T...
---@return T...
function ViewOneResult:__call() end

View File

@ -95,6 +95,15 @@ function World:read_event(event) end
---@return ViewResult
function World:view_query(view) end
---View a single entity in the world.
---
---The view can contain queries and filters, but they will only be evaluated for a single entity.
---
---@param en Entity
---@param view View
---@return ViewOneResult
function World:view_one(en, view) end
--World global
---@type World
world = nil

View File

@ -45,11 +45,12 @@ impl ScriptApiProvider for LyraEcsApiProvider {
globals.set("ActionHandler", ctx.create_proxy::<LuaActionHandler>()?)?;
globals.set("Window", ctx.create_proxy::<LuaWindow>()?)?;
globals.set("View", ctx.create_proxy::<View>()?)?;
globals.set("ResQuery", ctx.create_proxy::<LuaResQuery>()?)?;
globals.set("ChangedQuery", ctx.create_proxy::<LuaChangedQuery>()?)?;
globals.set("HasQuery", ctx.create_proxy::<LuaHasQuery>()?)?;
globals.set("NotQuery", ctx.create_proxy::<LuaNotQuery>()?)?;
globals.set("OrQuery", ctx.create_proxy::<LuaOrQuery>()?)?;
globals.set("AnyQuery", ctx.create_proxy::<LuaOrQuery>()?)?;
globals.set("TickOfQuery", ctx.create_proxy::<LuaTickOfQuery>()?)?;
globals.set("OptionalQuery", ctx.create_proxy::<LuaOptionalQuery>()?)?;