Skip to content

Commit bc2808f

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

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/function.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ 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(any(feature = "lua51", feature = "luajit")), doc))]
55+
pub num_params: usize,
56+
/// True if function accepts variable args
57+
#[cfg(any(not(any(feature = "lua51", feature = "luajit")), doc))]
58+
pub is_vararg: bool,
59+
/// Number of upvalues
60+
#[cfg(any(not(feature = "luau"), doc))]
61+
pub nups: usize,
5362
}
5463

5564
/// Luau function coverage snapshot.
@@ -343,7 +352,8 @@ impl Function {
343352

344353
/// Returns information about the function.
345354
///
346-
/// Corresponds to the `>Sn` what mask for [`lua_getinfo`] when applied to the function.
355+
/// Corresponds to the `>Snu` (`>Sn` for Luau) what mask for
356+
/// [`lua_getinfo`] when applied to the function.
347357
///
348358
/// [`lua_getinfo`]: https://www.lua.org/manual/5.4/manual.html#lua_getinfo
349359
pub fn info(&self) -> FunctionInfo {
@@ -356,7 +366,7 @@ impl Function {
356366
let mut ar: ffi::lua_Debug = mem::zeroed();
357367
lua.push_ref(&self.0);
358368
#[cfg(not(feature = "luau"))]
359-
let res = ffi::lua_getinfo(state, cstr!(">Sn"), &mut ar);
369+
let res = ffi::lua_getinfo(state, cstr!(">Snu"), &mut ar);
360370
#[cfg(feature = "luau")]
361371
let res = ffi::lua_getinfo(state, -1, cstr!("sn"), &mut ar);
362372
mlua_assert!(res != 0, "lua_getinfo failed with `>Sn`");
@@ -381,6 +391,12 @@ impl Function {
381391
last_line_defined: linenumber_to_usize(ar.lastlinedefined),
382392
#[cfg(feature = "luau")]
383393
last_line_defined: None,
394+
#[cfg(not(any(feature = "lua51", feature = "luajit")))]
395+
num_params: ar.nparams as usize,
396+
#[cfg(not(any(feature = "lua51", feature = "luajit")))]
397+
is_vararg: ar.isvararg != 0,
398+
#[cfg(not(feature = "luau"))]
399+
nups: ar.nups as usize,
384400
}
385401
}
386402
}

0 commit comments

Comments
 (0)