Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/awesome/object.rs b/src/awesome/object.rs
- index 9caf9e6..f3015c2 100644
- --- a/src/awesome/object.rs
- +++ b/src/awesome/object.rs
- @@ -11,12 +11,12 @@ use super::property::Property;
- /// All Lua objects can be cast to this.
- #[derive(Clone, Debug)]
- pub struct Object<'lua> {
- - table: Table<'lua>
- + object: AnyUserData<'lua>
- }
- -impl <'lua> From<Table<'lua>> for Object<'lua> {
- - fn from(table: Table<'lua>) -> Self {
- - Object { table }
- +impl <'lua> From<AnyUserData<'lua>> for Object<'lua> {
- + fn from(object: AnyUserData<'lua>) -> Self {
- + Object { object }
- }
- }
- @@ -132,10 +132,13 @@ pub trait Objectable<'lua, T, S: UserData + Default + Display + Clone> {
- __metatable = {}
- }
- */
- - let object = S::default();
- + let object = match S::default().to_lua(lua)? {
- + rlua::Value::UserData(data) => data,
- + _ => unreachable!()
- + };
- // TODO Increment the instance count
- let wrapper_table = lua.create_table()?;
- - wrapper_table.set("userdata", object)?;
- + //wrapper_table.set("userdata", object)?;
- let data_table = lua.create_table()?;
- wrapper_table.set("data", data_table)?;
- let meta = lua.create_table()?;
- @@ -153,8 +156,9 @@ pub trait Objectable<'lua, T, S: UserData + Default + Display + Clone> {
- Ok(format!("{}", wrapper_table.get::<_, S>("userdata")?))
- })?)?;
- wrapper_table.set_metatable(Some(meta));
- + object.set_user_value(wrapper_table);
- // TODO Emit new signal event
- - let object = Object { table: wrapper_table };
- + let object = Object { object };
- Ok(ObjectBuilder { object, lua })
- }
- }
- @@ -166,33 +170,12 @@ impl <'lua> ToLua<'lua> for Object<'lua> {
- }
- impl <'lua> Object<'lua> {
- - /// Coerces a concrete object into a generic object.
- - ///
- - /// This requires a check to ensure data integrity, and it's often useless.
- - /// Please don't use this method unless you need to.
- - #[allow(dead_code)]
- - #[deprecated]
- - pub fn to_object<T, S, O>(obj: O) -> Self
- - where S: Default + Display + Clone + UserData,
- - O: Objectable<'lua, T, S>
- - {
- - let table = obj.get_table();
- - assert!(table.contains_key("userdata")
- - .expect("Could not get userdata field of object wrapper table"),
- - "Table did not have special \"userdata\" field");
- - assert!(table.contains_key("data")
- - .expect("Could not get data field of object wrapper table"),
- - "Table did not have special \"data\" field"
- - );
- - Object { table }
- - }
- -
- pub fn signals(&self) -> rlua::Result<rlua::Table<'lua>> {
- self.table.get::<_, Table>("signals")
- }
- - pub fn table(self) -> rlua::Table<'lua> {
- - self.table
- + pub fn table(&self) -> rlua::Result<Table<'lua>> {
- + self.object.get_user_value::<Table<'lua>>()
- }
- }
Add Comment
Please, Sign In to add comment