Add doc comments for Entity.get / getRef / getMut

main
copygirl 3 months ago
parent 1c44cf61c7
commit 5273084f99
  1. 18
      src/entity.zig

@ -301,16 +301,34 @@ pub fn Entity(comptime ctx: anytype) type {
c.ecs_remove_id(self.world.raw, self.raw, ecs_id);
}
/// Gets a value copy of a component.
/// If the component does not exist, returns null.
pub fn get(self: Self, comptime T: type) ?T {
return if (getRef(self, T)) |p| p.* else null;
}
/// Gets an immutable pointer to a component.
/// If the component does not exist, returns null.
///
/// The returned pointer may become invalid after calling other Flecs
/// functions, notably when an `Entity` moves to another table caused
/// by adding or removing other components.
pub fn getRef(self: Self, comptime T: type) ?*const T {
const id = Context.lookup(T).*;
const ptr = c.ecs_get_id(self.world.raw, self.raw, id);
return @alignCast(@ptrCast(ptr));
}
/// Get a mutable pointer to a component.
/// If the component did not yet exist, it will be added.
///
/// The returned pointer may become invalid after calling other Flecs
/// functions, notably when an `Entity` moves to another table caused
/// by adding or removing other components.
///
/// If `getMut` is called when the world is in deferred / readonly
/// mode, and the component does not yet exist, it will return a
/// pointer to a temp storage.
pub fn getMut(self: Self, comptime T: type) *T {
const id = Context.lookup(T).*;
const ptr = c.ecs_get_mut_id(self.world.raw, self.raw, id);

Loading…
Cancel
Save