summaryrefslogtreecommitdiff
path: root/src/conversion.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2017-06-23 15:24:03 -0400
committerkyren <kerriganw@gmail.com>2017-06-23 15:24:03 -0400
commit8e3a9f0e843e5d82114e990f4985f37ed825b181 (patch)
tree5e8b8f3cc7c89ab6f903ae337fe784e41d21db68 /src/conversion.rs
parent7b7f7f36fc40af8c1c146b9149ba48e103588eac (diff)
downloadmlua-8e3a9f0e843e5d82114e990f4985f37ed825b181.zip
Add ToString metamethod, make LuaError implement LuaUserData
LuaError implementing LuaUserData makes it easy to return LuaResult from a callback to implement callback functions that can error.
Diffstat (limited to 'src/conversion.rs')
-rw-r--r--src/conversion.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/conversion.rs b/src/conversion.rs
index 5ef0050..c6e74f1 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -1,5 +1,6 @@
use std::collections::{HashMap, BTreeMap};
use std::hash::Hash;
+use error_chain::ChainedError;
use error::*;
use lua::*;
@@ -263,3 +264,15 @@ impl<'lua, T: FromLua<'lua>> FromLua<'lua> for Option<T> {
}
}
}
+
+impl LuaUserDataType for LuaError {
+ fn add_methods(methods: &mut LuaUserDataMethods<Self>) {
+ methods.add_method("backtrace", |lua, err, _| {
+ lua.pack(format!("{}", err.display()))
+ });
+
+ methods.add_meta_method(LuaMetaMethod::ToString, |lua, err, _| {
+ lua.pack(err.to_string())
+ });
+ }
+}