Merge pull request #54 from Timidger/feature/debug-unsafe-lib

Added ability to load debug lib, Fixes #52
This commit is contained in:
kyren 2017-11-04 02:57:03 -04:00 committed by GitHub
commit 33eff0e132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -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.
///
/// The source can be named by setting the `name` parameter. This is generally recommended as it

View File

@ -14,6 +14,23 @@ fn test_load() {
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]
fn test_exec() {
let lua = Lua::new();