@@ -8,7 +8,8 @@ use crate::table::Table;
88use crate :: traits:: { FromLuaMulti , IntoLua , IntoLuaMulti , LuaNativeFn , LuaNativeFnMut } ;
99use crate :: types:: { Callback , LuaType , MaybeSend , ValueRef } ;
1010use crate :: util:: {
11- assert_stack, check_stack, linenumber_to_usize, pop_error, ptr_to_lossy_str, ptr_to_str, StackGuard ,
11+ assert_stack, check_stack, linenumber_to_usize, pop_error, ptr_to_lossy_str, ptr_to_str,
12+ StackGuard ,
1213} ;
1314use crate :: value:: Value ;
1415
@@ -50,6 +51,15 @@ pub struct FunctionInfo {
5051 pub line_defined : Option < usize > ,
5152 /// The line number where the definition of the function ends (not set by Luau).
5253 pub last_line_defined : Option < usize > ,
54+ /// Number of function parameters
55+ #[ cfg( any( not( any( feature = "lua51" , feature = "luajit" ) ) , doc) ) ]
56+ pub num_params : usize ,
57+ /// True if function accepts variable args
58+ #[ cfg( any( not( any( feature = "lua51" , feature = "luajit" ) ) , doc) ) ]
59+ pub is_vararg : bool ,
60+ /// Number of upvalues
61+ #[ cfg( any( not( feature = "luau" ) , doc) ) ]
62+ pub nups : usize ,
5363}
5464
5565/// Luau function coverage snapshot.
@@ -343,7 +353,8 @@ impl Function {
343353
344354 /// Returns information about the function.
345355 ///
346- /// Corresponds to the `>Sn` what mask for [`lua_getinfo`] when applied to the function.
356+ /// Corresponds to the `>Snu` (`>Sn` for Luau) what mask for
357+ /// [`lua_getinfo`] when applied to the function.
347358 ///
348359 /// [`lua_getinfo`]: https://www.lua.org/manual/5.4/manual.html#lua_getinfo
349360 pub fn info ( & self ) -> FunctionInfo {
@@ -356,7 +367,7 @@ impl Function {
356367 let mut ar: ffi:: lua_Debug = mem:: zeroed ( ) ;
357368 lua. push_ref ( & self . 0 ) ;
358369 #[ cfg( not( feature = "luau" ) ) ]
359- let res = ffi:: lua_getinfo ( state, cstr ! ( ">Sn " ) , & mut ar) ;
370+ let res = ffi:: lua_getinfo ( state, cstr ! ( ">Snu " ) , & mut ar) ;
360371 #[ cfg( feature = "luau" ) ]
361372 let res = ffi:: lua_getinfo ( state, -1 , cstr ! ( "sn" ) , & mut ar) ;
362373 mlua_assert ! ( res != 0 , "lua_getinfo failed with `>Sn`" ) ;
@@ -381,6 +392,12 @@ impl Function {
381392 last_line_defined : linenumber_to_usize ( ar. lastlinedefined ) ,
382393 #[ cfg( feature = "luau" ) ]
383394 last_line_defined : None ,
395+ #[ cfg( not( any( feature = "lua51" , feature = "luajit" ) ) ) ]
396+ num_params : ar. nparams as usize ,
397+ #[ cfg( not( any( feature = "lua51" , feature = "luajit" ) ) ) ]
398+ is_vararg : ar. isvararg != 0 ,
399+ #[ cfg( not( feature = "luau" ) ) ]
400+ nups : ar. nups as usize ,
384401 }
385402 }
386403 }
@@ -548,7 +565,9 @@ impl Function {
548565 {
549566 let func = RefCell :: new ( func) ;
550567 WrappedFunction ( Box :: new ( move |lua, nargs| unsafe {
551- let mut func = func. try_borrow_mut ( ) . map_err ( |_| Error :: RecursiveMutCallback ) ?;
568+ let mut func = func
569+ . try_borrow_mut ( )
570+ . map_err ( |_| Error :: RecursiveMutCallback ) ?;
552571 let args = A :: from_stack_args ( nargs, 1 , None , lua) ?;
553572 func. call ( args) ?. push_into_stack_multi ( lua)
554573 } ) )
@@ -583,7 +602,9 @@ impl Function {
583602 {
584603 let func = RefCell :: new ( func) ;
585604 WrappedFunction ( Box :: new ( move |lua, nargs| unsafe {
586- let mut func = func. try_borrow_mut ( ) . map_err ( |_| Error :: RecursiveMutCallback ) ?;
605+ let mut func = func
606+ . try_borrow_mut ( )
607+ . map_err ( |_| Error :: RecursiveMutCallback ) ?;
587608 let args = A :: from_stack_args ( nargs, 1 , None , lua) ?;
588609 func. call ( args) . push_into_stack_multi ( lua)
589610 } ) )
@@ -645,7 +666,9 @@ impl IntoLua for WrappedFunction {
645666impl IntoLua for WrappedAsyncFunction {
646667 #[ inline]
647668 fn into_lua ( self , lua : & Lua ) -> Result < Value > {
648- lua. lock ( ) . create_async_callback ( self . 0 ) . map ( Value :: Function )
669+ lua. lock ( )
670+ . create_async_callback ( self . 0 )
671+ . map ( Value :: Function )
649672 }
650673}
651674
0 commit comments