Skip to main content

luaur_vm/functions/
lua_h_getstr.rs

1//! Node: `cxx:Function:Luau.VM:VM/src/ltable.cpp:657:lua_h_getstr`
2//! Source: `VM/src/ltable.cpp` (ltable.cpp:657-669, hand-ported)
3
4use crate::macros::gkey::{gkey, gval};
5use crate::macros::gnext::gnext;
6use crate::macros::hashstr::hashstr;
7use crate::macros::lua_o_nilobject::luaO_nilobject;
8use crate::macros::tsvalue::tsvalue;
9use crate::macros::ttisstring::ttisstring;
10use crate::records::lua_node::LuaNode;
11use crate::records::lua_table::LuaTable;
12use crate::records::t_string::TString;
13use crate::type_aliases::t_value::TValue;
14
15#[allow(non_snake_case)]
16pub unsafe fn luaH_getstr(t: *mut LuaTable, key: *mut TString) -> *const TValue {
17    let mut n: *mut LuaNode = hashstr!(t, key);
18    loop {
19        // check whether `key' is somewhere in the chain
20        if ttisstring!(gkey!(n)) && tsvalue!(gkey!(n)) == key {
21            return gval!(n); // that's it
22        }
23        if gnext!(n) == 0 {
24            break;
25        }
26        n = n.offset(gnext!(n) as isize);
27    }
28    luaO_nilobject
29}
30
31pub use luaH_getstr as lua_h_getstr;