2024-11-21 18:50:10 +03:00
|
|
|
use std::ffi::CStr;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
lua_bindings::{lua_CFunction, lua_State, LUA_GLOBALSINDEX},
|
|
|
|
LUA,
|
|
|
|
};
|
2024-11-21 17:08:03 +03:00
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
2024-11-21 18:50:10 +03:00
|
|
|
pub(crate) struct LuaState {
|
|
|
|
lua: *mut lua_State,
|
|
|
|
}
|
2024-11-21 17:08:03 +03:00
|
|
|
|
|
|
|
impl LuaState {
|
|
|
|
pub(crate) fn new(lua: *mut lua_State) -> Self {
|
2024-11-21 18:50:10 +03:00
|
|
|
Self { lua }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn raw(&self) -> *mut lua_State {
|
|
|
|
self.lua
|
2024-11-21 17:08:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn to_integer(&self, index: i32) -> isize {
|
2024-11-21 18:50:10 +03:00
|
|
|
unsafe { LUA.lua_tointeger(self.lua, index) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn to_cfunction(&self, index: i32) -> lua_CFunction {
|
|
|
|
unsafe { LUA.lua_tocfunction(self.lua, index) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn get_global(&self, name: &CStr) {
|
|
|
|
unsafe { LUA.lua_getfield(self.lua, LUA_GLOBALSINDEX, name.as_ptr()) };
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn pop_last(&self) {
|
|
|
|
unsafe { LUA.lua_settop(self.lua, -2) };
|
2024-11-21 17:08:03 +03:00
|
|
|
}
|
|
|
|
}
|