luaur_vm/functions/
lua_l_openlibs.rs1use crate::functions::lua_call::lua_call;
5use crate::functions::lua_pushstring::lua_pushstring;
6use crate::functions::luaopen_base::luaopen_base;
7use crate::functions::luaopen_bit_32::luaopen_bit32;
8use crate::functions::luaopen_buffer::luaopen_buffer;
9use crate::functions::luaopen_class::luaopen_class;
10use crate::functions::luaopen_coroutine::luaopen_coroutine;
11use crate::functions::luaopen_debug::luaopen_debug;
12use crate::functions::luaopen_integer::luaopen_integer;
13use crate::functions::luaopen_math::luaopen_math;
14use crate::functions::luaopen_os::luaopen_os;
15use crate::functions::luaopen_string::luaopen_string;
16use crate::functions::luaopen_table::luaopen_table;
17use crate::functions::luaopen_utf_8::luaopen_utf_8;
18use crate::functions::luaopen_vector::luaopen_vector;
19use crate::macros::lua_pushcfunction::LUA_PUSHCFUNCTION;
20use crate::records::lua_l_reg::LuaLReg;
21use crate::type_aliases::lua_state::lua_State;
22
23pub unsafe fn lua_l_openlibs(l: *mut lua_State) {
24 let lualibs = [
25 LuaLReg {
26 name: c"".as_ptr(),
27 func: Some(luaopen_base),
28 },
29 LuaLReg {
30 name: c"coroutine".as_ptr(),
31 func: Some(luaopen_coroutine),
32 },
33 LuaLReg {
34 name: c"table".as_ptr(),
35 func: Some(luaopen_table),
36 },
37 LuaLReg {
38 name: c"os".as_ptr(),
39 func: Some(luaopen_os),
40 },
41 LuaLReg {
42 name: c"string".as_ptr(),
43 func: Some(luaopen_string),
44 },
45 LuaLReg {
46 name: c"math".as_ptr(),
47 func: Some(luaopen_math),
48 },
49 LuaLReg {
50 name: c"debug".as_ptr(),
51 func: Some(luaopen_debug),
52 },
53 LuaLReg {
54 name: c"utf8".as_ptr(),
55 func: Some(luaopen_utf_8),
56 },
57 LuaLReg {
58 name: c"bit32".as_ptr(),
59 func: Some(luaopen_bit32),
60 },
61 LuaLReg {
62 name: c"buffer".as_ptr(),
63 func: Some(luaopen_buffer),
64 },
65 LuaLReg {
66 name: c"vector".as_ptr(),
67 func: Some(luaopen_vector),
68 },
69 LuaLReg {
70 name: c"int64".as_ptr(),
71 func: Some(luaopen_integer),
72 },
73 LuaLReg {
74 name: core::ptr::null(),
75 func: None,
76 },
77 ];
78
79 let lualibs_nointeger = [
80 LuaLReg {
81 name: c"".as_ptr(),
82 func: Some(luaopen_base),
83 },
84 LuaLReg {
85 name: c"coroutine".as_ptr(),
86 func: Some(luaopen_coroutine),
87 },
88 LuaLReg {
89 name: c"table".as_ptr(),
90 func: Some(luaopen_table),
91 },
92 LuaLReg {
93 name: c"os".as_ptr(),
94 func: Some(luaopen_os),
95 },
96 LuaLReg {
97 name: c"string".as_ptr(),
98 func: Some(luaopen_string),
99 },
100 LuaLReg {
101 name: c"math".as_ptr(),
102 func: Some(luaopen_math),
103 },
104 LuaLReg {
105 name: c"debug".as_ptr(),
106 func: Some(luaopen_debug),
107 },
108 LuaLReg {
109 name: c"utf8".as_ptr(),
110 func: Some(luaopen_utf_8),
111 },
112 LuaLReg {
113 name: c"bit32".as_ptr(),
114 func: Some(luaopen_bit32),
115 },
116 LuaLReg {
117 name: c"buffer".as_ptr(),
118 func: Some(luaopen_buffer),
119 },
120 LuaLReg {
121 name: c"vector".as_ptr(),
122 func: Some(luaopen_vector),
123 },
124 LuaLReg {
125 name: core::ptr::null(),
126 func: None,
127 },
128 ];
129
130 let libs = if luaur_common::FFlag::LuauIntegerLibrary.get() {
131 lualibs.as_ptr()
132 } else {
133 lualibs_nointeger.as_ptr()
134 };
135
136 let mut lib = libs;
137 while (*lib).func.is_some() {
138 LUA_PUSHCFUNCTION(l, (*lib).func, core::ptr::null());
139 lua_pushstring(l, (*lib).name);
140 lua_call(l, 1, 0);
141 lib = lib.add(1);
142 }
143
144 if luaur_common::FFlag::DebugLuauUserDefinedClassesRuntime.get() {
145 LUA_PUSHCFUNCTION(l, Some(luaopen_class), core::ptr::null());
146 lua_pushstring(l, c"class".as_ptr());
147 lua_call(l, 1, 0);
148 }
149}