Skip to content

Commit d25f2fc

Browse files
committed
Take Table instead of impl IntoLua in Chunk::set_environment()
1 parent 104e242 commit d25f2fc

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/chunk.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::io::Result as IoResult;
55
use std::path::{Path, PathBuf};
66
use std::string::String as StdString;
77

8-
use crate::error::{Error, ErrorContext, Result};
8+
use crate::error::{Error, Result};
99
use crate::function::Function;
1010
use crate::state::{Lua, WeakLua};
1111
use 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 {

src/state/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl RawLua {
301301
pub(crate) fn load_chunk(
302302
&self,
303303
name: Option<&CStr>,
304-
env: Option<Table>,
304+
env: Option<&Table>,
305305
mode: Option<ChunkMode>,
306306
source: &[u8],
307307
) -> Result<Function> {

0 commit comments

Comments
 (0)