Working commit
This commit is contained in:
@@ -1,29 +1,28 @@
|
||||
use luaffi::{cdef, metatype};
|
||||
use luajit::State;
|
||||
use owo_colors::OwoColorize;
|
||||
use std::{cell::RefCell, fmt, process};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GlobalState(State);
|
||||
pub struct GlobalState(luajit::State);
|
||||
|
||||
impl GlobalState {
|
||||
thread_local! {
|
||||
static STATE: RefCell<Option<GlobalState>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn set(state: State) -> Option<State> {
|
||||
pub fn set(state: luajit::State) -> Option<luajit::State> {
|
||||
Self::STATE.with_borrow_mut(|s| s.replace(Self(state)).map(|s| s.0))
|
||||
}
|
||||
|
||||
pub fn with_current<T>(f: impl FnOnce(&State) -> T) -> T {
|
||||
pub fn with_current<T>(f: impl FnOnce(&luajit::State) -> T) -> T {
|
||||
Self::STATE.with_borrow(|s| f(&s.as_ref().expect("lua state not initialised").0))
|
||||
}
|
||||
|
||||
pub fn with_current_mut<T>(f: impl FnOnce(&mut State) -> T) -> T {
|
||||
pub fn with_current_mut<T>(f: impl FnOnce(&mut luajit::State) -> T) -> T {
|
||||
Self::STATE.with_borrow_mut(|s| f(&mut s.as_mut().expect("lua state not initialised").0))
|
||||
}
|
||||
|
||||
pub fn new_thread() -> State {
|
||||
pub fn new_thread() -> luajit::State {
|
||||
Self::with_current(|s| s.new_thread())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user