luaur_code_gen/functions/
on_destroy_function.rs1use crate::functions::get_code_gen_context::get_code_gen_context;
2use crate::records::shared_code_gen_context::SharedCodeGenContext;
3use crate::type_aliases::lua_state::lua_State;
4use luaur_vm::records::proto::Proto;
5
6pub fn on_destroy_function(L: *mut lua_State, proto: *mut Proto) {
7 unsafe {
8 if L.is_null() || proto.is_null() {
9 return;
10 }
11
12 let ctx = get_code_gen_context(L);
13 if !ctx.is_null() && !(*proto).execdata.is_null() {
14 SharedCodeGenContext::on_destroy_function((*proto).execdata);
15 }
16
17 (*proto).execdata = core::ptr::null_mut();
18 (*proto).exectarget = 0;
19 (*proto).codeentry = (*proto).code;
20 }
21}
22
23#[export_name = "on_destroy_function"]
24pub unsafe extern "C" fn on_destroy_function_export(L: *mut lua_State, proto: *mut Proto) {
25 on_destroy_function(L, proto);
26}