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 {
349
349
/// The constants are used by the compiler to optimize the generated bytecode.
350
350
/// Optimization level must be at least 2 for this to have any effect.
351
351
///
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 .
354
354
#[ must_use]
355
355
pub fn add_library_constant (
356
356
mut self ,
357
- lib : impl Into < StdString > ,
358
- member : impl Into < StdString > ,
357
+ name : impl AsRef < str > ,
359
358
r#const : impl Into < CompileConstant > ,
360
359
) -> 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
+
362
365
if !self . libraries_with_known_members . contains ( & lib) {
363
366
self . libraries_with_known_members . push ( lib. clone ( ) ) ;
364
367
}
Original file line number Diff line number Diff line change @@ -145,10 +145,10 @@ fn test_compiler_library_constants() {
145
145
146
146
let compiler = Compiler :: new ( )
147
147
. 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" ) ;
152
152
153
153
let lua = Lua :: new ( ) ;
154
154
lua. set_compiler ( compiler) ;
You can’t perform that action at this time.
0 commit comments