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