Skip to content

Commit

Permalink
improve sqobjects in sq api
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Aug 29, 2024
1 parent 1c8e401 commit fded3d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/high/squirrel_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ pub trait GetFromSquirrelVm: Sized {
/// this is only for certain internal apis
///
/// don't use this only for internal apis
#[doc(hidden)]
#[inline]
fn get_from_sqvm_internal(
sqvm: NonNull<HSquirrelVM>,
sqfunctions: &'static SquirrelFunctions,
Expand Down Expand Up @@ -474,6 +476,29 @@ impl GetFromSQObject for Vector3 {
}
}

impl GetFromSQObject for SQObject {
#[inline]
fn get_from_sqobject(obj: &SQObject) -> Self {
*obj
}
}

impl<T: IsSQObject> GetFromSQObject for SQHandle<T> {
#[inline]
fn get_from_sqobject(obj: &SQObject) -> Self {
match Self::try_new(*obj) {
Ok(handle) => handle,
Err(_) => {
panic!(
"the object wasn't the correct type got {:X} expected {}",
obj._Type as i32,
std::any::type_name::<T>()
);
}
}
}
}

impl<T: IntoSquirrelArgs> GetFromSQObject for SquirrelFn<T> {
#[inline]
fn get_from_sqobject(obj: &SQObject) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion src/mid/source_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SourceAlloc {
///
/// the source allocator has more functions which may be useful
pub fn get_underlying_alloc(&self) -> &'static IMemAlloc {
self.0.wait().get()
unsafe { self.0.get_unchecked().get() } // should be init
}
}

Expand Down

0 comments on commit fded3d4

Please sign in to comment.