@@ -5,11 +5,11 @@ use std::io::Result as IoResult;
5
5
use std:: path:: { Path , PathBuf } ;
6
6
use std:: string:: String as StdString ;
7
7
8
- use crate :: error:: { Error , ErrorContext , Result } ;
8
+ use crate :: error:: { Error , Result } ;
9
9
use crate :: function:: Function ;
10
10
use crate :: state:: { Lua , WeakLua } ;
11
11
use crate :: table:: Table ;
12
- use crate :: value:: { FromLuaMulti , IntoLua , IntoLuaMulti } ;
12
+ use crate :: value:: { FromLuaMulti , IntoLuaMulti } ;
13
13
14
14
/// Trait for types [loadable by Lua] and convertible to a [`Chunk`]
15
15
///
@@ -322,13 +322,8 @@ impl<'a> Chunk<'a> {
322
322
/// All global variables (including the standard library!) are looked up in `_ENV`, so it may be
323
323
/// necessary to populate the environment in order for scripts using custom environments to be
324
324
/// useful.
325
- pub fn set_environment ( mut self , env : impl IntoLua ) -> Self {
326
- let guard = self . lua . lock ( ) ;
327
- let lua = guard. lua ( ) ;
328
- self . env = env
329
- . into_lua ( lua)
330
- . and_then ( |val| lua. unpack ( val) )
331
- . context ( "bad environment value" ) ;
325
+ pub fn set_environment ( mut self , env : Table ) -> Self {
326
+ self . env = Ok ( Some ( env) ) ;
332
327
self
333
328
}
334
329
@@ -451,7 +446,7 @@ impl<'a> Chunk<'a> {
451
446
let name = Self :: convert_name ( self . name ) ?;
452
447
self . lua
453
448
. lock ( )
454
- . load_chunk ( Some ( & name) , self . env ?, self . mode , self . source ?. as_ref ( ) )
449
+ . load_chunk ( Some ( & name) , self . env ?. as_ref ( ) , self . mode , self . source ?. as_ref ( ) )
455
450
}
456
451
457
452
/// Compiles the chunk and changes mode to binary.
@@ -532,9 +527,12 @@ impl<'a> Chunk<'a> {
532
527
. unwrap_or ( source) ;
533
528
534
529
let name = Self :: convert_name ( self . name . clone ( ) ) ?;
535
- self . lua
536
- . lock ( )
537
- . load_chunk ( Some ( & name) , self . env . clone ( ) ?, None , & source)
530
+ let env = match & self . env {
531
+ Ok ( Some ( env) ) => Some ( env) ,
532
+ Ok ( None ) => None ,
533
+ Err ( err) => return Err ( err. clone ( ) ) ,
534
+ } ;
535
+ self . lua . lock ( ) . load_chunk ( Some ( & name) , env, None , & source)
538
536
}
539
537
540
538
fn detect_mode ( & self ) -> ChunkMode {
0 commit comments