Skip to content

feat(ladfile): type the asset functions of world by the asset type - #670

Open
makspll wants to merge 3 commits into
agent/lad-generic-function-signaturesfrom
agent/lad-generic-asset-functions
Open

makspll wants to merge 3 commits into
agent/lad-generic-function-signaturesfrom
agent/lad-generic-asset-functions

Conversation

@makspll

@makspll makspll commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Stacked on #668.

The asset functions of world are typed by the asset type, with the TypeOf / ValueOf wrappers of #668 and the declared Handle<A>:

fn load_asset(ctxt, path: String, asset_type: TypeOf<V<ScriptTypeRegistration>, A>) -> Result<ValueOf<Handle<A>>, InteropError>
fn get_asset(ctxt, handle: ValueOf<Handle<A>>, registration: TypeOf<V<ScriptTypeRegistration>, A>) -> Result<Option<ValueOf<A>>, InteropError>
fn add_asset(ctxt, value: ValueOf<A>) -> Result<ValueOf<Handle<A>>, InteropError>
// has_asset, is_loaded, load_state, asset_path take a `ValueOf<Handle<A>>`

In the LAD file the handle is Handle applied to the parameter, { "val": { "generic_type": "bevy_asset::handle::Handle", "args": [{ "val": { "param": "A" } }] } }, and isn't recorded as an instantiation of Handle.

Lua

---@generic A
---@param path string
---@param asset_type A
---@overload fun(path: string, asset_type: bms.ScriptTypeRegistration): ReflectReference
---@return asset.Handle<A>
function World.load_asset(path, asset_type) end

Generic functions now get the untyped overload whenever an argument uses a parameter, not only for type arguments, so an untyped handle (a ReflectReference) can still be passed to is_loaded. Values of a type applied to a parameter, like Handle<A>, are references in the overload.

Checked with LuaLS 3.19.2:

Expression Inferred
world.load_asset("image.png", Image) asset.Handle<render.Image>
world.get_asset(handle, Image) render.Image?
world.add_asset(image) (image: render.Image) ReflectReference | asset.Handle<render.Image> (merged with the overload)
world.is_loaded(untyped) (untyped: ReflectReference) boolean

The typed Image.load(path) / Image.get_asset(handle) of each asset type were already typed and are unchanged.

`load_asset`, `get_asset`, `add_asset`, `has_asset`, `is_loaded`, `load_state` and `asset_path` take or return
`ValueOf<Handle<A>>`, so the handle's asset type flows through them in Lua. Generic functions get an untyped overload
whenever an argument uses a parameter, as an untyped handle is passed as a reference.
@semanticdiff-com

semanticdiff-com Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

…eneric-asset-functions

# Conflicts:
#	crates/lad_backends/lua_language_server_lad_backend/src/convert/generics.rs
#	crates/ladfile_builder/src/plugin.rs
#	docs/src/ReleaseNotes/0.23-to-0.24.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant