#![allow(unused)]
mod import;
use std::cell::Cell;
pub use import::*;
mod lua_state;
pub use lua_state::LuaState as State;
mod push;
pub use push::*;
mod returns;
pub use returns::ValuesReturned;
mod raw_bind;
#[derive(Debug, Clone)]
pub enum LuaError {
MemoryAllocationError,
SyntaxError(Option<String>),
FileError(Option<String>),
RuntimeError(Option<String>),
ErrorHandlerError,
Unknown(i32),
}
#[macro_export]
macro_rules! lua_string {
( $str:literal ) => {
$crate::cstr::cstr!($str).as_ptr()
};
}
#[macro_export]
macro_rules! lua_stack_guard {
( $lua:ident => $code:block ) => {{
#[cfg(debug_assertions)] {
let top = $lua.get_top();
let ret = $code;
if top != $lua.get_top() {
$lua.dump_stack();
panic!("Stack is dirty! Expected the stack to have {} elements, but it has {}!", top, $lua.get_top());
}
ret
}
#[cfg(not(debug_assertions))]
$code
}};
( $lua:ident => $elem:literal => $code:block ) => {{
#[cfg(debug_assertions)] {
let ret = (|| $code)();
if $lua.get_top() != $elem {
$lua.dump_stack();
panic!("Stack is dirty! Expected the stack to have ", $elem, " (fixed size) elements, but it has {}!", $lua.get_top());
}
ret
}
#[cfg(not(debug_assertions))]
$code
}};
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct LuaDebug {
pub event: i32,
pub name: LuaString,
pub namewhat: LuaString,
pub what: LuaString,
pub source: LuaString,
pub currentline: i32,
pub nups: i32,
pub linedefined: i32,
pub lastlinedefined: i32,
pub short_src: [std::os::raw::c_char; LUA_IDSIZE],
pub i_ci: i32
}
#[inline(always)]
pub unsafe fn load() {
import::LUA_SHARED.load()
}
thread_local! {
#[cfg(debug_assertions)]
static LUA: Cell<Option<State>> = Cell::new(None);
#[cfg(not(debug_assertions))]
static LUA: Cell<State> = Cell::new(State(std::ptr::null_mut()));
}
pub unsafe fn state() -> State {
LUA.with(|cell| {
#[cfg(debug_assertions)] {
cell.get().expect("The Lua state cannot be found in this thread. Perhaps you are calling this function from a thread other than the main thread? Perhaps you forgot to use the `#[gmod13_open]` macro?")
}
#[cfg(not(debug_assertions))] {
cell.get()
}
})
}
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn __set_state__internal(state: State) {
LUA.with(|cell| {
#[cfg(debug_assertions)]
cell.set(Some(state));
#[cfg(not(debug_assertions))]
cell.set(state);
})
}