Skip to content

Commit

Permalink
Export LuauThread
Browse files Browse the repository at this point in the history
  • Loading branch information
bjcscat committed Dec 16, 2024
1 parent e69f30f commit c17dbb8
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use ffi::{
prelude::*,
};
use memory::{luau_alloc_cb, DefaultLuauAllocator};
use threads::LuauThread;
use userdata::{
drop_userdata, dtor_rs_luau_userdata_callback, Userdata, UserdataBorrowError, UserdataRef,
UserdataRefMut, UD_TAG,
Expand All @@ -35,6 +34,7 @@ use userdata::{
pub use ffi::prelude::LuauStatus;
pub use libs::LuauLibs;
pub use memory::LuauAllocator;
pub use threads::LuauThread;

macro_rules! luau_stack_precondition {
($cond:expr) => {
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Luau {
luau_stack_precondition!(self.check_index(-1));

// SAFETY: a value on the top of the stack exists as verified by the precondition
unsafe {lua_error(self.state)}
unsafe { lua_error(self.state) }
}

/// Returns the type of a luau value at `idx`
Expand Down Expand Up @@ -985,10 +985,8 @@ impl Luau {
}

/// Returns the thread local userdata
pub fn get_thread_data<T: Any>(&self) -> Option<&T> {
let boxed = unsafe {
(lua_getthreaddata(self.state) as *const Box<dyn Any>).as_ref()?
};
pub fn get_thread_data<T: Any>(&self) -> Option<&T> {
let boxed = unsafe { (lua_getthreaddata(self.state) as *const Box<dyn Any>).as_ref()? };

boxed.downcast_ref()
}
Expand Down Expand Up @@ -1266,12 +1264,10 @@ impl Drop for Luau {

#[macro_export]
macro_rules! try_luau {
($state:ident, $block:block) => {
{
$state.push_function(|$state| $block, Some("_try_lua"), 0);
$state.call(0, 0)
}
};
($state:ident, $block:block) => {{
$state.push_function(|$state| $block, Some("_try_lua"), 0);
$state.call(0, 0)
}};
}

#[cfg(test)]
Expand Down Expand Up @@ -1300,7 +1296,10 @@ mod tests {
luau.error()
});

assert!(matches!(status, LuauStatus::LUA_ERRRUN), "Expected a runtime error");
assert!(
matches!(status, LuauStatus::LUA_ERRRUN),
"Expected a runtime error"
);
assert!(luau.to_boolean(-1), "Expected the boolean to be true");
}

Expand Down Expand Up @@ -1380,7 +1379,6 @@ mod tests {
assert_eq!(luau.type_of(-1), LuauType::LUA_TFUNCTION);
}


#[test]
fn tables() {
let luau = Luau::default();
Expand Down

0 comments on commit c17dbb8

Please sign in to comment.