luaur_repl_cli/functions/try_replace_top_with_index.rs
1use core::ffi::c_char;
2use luaur_vm::functions::lua_l_getmetafield::lua_l_getmetafield;
3use luaur_vm::functions::lua_remove::lua_remove;
4use luaur_vm::records::lua_state::lua_State;
5
6pub unsafe fn try_replace_top_with_index(l: *mut lua_State) -> bool {
7 if lua_l_getmetafield(l, -1, b"__index\0".as_ptr() as *const c_char) != 0 {
8 // Remove the table leaving __index on the top of stack
9 lua_remove(l, -2);
10 true
11 } else {
12 false
13 }
14}