Skip to main content

luaur_repl_cli/functions/
coverage_init.rs

1use alloc::vec::Vec;
2
3use luaur_vm::functions::lua_mainthread::lua_mainthread;
4use luaur_vm::type_aliases::lua_state::lua_State;
5
6// Faithful port of Repl.cpp's file-static `struct Coverage { lua_State* L;
7// std::vector<int> functions; } gCoverage;`. The REPL drives this on a single
8// thread, mirroring the C++ static.
9pub(crate) struct CoverageState {
10    pub(crate) l: *mut lua_State,
11    pub(crate) functions: Vec<i32>,
12}
13
14pub(crate) static mut G_COVERAGE: CoverageState = CoverageState {
15    l: core::ptr::null_mut(),
16    functions: Vec::new(),
17};
18
19pub fn coverage_init(l: *mut lua_State) {
20    unsafe {
21        (*core::ptr::addr_of_mut!(G_COVERAGE)).l = lua_mainthread(l);
22    }
23}