Skip to main content

luaur_bytecode/methods/
bytecode_builder_set_debug_function_name.rs

1use crate::records::bytecode_builder::BytecodeBuilder;
2use crate::records::string_ref::StringRef;
3
4impl BytecodeBuilder {
5    pub fn set_debug_function_name(&mut self, name: StringRef) {
6        let index = self.add_string_table_entry(name);
7
8        self.functions[self.current_function as usize].debugname = index;
9
10        // C++: `functions[currentFunction].dumpname = std::string(name.data, name.length);`
11        // dumpname is the function's debug NAME (e.g. 'foo'), shown in DUPCLOSURE
12        // constant dumps — NOT the function's bytecode dump. The port erroneously
13        // invoked the dump function pointer here.
14        if self.dump_function_ptr.is_some() {
15            let bytes = if name.length == 0 {
16                &[][..]
17            } else {
18                unsafe { core::slice::from_raw_parts(name.data as *const u8, name.length) }
19            };
20            self.functions[self.current_function as usize].dumpname =
21                alloc::string::String::from_utf8_lossy(bytes).into_owned();
22        }
23    }
24}