luaur-rt 0.1.3

Safe, ergonomic, mlua-style API for luaur (pure-Rust Luau).
Documentation
//! Thin, centralized imports of the luaur C API we build on (internal plumbing).
//!
//! Every raw `lua_*` function/type/constant used by `luaur-rt` is re-exported
//! from here, so the rest of the crate has a single place to look and we keep
//! the (long) import paths in one module. Nothing in here is part of the public
//! API; the small mlua-style public `ffi` surface lives in `crate::sys` (the
//! `ffi.rs` *public* module), this one is mounted privately as `crate::sys`.

pub(crate) use core::ffi::{c_char, c_int, c_void};

// ---- types ---------------------------------------------------------------
pub(crate) use luaur_vm::type_aliases::lua_c_function::lua_CFunction;
pub(crate) use luaur_vm::type_aliases::lua_state::lua_State;

// ---- state ---------------------------------------------------------------
pub(crate) use luaur_vm::functions::lua_close::lua_close;
pub(crate) use luaur_vm::functions::lua_l_newstate::lua_l_newstate;
pub(crate) use luaur_vm::functions::lua_l_openlibs::lua_l_openlibs;

// ---- stack / values ------------------------------------------------------
pub(crate) use luaur_vm::functions::lua_gettop::lua_gettop;
pub(crate) use luaur_vm::functions::lua_pushboolean::lua_pushboolean;
pub(crate) use luaur_vm::functions::lua_pushlstring::lua_pushlstring;
pub(crate) use luaur_vm::functions::lua_pushnil::lua_pushnil;
pub(crate) use luaur_vm::functions::lua_pushnumber::lua_pushnumber;
pub(crate) use luaur_vm::functions::lua_pushvalue::lua_pushvalue;
pub(crate) use luaur_vm::functions::lua_settop::lua_settop;
pub(crate) use luaur_vm::functions::lua_toboolean::lua_toboolean;
pub(crate) use luaur_vm::functions::lua_tolstring::lua_tolstring;
pub(crate) use luaur_vm::functions::lua_tonumberx::lua_tonumberx;
pub(crate) use luaur_vm::functions::lua_type::lua_type;

// ---- tables --------------------------------------------------------------
pub(crate) use luaur_vm::functions::lua_createtable::lua_createtable;
pub(crate) use luaur_vm::functions::lua_gettable::lua_gettable;
pub(crate) use luaur_vm::functions::lua_next::lua_next;
pub(crate) use luaur_vm::functions::lua_objlen::lua_objlen;
pub(crate) use luaur_vm::functions::lua_settable::lua_settable;

// ---- raw table access + metatables + stack juggling ----------------------
pub(crate) use luaur_vm::functions::lua_equal::lua_equal;
pub(crate) use luaur_vm::functions::lua_getmetatable::lua_getmetatable;
pub(crate) use luaur_vm::functions::lua_getreadonly::lua_getreadonly;
pub(crate) use luaur_vm::functions::lua_insert::lua_insert;
pub(crate) use luaur_vm::functions::lua_rawget::lua_rawget;
pub(crate) use luaur_vm::functions::lua_rawset::lua_rawset;
pub(crate) use luaur_vm::functions::lua_setreadonly::lua_setreadonly;
pub(crate) use luaur_vm::functions::lua_topointer::lua_topointer;

// ---- garbage collection --------------------------------------------------
pub(crate) use luaur_vm::enums::lua_gc_op::lua_GCOp;
pub(crate) use luaur_vm::functions::lua_gc::lua_gc;

// ---- interrupts / sandbox / memory categories (Luau) ---------------------
pub(crate) use luaur_vm::functions::lua_callbacks::lua_callbacks;
pub(crate) use luaur_vm::functions::lua_isyieldable::lua_isyieldable;
pub(crate) use luaur_vm::functions::lua_l_sandbox::lua_l_sandbox;
pub(crate) use luaur_vm::functions::lua_l_sandboxthread::lua_l_sandboxthread;
pub(crate) use luaur_vm::functions::lua_rawcheckstack::lua_rawcheckstack;
pub(crate) use luaur_vm::functions::lua_replace::lua_replace;
pub(crate) use luaur_vm::functions::lua_setmemcat::lua_setmemcat;
pub(crate) use luaur_vm::functions::lua_setsafeenv::lua_setsafeenv;

// ---- metatable-aware tostring --------------------------------------------
pub(crate) use luaur_vm::functions::lua_l_tolstring::lua_l_tolstring;

// ---- traceback -----------------------------------------------------------
pub(crate) use luaur_vm::functions::lua_l_traceback::lua_l_traceback;

// ---- named registry + field access ---------------------------------------
pub(crate) use luaur_vm::functions::lua_getfield::lua_getfield;
pub(crate) use luaur_vm::functions::lua_setfield::lua_setfield;
pub(crate) use luaur_vm::macros::lua_registryindex::LUA_REGISTRYINDEX;

// ---- light userdata ------------------------------------------------------
pub(crate) use luaur_vm::functions::lua_pushlightuserdatatagged::lua_pushlightuserdatatagged;
pub(crate) use luaur_vm::functions::lua_tolightuserdata::lua_tolightuserdata;

