Skip to main content

mlua_sys/
lib.rs

1//! Low level bindings to Lua 5.5/5.4/5.3/5.2/5.1 (including LuaJIT) and Luau.
2
3#![allow(non_camel_case_types, non_snake_case)]
4#![allow(clippy::missing_safety_doc)]
5#![allow(unsafe_op_in_unsafe_fn)]
6#![doc(test(attr(deny(warnings))))]
7#![cfg_attr(docsrs, feature(doc_cfg))]
8
9use std::os::raw::c_int;
10
11#[cfg(any(feature = "lua55", doc))]
12pub use lua55::*;
13
14#[cfg(any(feature = "lua54", doc))]
15pub use lua54::*;
16
17#[cfg(any(feature = "lua53", doc))]
18pub use lua53::*;
19
20#[cfg(any(feature = "lua52", doc))]
21pub use lua52::*;
22
23#[cfg(any(feature = "lua51", feature = "luajit", doc))]
24pub use lua51::*;
25
26#[cfg(any(feature = "luau", doc))]
27pub use luau::*;
28
29#[cfg(any(feature = "lua55", feature = "lua54", feature = "lua53", feature = "lua52"))]
30#[doc(hidden)]
31pub const LUA_MAX_UPVALUES: c_int = 255;
32
33#[cfg(any(feature = "lua51", feature = "luajit"))]
34#[doc(hidden)]
35pub const LUA_MAX_UPVALUES: c_int = 60;
36
37#[cfg(feature = "luau")]
38#[doc(hidden)]
39pub const LUA_MAX_UPVALUES: c_int = 200;
40
41// I believe `luaL_traceback` < 5.4 requires this much free stack to not error.
42// 5.4 uses `luaL_Buffer`
43#[doc(hidden)]
44pub const LUA_TRACEBACK_STACK: c_int = 11;
45
46// The minimum alignment guaranteed by the architecture.
47// Copied from https://github.com/rust-lang/rust/blob/main/library/std/src/sys/alloc/mod.rs
48#[doc(hidden)]
49#[rustfmt::skip]
50pub const SYS_MIN_ALIGN: usize = if cfg!(any(
51    all(target_arch = "riscv32", any(target_os = "espidf", target_os = "zkvm")),
52    all(target_arch = "xtensa", target_os = "espidf"),
53)) {
54    // The allocator on the esp-idf and zkvm platforms guarantees 4 byte alignment.
55    4
56} else if cfg!(any(
57    target_arch = "x86",
58    target_arch = "arm",
59    target_arch = "m68k",
60    target_arch = "csky",
61    target_arch = "loongarch32",
62    target_arch = "mips",
63    target_arch = "mips32r6",
64    target_arch = "powerpc",
65    target_arch = "powerpc64",
66    target_arch = "sparc",
67    target_arch = "wasm32",
68    target_arch = "hexagon",
69    target_arch = "riscv32",
70    target_arch = "xtensa",
71)) {
72    8
73} else if cfg!(any(
74    target_arch = "x86_64",
75    target_arch = "aarch64",
76    target_arch = "arm64ec",
77    target_arch = "loongarch64",
78    target_arch = "mips64",
79    target_arch = "mips64r6",
80    target_arch = "s390x",
81    target_arch = "sparc64",
82    target_arch = "riscv64",
83    target_arch = "wasm64",
84)) {
85    16
86} else {
87    panic!("no value for SYS_MIN_ALIGN")
88};
89
90#[macro_use]
91mod macros;
92
93#[cfg(any(feature = "lua55", doc))]
94#[cfg_attr(docsrs, doc(cfg(feature = "lua55")))]
95pub mod lua55;
96
97#[cfg(any(feature = "lua54", doc))]
98#[cfg_attr(docsrs, doc(cfg(feature = "lua54")))]
99pub mod lua54;
100
101#[cfg(any(feature = "lua53", doc))]
102#[cfg_attr(docsrs, doc(cfg(feature = "lua53")))]
103pub mod lua53;
104
105#[cfg(any(feature = "lua52", doc))]
106#[cfg_attr(docsrs, doc(cfg(feature = "lua52")))]
107pub mod lua52;
108
109#[cfg(any(feature = "lua51", feature = "luajit", doc))]
110#[cfg_attr(docsrs, doc(cfg(any(feature = "lua51", feature = "luajit"))))]
111pub mod lua51;
112
113#[cfg(any(feature = "luau", doc))]
114#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
115pub mod luau;