luaur-analysis 0.1.3

Luau type checker and type inference (Rust).
Documentation
use luaur_ast::records::ast_expr_call::AstExprCall;
use luaur_ast::records::ast_expr_global::AstExprGlobal;
use luaur_ast::records::ast_node::AstNode;
use luaur_ast::rtti::ast_node_as;

pub fn match_set_metatable(call: &AstExprCall) -> bool {
    if call.args.len() != 2 {
        return false;
    }

    let func_as_global = unsafe { ast_node_as::<AstExprGlobal>(call.func as *mut AstNode) };

    if func_as_global.is_null() {
        return false;
    }

    let name = unsafe { (*func_as_global).name.value };
    if name.is_null() {
        return false;
    }

    let name_bytes = unsafe { core::ffi::CStr::from_ptr(name).to_bytes() };
    name_bytes == b"setmetatable"
}