1use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
2
3#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
5pub struct StdLib(u32);
6
7impl StdLib {
8 #[cfg(any(
12 feature = "lua54",
13 feature = "lua53",
14 feature = "lua52",
15 feature = "luau"
16 ))]
17 pub const COROUTINE: StdLib = StdLib(1);
18
19 pub const TABLE: StdLib = StdLib(1 << 1);
21
22 #[cfg(not(feature = "luau"))]
24 #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
25 pub const IO: StdLib = StdLib(1 << 2);
26
27 pub const OS: StdLib = StdLib(1 << 3);
29
30 pub const STRING: StdLib = StdLib(1 << 4);
32
33 #[cfg(any(feature = "lua54", feature = "lua53", feature = "luau"))]
37 pub const UTF8: StdLib = StdLib(1 << 5);
38
39 #[cfg(any(feature = "lua52", feature = "luajit", feature = "luau", doc))]
43 pub const BIT: StdLib = StdLib(1 << 6);
44
45 pub const MATH: StdLib = StdLib(1 << 7);
47
48 pub const PACKAGE: StdLib = StdLib(1 << 8);
50
51 #[cfg(any(feature = "luau", doc))]
53 #[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
54 pub const BUFFER: StdLib = StdLib(1 << 9);
55
56 #[cfg(any(feature = "luajit", doc))]
60 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
61 pub const JIT: StdLib = StdLib(1 << 9);
62
63 #[cfg(any(feature = "luajit", doc))]
67 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
68 pub const FFI: StdLib = StdLib(1 << 30);
69
70 pub const DEBUG: StdLib = StdLib(1 << 31);
72
73 pub const NONE: StdLib = StdLib(0);
75 pub const ALL: StdLib = StdLib(u32::MAX);
77 #[cfg(not(feature = "luau"))]
79 pub const ALL_SAFE: StdLib = StdLib((1 << 30) - 1);
80 #[cfg(feature = "luau")]
81 pub const ALL_SAFE: StdLib = StdLib(u32::MAX);
82
83 pub fn contains(self, lib: Self) -> bool {
84 (self & lib).0 != 0
85 }
86}
87
88impl BitAnd for StdLib {
89 type Output = Self;
90 fn bitand(self, rhs: Self) -> Self::Output {
91 StdLib(self.0 & rhs.0)
92 }
93}
94
95impl BitAndAssign for StdLib {
96 fn bitand_assign(&mut self, rhs: Self) {
97 *self = StdLib(self.0 & rhs.0)
98 }
99}
100
101impl BitOr for StdLib {
102 type Output = Self;
103 fn bitor(self, rhs: Self) -> Self::Output {
104 StdLib(self.0 | rhs.0)
105 }
106}
107
108impl BitOrAssign for StdLib {
109 fn bitor_assign(&mut self, rhs: Self) {
110 *self = StdLib(self.0 | rhs.0)
111 }
112}
113
114impl BitXor for StdLib {
115 type Output = Self;
116 fn bitxor(self, rhs: Self) -> Self::Output {
117 StdLib(self.0 ^ rhs.0)
118 }
119}
120
121impl BitXorAssign for StdLib {
122 fn bitxor_assign(&mut self, rhs: Self) {
123 *self = StdLib(self.0 ^ rhs.0)
124 }
125}