1use crate::records::native_context::NativeContext;
2use crate::type_aliases::lua_state::lua_State;
3use crate::type_aliases::luau_fast_function::luau_fast_function;
4use luaur_vm::type_aliases::stk_id::StkId;
5use luaur_vm::type_aliases::t_value::TValue;
6use luaur_vm::type_aliases::tms::TMS;
7
8extern "C" {
9 pub fn luaV_lessthan(L: *mut lua_State, l: *const TValue, r: *const TValue)
10 -> core::ffi::c_int;
11 pub fn luaV_lessequal(
12 L: *mut lua_State,
13 l: *const TValue,
14 r: *const TValue,
15 ) -> core::ffi::c_int;
16 pub fn luaV_equalval(
17 L: *mut lua_State,
18 t1: *const TValue,
19 t2: *const TValue,
20 ) -> core::ffi::c_int;
21
22 pub fn luaV_doarithimpl_TM_ADD(
23 L: *mut lua_State,
24 ra: StkId,
25 rb: *const TValue,
26 rc: *const TValue,
27 );
28 pub fn luaV_doarithimpl_TM_SUB(
29 L: *mut lua_State,
30 ra: StkId,
31 rb: *const TValue,
32 rc: *const TValue,
33 );
34 pub fn luaV_doarithimpl_TM_MUL(
35 L: *mut lua_State,
36 ra: StkId,
37 rb: *const TValue,
38 rc: *const TValue,
39 );
40 pub fn luaV_doarithimpl_TM_DIV(
41 L: *mut lua_State,
42 ra: StkId,
43 rb: *const TValue,
44 rc: *const TValue,
45 );
46 pub fn luaV_doarithimpl_TM_IDIV(
47 L: *mut lua_State,
48 ra: StkId,
49 rb: *const TValue,
50 rc: *const TValue,
51 );
52 pub fn luaV_doarithimpl_TM_MOD(
53 L: *mut lua_State,
54 ra: StkId,
55 rb: *const TValue,
56 rc: *const TValue,
57 );
58 pub fn luaV_doarithimpl_TM_POW(
59 L: *mut lua_State,
60 ra: StkId,
61 rb: *const TValue,
62 rc: *const TValue,
63 );
64 pub fn luaV_doarithimpl_TM_UNM(
65 L: *mut lua_State,
66 ra: StkId,
67 rb: *const TValue,
68 rc: *const TValue,
69 );
70
71 pub fn luaV_dolen(L: *mut lua_State, ra: StkId, rb: *const TValue);
72 pub fn luaV_gettable(L: *mut lua_State, t: *const TValue, key: *mut TValue, val: StkId);
73 pub fn luaV_settable(L: *mut lua_State, t: *const TValue, key: *mut TValue, val: StkId);
74 pub fn luaV_concat(L: *mut lua_State, total: core::ffi::c_int, last: core::ffi::c_int);
75
76 pub fn luaH_getn(t: *mut core::ffi::c_void) -> core::ffi::c_int;
77 pub fn luaH_new(
78 L: *mut lua_State,
79 narray: core::ffi::c_int,
80 lnhash: core::ffi::c_int,
81 ) -> *mut core::ffi::c_void;
82 pub fn luaH_clone(L: *mut lua_State, tt: *mut core::ffi::c_void) -> *mut core::ffi::c_void;
83 pub fn luaH_resizearray(L: *mut lua_State, t: *mut core::ffi::c_void, nasize: core::ffi::c_int);
84 pub fn luaH_setnum(
85 L: *mut lua_State,
86 t: *mut core::ffi::c_void,
87 key: core::ffi::c_int,
88 ) -> *mut TValue;
89
90 pub fn luaC_barriertable(
91 L: *mut lua_State,
92 t: *mut core::ffi::c_void,
93 v: *mut core::ffi::c_void,
94 );
95 pub fn luaC_barrierf(L: *mut lua_State, o: *mut core::ffi::c_void, v: *mut core::ffi::c_void);
96 pub fn luaC_barrierback(
97 L: *mut lua_State,
98 o: *mut core::ffi::c_void,
99 gclist: *mut *mut core::ffi::c_void,
100 );
101 pub fn luaC_step(L: *mut lua_State, assist: bool) -> usize;
102
103 pub fn luaF_close(L: *mut lua_State, level: StkId);
104 pub fn luaF_findupval(L: *mut lua_State, level: StkId) -> *mut core::ffi::c_void;
105 pub fn luaF_newLclosure(
106 L: *mut lua_State,
107 nelems: core::ffi::c_int,
108 e: *mut core::ffi::c_void,
109 p: *mut core::ffi::c_void,
110 ) -> *mut core::ffi::c_void;
111
112 pub fn luaT_gettm(
113 events: *mut core::ffi::c_void,
114 event: TMS,
115 ename: *mut core::ffi::c_void,
116 ) -> *const TValue;
117 pub fn luaT_objtypenamestr(L: *mut lua_State, o: *const TValue) -> *const core::ffi::c_void;
118
119 pub fn exp(x: f64) -> f64;
120 pub fn pow(x: f64, y: f64) -> f64;
121 pub fn fmod(x: f64, y: f64) -> f64;
122 pub fn log(x: f64) -> f64;
123 pub fn log2(x: f64) -> f64;
124 pub fn log10(x: f64) -> f64;
125 pub fn ldexp(x: f64, exp: core::ffi::c_int) -> f64;
126 pub fn round(x: f64) -> f64;
127 pub fn frexp(x: f64, exp: *mut core::ffi::c_int) -> f64;
128 pub fn modf(x: f64, iptr: *mut f64) -> f64;
129
130 pub fn asin(x: f64) -> f64;
131 pub fn sin(x: f64) -> f64;
132 pub fn sinh(x: f64) -> f64;
133 pub fn acos(x: f64) -> f64;
134 pub fn cos(x: f64) -> f64;
135 pub fn cosh(x: f64) -> f64;
136 pub fn atan(x: f64) -> f64;
137 pub fn atan2(y: f64, x: f64) -> f64;
138 pub fn tan(x: f64) -> f64;
139 pub fn tanh(x: f64) -> f64;
140
141 pub fn forgLoopTableIter(
142 L: *mut lua_State,
143 h: *mut core::ffi::c_void,
144 index: core::ffi::c_int,
145 ra: *mut TValue,
146 ) -> bool;
147 pub fn forgLoopNodeIter(
148 L: *mut lua_State,
149 h: *mut core::ffi::c_void,
150 index: core::ffi::c_int,
151 ra: *mut TValue,
152 ) -> bool;
153 pub fn forgLoopNonTableFallback(
154 L: *mut lua_State,
155 insnA: core::ffi::c_int,
156 aux: core::ffi::c_int,
157 ) -> core::ffi::c_int;
158 pub fn forgLoopNonTableFallback_DEPRECATED(
159 L: *mut lua_State,
160 insnA: core::ffi::c_int,
161 aux: core::ffi::c_int,
162 ) -> bool;
163 pub fn forgPrepXnextFallback(L: *mut lua_State, ra: *mut TValue, pc: core::ffi::c_int);
164 pub fn callProlog(
165 L: *mut lua_State,
166 ra: *mut TValue,
167 argtop: StkId,
168 nresults: core::ffi::c_int,
169 ) -> *mut core::ffi::c_void;
170 pub fn callEpilogC(L: *mut lua_State, nresults: core::ffi::c_int, n: core::ffi::c_int);
171 pub fn newUserdata(
172 L: *mut lua_State,
173 s: usize,
174 tag: core::ffi::c_int,
175 ) -> *mut core::ffi::c_void;
176 pub fn getImport(L: *mut lua_State, res: StkId, id: core::ffi::c_uint, pc: core::ffi::c_uint);
177
178 pub fn callFallback(
179 L: *mut lua_State,
180 ra: StkId,
181 argtop: StkId,
182 nresults: core::ffi::c_int,
183 ) -> *mut core::ffi::c_void;
184
185 pub fn executeGETGLOBAL(
186 L: *mut lua_State,
187 pc: *const u32,
188 base: StkId,
189 k: *mut TValue,
190 ) -> *const u32;
191 pub fn executeSETGLOBAL(
192 L: *mut lua_State,
193 pc: *const u32,
194 base: StkId,
195 k: *mut TValue,
196 ) -> *const u32;
197 pub fn executeGETTABLEKS(
198 L: *mut lua_State,
199 pc: *const u32,
200 base: StkId,
201 k: *mut TValue,
202 ) -> *const u32;
203 pub fn executeSETTABLEKS(
204 L: *mut lua_State,
205 pc: *const u32,
206 base: StkId,
207 k: *mut TValue,
208 ) -> *const u32;
209 pub fn executeNAMECALL(
210 L: *mut lua_State,
211 pc: *const u32,
212 base: StkId,
213 k: *mut TValue,
214 ) -> *const u32;
215 pub fn executeFORGPREP(
216 L: *mut lua_State,
217 pc: *const u32,
218 base: StkId,
219 k: *mut TValue,
220 ) -> *const u32;
221 pub fn executeGETVARARGSMultRet(
222 L: *mut lua_State,
223 pc: *const u32,
224 base: StkId,
225 rai: core::ffi::c_int,
226 );
227 pub fn executeGETVARARGSConst(
228 L: *mut lua_State,
229 base: StkId,
230 rai: core::ffi::c_int,
231 b: core::ffi::c_int,
232 );
233 pub fn executeDUPCLOSURE(
234 L: *mut lua_State,
235 pc: *const u32,
236 base: StkId,
237 k: *mut TValue,
238 ) -> *const u32;
239 pub fn executePREPVARARGS(
240 L: *mut lua_State,
241 pc: *const u32,
242 base: StkId,
243 k: *mut TValue,
244 ) -> *const u32;
245 pub fn executeSETLIST(
246 L: *mut lua_State,
247 pc: *const u32,
248 base: StkId,
249 k: *mut TValue,
250 ) -> *const u32;
251
252 pub static luauF_table: [luau_fast_function; 256];
253}
254
255pub fn init_functions(context: &mut NativeContext) {
256 unsafe {
257 core::ptr::copy_nonoverlapping(luauF_table.as_ptr(), context.luauF_table.as_mut_ptr(), 256);
258
259 context.luaV_lessthan = Some(luaV_lessthan);
260 context.luaV_lessequal = Some(luaV_lessequal);
261 context.luaV_equalval = Some(luaV_equalval);
262
263 context.luaV_doarithadd = Some(luaV_doarithimpl_TM_ADD);
264 context.luaV_doarithsub = Some(luaV_doarithimpl_TM_SUB);
265 context.luaV_doarithmul = Some(luaV_doarithimpl_TM_MUL);
266 context.luaV_doarithdiv = Some(luaV_doarithimpl_TM_DIV);
267 context.luaV_doarithidiv = Some(luaV_doarithimpl_TM_IDIV);
268 context.luaV_doarithmod = Some(luaV_doarithimpl_TM_MOD);
269 context.luaV_doarithpow = Some(luaV_doarithimpl_TM_POW);
270 context.luaV_doarithunm = Some(luaV_doarithimpl_TM_UNM);
271
272 context.luaV_dolen = Some(luaV_dolen);
273 context.luaV_gettable = Some(luaV_gettable);
274 context.luaV_settable = Some(luaV_settable);
275 context.luaV_concat = Some(luaV_concat);
276
277 context.luaH_getn = Some(luaH_getn);
278 context.luaH_new = Some(luaH_new);
279 context.luaH_clone = Some(luaH_clone);
280 context.luaH_resizearray = Some(luaH_resizearray);
281 context.luaH_setnum = Some(luaH_setnum);
282
283 context.luaC_barriertable = Some(luaC_barriertable);
284 context.luaC_barrierf = Some(luaC_barrierf);
285 context.luaC_barrierback = Some(luaC_barrierback);
286 context.luaC_step = Some(luaC_step);
287
288 context.luaF_close = Some(luaF_close);
289 context.luaF_findupval = Some(luaF_findupval);
290 context.luaF_newLclosure = Some(luaF_newLclosure);
291
292 context.luaT_gettm = Some(luaT_gettm);
293 context.luaT_objtypenamestr = Some(luaT_objtypenamestr);
294
295 context.libm_exp = Some(exp);
296 context.libm_pow = Some(pow);
297 context.libm_fmod = Some(fmod);
298 context.libm_log = Some(log);
299 context.libm_log2 = Some(log2);
300 context.libm_log10 = Some(log10);
301 context.libm_ldexp = Some(ldexp);
302 context.libm_round = Some(round);
303 context.libm_frexp = Some(frexp);
304 context.libm_modf = Some(modf);
305
306 context.libm_asin = Some(asin);
307 context.libm_sin = Some(sin);
308 context.libm_sinh = Some(sinh);
309 context.libm_acos = Some(acos);
310 context.libm_cos = Some(cos);
311 context.libm_cosh = Some(cosh);
312 context.libm_atan = Some(atan);
313 context.libm_atan2 = Some(atan2);
314 context.libm_tan = Some(tan);
315 context.libm_tanh = Some(tanh);
316
317 context.forgLoopTableIter = Some(forgLoopTableIter);
318 context.forgLoopNodeIter = Some(forgLoopNodeIter);
319 context.forgLoopNonTableFallback = Some(forgLoopNonTableFallback);
320 context.forgLoopNonTableFallback_DEPRECATED = Some(forgLoopNonTableFallback_DEPRECATED);
321 context.forgPrepXnextFallback = Some(forgPrepXnextFallback);
322 context.callProlog = Some(callProlog);
323 context.callEpilogC = Some(callEpilogC);
324 context.newUserdata = Some(newUserdata);
325 context.getImport = Some(getImport);
326
327 context.callFallback = Some(callFallback);
328
329 context.executeGETGLOBAL = Some(executeGETGLOBAL);
330 context.executeSETGLOBAL = Some(executeSETGLOBAL);
331 context.executeGETTABLEKS = Some(executeGETTABLEKS);
332 context.executeSETTABLEKS = Some(executeSETTABLEKS);
333
334 context.executeNAMECALL = Some(executeNAMECALL);
335 context.executeFORGPREP = Some(executeFORGPREP);
336 context.executeGETVARARGSMultRet = Some(executeGETVARARGSMultRet);
337 context.executeGETVARARGSConst = Some(executeGETVARARGSConst);
338 context.executeDUPCLOSURE = Some(executeDUPCLOSURE);
339 context.executePREPVARARGS = Some(executePREPVARARGS);
340 context.executeSETLIST = Some(executeSETLIST);
341 }
342}