lyra-engine/lyra-scripting/src/world.rs

46 lines
945 B
Rust
Raw Normal View History

2024-01-05 01:52:47 +00:00
use std::ptr::NonNull;
use lyra_ecs::{World, Entity};
2024-01-05 01:52:47 +00:00
#[derive(Clone)]
pub struct ScriptEntity(pub Entity);
impl std::ops::Deref for ScriptEntity {
type Target = Entity;
fn deref(&self) -> &Self::Target {
&self.0
}
}
2024-01-05 01:52:47 +00:00
#[derive(Clone)]
pub struct ScriptWorldPtr {
pub inner: NonNull<World>,
}
impl ScriptWorldPtr {
/// Creates a world pointer from a world borrow.
pub fn from_ref(world: &World) -> Self {
Self {
inner: NonNull::from(world),
}
}
/// Returns a borrow to the world from the ptr.
pub fn as_ref(&self) -> &World {
unsafe { self.inner.as_ref() }
}
/// Returns a mutable borrow to the world from the ptr.
pub fn as_mut(&mut self) -> &mut World {
unsafe { self.inner.as_mut() }
}
}
impl std::ops::Deref for ScriptWorldPtr {
type Target = NonNull<World>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}