38 lines
821 B
Rust
38 lines
821 B
Rust
|
use std::ptr::NonNull;
|
||
|
|
||
|
use lyra_ecs::{world::World, Entity};
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct ScriptEntity(pub Entity);
|
||
|
|
||
|
#[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
|
||
|
}
|
||
|
}
|