Merge pull request #54 from Timidger/feature/debug-unsafe-lib
Added ability to load debug lib, Fixes #52
This commit is contained in:
commit
33eff0e132
10
src/lua.rs
10
src/lua.rs
|
@ -557,6 +557,16 @@ impl Lua {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads the Lua debug library.
|
||||||
|
///
|
||||||
|
/// The debug library is very unsound, loading it and using it breaks all
|
||||||
|
/// the guarantees of rlua.
|
||||||
|
pub unsafe fn load_debug(&self) {
|
||||||
|
check_stack(self.state, 1);
|
||||||
|
ffi::luaL_requiref(self.state, cstr!("debug"), ffi::luaopen_debug, 1);
|
||||||
|
ffi::lua_pop(self.state, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/// Loads a chunk of Lua code and returns it as a function.
|
/// Loads a chunk of Lua code and returns it as a function.
|
||||||
///
|
///
|
||||||
/// The source can be named by setting the `name` parameter. This is generally recommended as it
|
/// The source can be named by setting the `name` parameter. This is generally recommended as it
|
||||||
|
|
17
src/tests.rs
17
src/tests.rs
|
@ -14,6 +14,23 @@ fn test_load() {
|
||||||
assert!(lua.load("§$%§&$%&", None).is_err());
|
assert!(lua.load("§$%§&$%&", None).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_load_debug() {
|
||||||
|
let lua = Lua::new();
|
||||||
|
lua.exec::<()>("assert(debug == nil)", None).unwrap();
|
||||||
|
unsafe {
|
||||||
|
lua.load_debug();
|
||||||
|
}
|
||||||
|
match lua.eval("debug", None).unwrap() {
|
||||||
|
Value::Table(_) => {},
|
||||||
|
val => {
|
||||||
|
panic!("Expected table for debug library, got {:#?}", val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let traceback_output = lua.eval::<String>("debug.traceback()", None).unwrap();
|
||||||
|
assert_eq!(traceback_output.split("\n").next(), "stack traceback:".into());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exec() {
|
fn test_exec() {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
|
|
Loading…
Reference in New Issue