1use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
2
3#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
5pub struct StdLib(u32);
6
7impl StdLib {
8 #[cfg(any(
10 feature = "lua55",
11 feature = "lua54",
12 feature = "lua53",
13 feature = "lua52",
14 feature = "luau"
15 ))]
16 #[cfg_attr(
17 docsrs,
18 doc(cfg(any(
19 feature = "lua55",
20 feature = "lua54",
21 feature = "lua53",
22 feature = "lua52",
23 feature = "luau"
24 )))
25 )]
26 pub const COROUTINE: StdLib = StdLib(1);
27
28 pub const TABLE: StdLib = StdLib(1 << 1);
30
31 #[cfg(not(feature = "luau"))]
33 #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
34 pub const IO: StdLib = StdLib(1 << 2);
35
36 pub const OS: StdLib = StdLib(1 << 3);
38
39 pub const STRING: StdLib = StdLib(1 << 4);
41
42 #[cfg(any(feature = "lua55", feature = "lua54", feature = "lua53", feature = "luau"))]
44 #[cfg_attr(
45 docsrs,
46 doc(cfg(any(feature = "lua55", feature = "lua54", feature = "lua53", feature = "luau")))
47 )]
48 pub const UTF8: StdLib = StdLib(1 << 5);
49
50 #[cfg(any(feature = "lua52", feature = "luajit", feature = "luau", doc))]
52 #[cfg_attr(
53 docsrs,
54 doc(cfg(any(feature = "lua52", feature = "luajit", feature = "luau")))
55 )]
56 pub const BIT: StdLib = StdLib(1 << 6);
57
58 pub const MATH: StdLib = StdLib(1 << 7);
60
61 #[cfg(not(feature = "luau"))]
63 #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
64 pub const PACKAGE: StdLib = StdLib(1 << 8);
65
66 #[cfg(any(feature = "luau", doc))]
68 #[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
69 pub const BUFFER: StdLib = StdLib(1 << 9);
70
71 #[cfg(any(feature = "luau", doc))]
73 #[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
74 pub const VECTOR: StdLib = StdLib(1 << 10);
75
76 #[cfg(any(feature = "luau", doc))]
78 #[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
79 pub const INTEGER: StdLib = StdLib(1 << 11);
80
81 #[cfg(any(feature = "luajit", doc))]
83 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
84 pub const JIT: StdLib = StdLib(1 << 12);
85
86 #[cfg(any(feature = "luajit", doc))]
88 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
89 pub const FFI: StdLib = StdLib(1 << 30);
90
91 pub const DEBUG: StdLib = StdLib(1 << 31);
93
94 pub const NONE: StdLib = StdLib(0);
96 pub const ALL: StdLib = StdLib(u32::MAX);
98 #[cfg(not(feature = "luau"))]
100 pub const ALL_SAFE: StdLib = StdLib((1 << 30) - 1);
101 #[cfg(feature = "luau")]
102 pub const ALL_SAFE: StdLib = StdLib(u32::MAX);
103
104 pub fn contains(self, lib: Self) -> bool {
105 (self & lib).0 != 0
106 }
107}
108
109impl BitAnd for StdLib {
110 type Output = Self;
111 fn bitand(self, rhs: Self) -> Self::Output {
112 StdLib(self.0 & rhs.0)
113 }
114}
115
116impl BitAndAssign for StdLib {
117 fn bitand_assign(&mut self, rhs: Self) {
118 *self = StdLib(self.0 & rhs.0)
119 }
120}
121
122impl BitOr for StdLib {
123 type Output = Self;
124 fn bitor(self, rhs: Self) -> Self::Output {
125 StdLib(self.0 | rhs.0)
126 }
127}
128
129impl BitOrAssign for StdLib {
130 fn bitor_assign(&mut self, rhs: Self) {
131 *self = StdLib(self.0 | rhs.0)
132 }
133}
134
135impl BitXor for StdLib {
136 type Output = Self;
137 fn bitxor(self, rhs: Self) -> Self::Output {
138 StdLib(self.0 ^ rhs.0)
139 }
140}
141
142impl BitXorAssign for StdLib {
143 fn bitxor_assign(&mut self, rhs: Self) {
144 *self = StdLib(self.0 ^ rhs.0)
145 }
146}
147
148impl Not for StdLib {
149 type Output = Self;
150 fn not(self) -> Self::Output {
151 StdLib(!self.0)
152 }
153}