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(
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 = "luajit", doc))]
78 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
79 pub const JIT: StdLib = StdLib(1 << 11);
80
81 #[cfg(any(feature = "luajit", doc))]
83 #[cfg_attr(docsrs, doc(cfg(feature = "luajit")))]
84 pub const FFI: StdLib = StdLib(1 << 30);
85
86 pub const DEBUG: StdLib = StdLib(1 << 31);
88
89 pub const NONE: StdLib = StdLib(0);
91 pub const ALL: StdLib = StdLib(u32::MAX);
93 #[cfg(not(feature = "luau"))]
95 pub const ALL_SAFE: StdLib = StdLib((1 << 30) - 1);
96 #[cfg(feature = "luau")]
97 pub const ALL_SAFE: StdLib = StdLib(u32::MAX);
98
99 pub fn contains(self, lib: Self) -> bool {
100 (self & lib).0 != 0
101 }
102}
103
104impl BitAnd for StdLib {
105 type Output = Self;
106 fn bitand(self, rhs: Self) -> Self::Output {
107 StdLib(self.0 & rhs.0)
108 }
109}
110
111impl BitAndAssign for StdLib {
112 fn bitand_assign(&mut self, rhs: Self) {
113 *self = StdLib(self.0 & rhs.0)
114 }
115}
116
117impl BitOr for StdLib {
118 type Output = Self;
119 fn bitor(self, rhs: Self) -> Self::Output {
120 StdLib(self.0 | rhs.0)
121 }
122}
123
124impl BitOrAssign for StdLib {
125 fn bitor_assign(&mut self, rhs: Self) {
126 *self = StdLib(self.0 | rhs.0)
127 }
128}
129
130impl BitXor for StdLib {
131 type Output = Self;
132 fn bitxor(self, rhs: Self) -> Self::Output {
133 StdLib(self.0 ^ rhs.0)
134 }
135}
136
137impl BitXorAssign for StdLib {
138 fn bitxor_assign(&mut self, rhs: Self) {
139 *self = StdLib(self.0 ^ rhs.0)
140 }
141}