@@ -5,11 +5,11 @@ use std::io::Result as IoResult;
55use std:: path:: { Path , PathBuf } ;
66use std:: string:: String as StdString ;
77
8- use crate :: error:: { Error , ErrorContext , Result } ;
8+ use crate :: error:: { Error , Result } ;
99use crate :: function:: Function ;
1010use crate :: state:: { Lua , WeakLua } ;
1111use crate :: table:: Table ;
12- use crate :: value:: { FromLuaMulti , IntoLua , IntoLuaMulti } ;
12+ use crate :: value:: { FromLuaMulti , IntoLuaMulti } ;
1313
1414/// Trait for types [loadable by Lua] and convertible to a [`Chunk`]
1515///
@@ -322,13 +322,8 @@ impl<'a> Chunk<'a> {
322322 /// All global variables (including the standard library!) are looked up in `_ENV`, so it may be
323323 /// necessary to populate the environment in order for scripts using custom environments to be
324324 /// 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) ) ;
332327 self
333328 }
334329
@@ -451,7 +446,7 @@ impl<'a> Chunk<'a> {
451446 let name = Self :: convert_name ( self . name ) ?;
452447 self . lua
453448 . 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 ( ) )
455450 }
456451
457452 /// Compiles the chunk and changes mode to binary.
@@ -532,9 +527,12 @@ impl<'a> Chunk<'a> {
532527 . unwrap_or ( source) ;
533528
534529 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)
538536 }
539537
540538 fn detect_mode ( & self ) -> ChunkMode {
0 commit comments