luaur_analysis/functions/
match_require.rs1use luaur_ast::records::ast_expr::AstExpr;
2use luaur_ast::records::ast_expr_call::AstExprCall;
3use luaur_ast::records::ast_expr_global::AstExprGlobal;
4use luaur_ast::records::ast_node::AstNode;
5
6use luaur_ast::rtti::ast_node_as;
7
8pub fn match_require(call: &AstExprCall) -> Option<*mut AstExpr> {
9 const REQUIRE: &str = "require";
10
11 if call.args.len() != 1 {
12 return None;
13 }
14
15 let func_as_global = unsafe { ast_node_as::<AstExprGlobal>(call.func as *mut AstNode) };
16 if func_as_global.is_null() {
17 return None;
18 }
19
20 let name_ptr = unsafe { (*func_as_global).name.value };
21 if name_ptr.is_null() {
22 return None;
23 }
24
25 let name_bytes = unsafe { core::ffi::CStr::from_ptr(name_ptr).to_bytes() };
26 if name_bytes != REQUIRE.as_bytes() {
27 return None;
28 }
29
30 Some(unsafe { *call.args.begin() })
31}