Skip to content

Commit 5bddac9

Browse files
committed
Add num_params, is_vararg, nups to FunctionInfo
1 parent 0245d4c commit 5bddac9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/function.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ pub struct FunctionInfo {
5050
pub line_defined: Option<usize>,
5151
/// The line number where the definition of the function ends (not set by Luau).
5252
pub last_line_defined: Option<usize>,
53+
/// Number of function parameters
54+
#[cfg(any(not(feature = "lua51"), doc))]
55+
pub num_params: usize,
56+
/// True if function accepts variable args
57+
#[cfg(any(not(feature = "lua51"), doc))]
58+
pub is_vararg: bool,
59+
/// Number of upvalues
60+
pub nups: usize,
5361
}
5462

5563
/// Luau function coverage snapshot.
@@ -343,7 +351,7 @@ impl Function {
343351

344352
/// Returns information about the function.
345353
///
346-
/// Corresponds to the `>Sn` what mask for [`lua_getinfo`] when applied to the function.
354+
/// Corresponds to the `>Snu` what mask for [`lua_getinfo`] when applied to the function.
347355
///
348356
/// [`lua_getinfo`]: https://www.lua.org/manual/5.4/manual.html#lua_getinfo
349357
pub fn info(&self) -> FunctionInfo {
@@ -355,8 +363,8 @@ impl Function {
355363

356364
let mut ar: ffi::lua_Debug = mem::zeroed();
357365
lua.push_ref(&self.0);
358-
#[cfg(not(feature = "luau"))]
359-
let res = ffi::lua_getinfo(state, cstr!(">Sn"), &mut ar);
366+
#[cfg(not(feature = "luau"))] // TODO: cfg for u
367+
let res = ffi::lua_getinfo(state, cstr!(">Snu"), &mut ar);
360368
#[cfg(feature = "luau")]
361369
let res = ffi::lua_getinfo(state, -1, cstr!("sn"), &mut ar);
362370
mlua_assert!(res != 0, "lua_getinfo failed with `>Sn`");
@@ -381,6 +389,11 @@ impl Function {
381389
last_line_defined: linenumber_to_usize(ar.lastlinedefined),
382390
#[cfg(feature = "luau")]
383391
last_line_defined: None,
392+
#[cfg(not(feature = "lua51"))]
393+
num_params: ar.nparams as _,
394+
#[cfg(not(feature = "lua51"))]
395+
is_vararg: ar.isvararg != 0,
396+
nups: ar.nups as _,
384397
}
385398
}
386399
}

0 commit comments

Comments
 (0)