File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -349,16 +349,19 @@ impl Compiler {
349349 /// The constants are used by the compiler to optimize the generated bytecode.
350350 /// Optimization level must be at least 2 for this to have any effect.
351351 ///
352- /// The first element of the tuple is the library name,the second is the member name, and the
353- /// third is the constant value .
352+ /// The `name` is a string in the format `lib.member`, where `lib` is the library name
353+ /// and `member` is the member ( constant) name .
354354 #[ must_use]
355355 pub fn add_library_constant (
356356 mut self ,
357- lib : impl Into < StdString > ,
358- member : impl Into < StdString > ,
357+ name : impl AsRef < str > ,
359358 r#const : impl Into < CompileConstant > ,
360359 ) -> Self {
361- let ( lib, member) = ( lib. into ( ) , member. into ( ) ) ;
360+ let Some ( ( lib, member) ) = name. as_ref ( ) . split_once ( '.' ) else {
361+ return self ;
362+ } ;
363+ let ( lib, member) = ( lib. to_owned ( ) , member. to_owned ( ) ) ;
364+
362365 if !self . libraries_with_known_members . contains ( & lib) {
363366 self . libraries_with_known_members . push ( lib. clone ( ) ) ;
364367 }
Original file line number Diff line number Diff line change @@ -145,10 +145,10 @@ fn test_compiler_library_constants() {
145145
146146 let compiler = Compiler :: new ( )
147147 . set_optimization_level ( 2 )
148- . add_library_constant ( "mylib" , " const_bool", true )
149- . add_library_constant ( "mylib" , " const_num", 123.0 )
150- . add_library_constant ( "mylib" , " const_vec", Vector :: zero ( ) )
151- . add_library_constant ( "mylib" , " const_str", "value1" ) ;
148+ . add_library_constant ( "mylib. const_bool" , true )
149+ . add_library_constant ( "mylib. const_num" , 123.0 )
150+ . add_library_constant ( "mylib. const_vec" , Vector :: zero ( ) )
151+ . add_library_constant ( "mylib. const_str" , "value1" ) ;
152152
153153 let lua = Lua :: new ( ) ;
154154 lua. set_compiler ( compiler) ;
You can’t perform that action at this time.
0 commit comments