// ---- buffers / vectors (Luau) --------------------------------------------
pub(crate) use luaur_vm::functions::lua_newbuffer::lua_newbuffer;
pub(crate) use luaur_vm::functions::lua_pushvector_lapi::lua_pushvector_lua_state_f32_f32_f32_f32;
pub(crate) use luaur_vm::functions::lua_tobuffer::lua_tobuffer;
pub(crate) use luaur_vm::functions::lua_tovector::lua_tovector;

// ---- closures / userdata -------------------------------------------------
pub(crate) use luaur_vm::functions::lua_newuserdatadtor::lua_newuserdatadtor;
pub(crate) use luaur_vm::functions::lua_pushcclosurek::lua_pushcclosurek;
pub(crate) use luaur_vm::functions::lua_setmetatable::lua_setmetatable;
pub(crate) use luaur_vm::functions::lua_touserdata::lua_touserdata;

// ---- refs / call / load --------------------------------------------------
pub(crate) use luaur_vm::functions::lua_checkstack::lua_checkstack;
pub(crate) use luaur_vm::functions::lua_error::lua_error;
pub(crate) use luaur_vm::functions::lua_pcall::lua_pcall;
pub(crate) use luaur_vm::functions::lua_ref::lua_ref;
pub(crate) use luaur_vm::functions::lua_unref::lua_unref;
pub(crate) use luaur_vm::functions::luau_load::luau_load;

// ---- threads / coroutines ------------------------------------------------
pub(crate) use luaur_vm::functions::lua_costatus::lua_costatus;
pub(crate) use luaur_vm::functions::lua_newthread::lua_newthread;
pub(crate) use luaur_vm::functions::lua_pushthread::lua_pushthread;
pub(crate) use luaur_vm::functions::lua_resetthread::lua_resetthread;
pub(crate) use luaur_vm::functions::lua_resume::lua_resume;
pub(crate) use luaur_vm::functions::lua_resumeerror::lua_resumeerror;
pub(crate) use luaur_vm::functions::lua_status::lua_status;
pub(crate) use luaur_vm::functions::lua_tothread::lua_tothread;
pub(crate) use luaur_vm::functions::lua_xmove::lua_xmove;

// ---- function environment + debug info -----------------------------------
pub(crate) use luaur_vm::functions::lua_getfenv::lua_getfenv;
pub(crate) use luaur_vm::functions::lua_getinfo::lua_getinfo;
pub(crate) use luaur_vm::functions::lua_getupvalue::lua_getupvalue;
pub(crate) use luaur_vm::functions::lua_setfenv::lua_setfenv;
pub(crate) use luaur_vm::records::lua_debug::LuaDebug;

// ---- macro-defined helpers (exposed as plain fns) ------------------------
pub(crate) use luaur_vm::macros::lua_globalsindex::LUA_GLOBALSINDEX;
pub(crate) use luaur_vm::macros::lua_pop::lua_pop;
pub(crate) use luaur_vm::macros::lua_upvalueindex::lua_upvalueindex;

// ---- async bridge (Future <-> coroutine) ---------------------------------
// Only the async feature touches these; gating them keeps the default build
// free of unused-import churn (and byte-identical).
#[cfg(feature = "async")]
pub(crate) use luaur_vm::functions::lua_pushinteger::lua_pushinteger;
#[cfg(feature = "async")]
pub(crate) use luaur_vm::functions::lua_rawgeti::lua_rawgeti;
#[cfg(feature = "async")]
pub(crate) use luaur_vm::functions::lua_tointegerx::lua_tointegerx;

/// Lua type tags (subset we care about). The VM returns these as `c_int` from
/// [`lua_type`]; we keep our own constants to avoid leaking the VM enum.
pub(crate) mod ttype {
    use super::c_int;
    pub const NONE: c_int = -1;
    pub const NIL: c_int = 0;
    pub const BOOLEAN: c_int = 1;
    pub const LIGHTUSERDATA: c_int = 2;
    pub const VECTOR: c_int = 5;
    pub const NUMBER: c_int = 3;
    pub const STRING: c_int = 6;
    pub const TABLE: c_int = 7;
    pub const FUNCTION: c_int = 8;
    pub const USERDATA: c_int = 9;
    pub const THREAD: c_int = 10;
    pub const BUFFER: c_int = 11;
}

/// Coroutine status codes returned by [`super::lua_costatus`] (mirrors luaur's
/// `lua_CoStatus`). Kept local so we don't leak the VM enum.
pub(crate) mod costatus {
    use super::c_int;
    pub const RUNNING: c_int = 0;
    pub const SUSPENDED: c_int = 1;
    pub const NORMAL: c_int = 2;
    pub const FINISHED: c_int = 3;
    pub const ERROR: c_int = 4;
}

/// Lua call/load status codes (subset). Mirrors luaur's `lua_Status`.
pub(crate) mod status {
    use super::c_int;
    pub const OK: c_int = 0;
    pub const YIELD: c_int = 1;
    /// `LUA_BREAK` — produced when an interrupt callback yields the VM via
    /// `lua_break`. The coroutine is still resumable (it continues from the
    /// break point on the next `lua_resume`), so we treat it like a yield.
    pub const BREAK: c_int = 6;
}