@@ -320,47 +320,63 @@ impl ScriptFunctionRegistry {
320320 ) where
321321 F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
322322 {
323- self . register_overload ( namespace, name, func, false , None :: < & ' static str > ) ;
323+ self . register_overload ( namespace, name, func, false , None :: < & ' static str > , None ) ;
324324 }
325325
326326 /// Equivalent to [`ScriptFunctionRegistry::register`] but with the ability to provide documentation for the function.
327327 ///
328328 /// The docstring will be added to the function's metadata and can be accessed at runtime.
329- pub fn register_documented < F , M > (
329+ pub fn register_documented < ' env , F , M > (
330330 & mut self ,
331331 namespace : Namespace ,
332332 name : impl Into < Cow < ' static , str > > ,
333333 func : F ,
334334 docs : & ' static str ,
335335 ) where
336- F : ScriptFunction < ' static , M > + GetFunctionInfo < M > ,
336+ F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
337+ {
338+ self . register_overload ( namespace, name, func, false , Some ( docs) , None ) ;
339+ }
340+
341+ /// Equivalent to [`ScriptFunctionRegistry::register`] but with the ability to provide argument names for the function as well as documentation.
342+ ///
343+ /// The argument names and docstring will be added to the function's metadata and can be accessed at runtime.
344+ pub fn register_with_arg_names < ' env , F , M > (
345+ & mut self ,
346+ namespace : Namespace ,
347+ name : impl Into < Cow < ' static , str > > ,
348+ func : F ,
349+ docs : & ' static str ,
350+ arg_names : & ' static [ & ' static str ] ,
351+ ) where
352+ F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
337353 {
338- self . register_overload ( namespace, name, func, false , Some ( docs) ) ;
354+ self . register_overload ( namespace, name, func, false , Some ( docs) , Some ( arg_names ) ) ;
339355 }
340356
341357 /// Overwrite a function with the given name. If the function does not exist, it will be registered as a new function.
342- pub fn overwrite < F , M > (
358+ pub fn overwrite < ' env , F , M > (
343359 & mut self ,
344360 namespace : Namespace ,
345361 name : impl Into < Cow < ' static , str > > ,
346362 func : F ,
347363 ) where
348- F : ScriptFunction < ' static , M > + GetFunctionInfo < M > ,
364+ F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
349365 {
350- self . register_overload ( namespace, name, func, true , None :: < & ' static str > ) ;
366+ self . register_overload ( namespace, name, func, true , None :: < & ' static str > , None ) ;
351367 }
352368
353369 /// Equivalent to [`ScriptFunctionRegistry::overwrite`] but with the ability to provide documentation for the function.
354- pub fn overwrite_documented < F , M > (
370+ pub fn overwrite_documented < ' env , F , M > (
355371 & mut self ,
356372 namespace : Namespace ,
357373 name : impl Into < Cow < ' static , str > > ,
358374 func : F ,
359375 docs : & ' static str ,
360376 ) where
361- F : ScriptFunction < ' static , M > + GetFunctionInfo < M > ,
377+ F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
362378 {
363- self . register_overload ( namespace, name, func, true , Some ( docs) ) ;
379+ self . register_overload ( namespace, name, func, true , Some ( docs) , None ) ;
364380 }
365381
366382 /// Remove a function from the registry if it exists. Returns the removed function if it was found.
@@ -401,6 +417,7 @@ impl ScriptFunctionRegistry {
401417 func : F ,
402418 overwrite : bool ,
403419 docs : Option < impl Into < Cow < ' static , str > > > ,
420+ arg_names : Option < & ' static [ & ' static str ] > ,
404421 ) where
405422 F : ScriptFunction < ' env , M > + GetFunctionInfo < M > ,
406423 {
@@ -413,6 +430,10 @@ impl ScriptFunctionRegistry {
413430 Some ( docs) => info. with_docs ( docs. into ( ) ) ,
414431 None => info,
415432 } ;
433+ let info = match arg_names {
434+ Some ( arg_names) => info. with_arg_names ( arg_names) ,
435+ None => info,
436+ } ;
416437 let func = func. into_dynamic_script_function ( ) . with_info ( info) ;
417438 self . functions . insert ( FunctionKey { name, namespace } , func) ;
418439 return ;
0 commit comments