chore(lua): style

This commit is contained in:
əlemi 2024-10-06 10:19:22 +02:00 committed by alemi.dev
parent 45864e19f6
commit d66b25deb4
4 changed files with 22 additions and 37 deletions

View file

@ -12,10 +12,9 @@ impl LuaUserData for CodempBufferController {
Ok(format!("{:?}", this)) Ok(format!("{:?}", this))
}); });
methods.add_method("send", |_, this, (change,): (CodempTextChange,)| { methods.add_method("send", |_, this, (change,): (CodempTextChange,)|
this.send(change)?; Ok(this.send(change)?)
Ok(()) );
});
methods.add_method( methods.add_method(
"try_recv", "try_recv",
@ -29,16 +28,12 @@ impl LuaUserData for CodempBufferController {
|_, this, ()| a_sync! { this => this.content().await? }, |_, this, ()| a_sync! { this => this.content().await? },
); );
methods.add_method("clear_callback", |_, this, ()| { methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
this.clear_callback(); methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
Ok(()) Ok(this.callback(move |controller: CodempBufferController|
});
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
this.callback(move |controller: CodempBufferController| {
super::ext::callback().invoke(cb.clone(), controller) super::ext::callback().invoke(cb.clone(), controller)
}); ))
Ok(()) );
});
} }
} }

View file

@ -13,8 +13,7 @@ impl LuaUserData for CodempCursorController {
}); });
methods.add_method("send", |_, this, (cursor,): (CodempCursor,)| { methods.add_method("send", |_, this, (cursor,): (CodempCursor,)| {
this.send(cursor)?; Ok(this.send(cursor)?)
Ok(())
}); });
methods.add_method( methods.add_method(
"try_recv", "try_recv",
@ -23,16 +22,12 @@ impl LuaUserData for CodempCursorController {
methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? }); methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? });
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? }); methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
methods.add_method("clear_callback", |_, this, ()| { methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
this.clear_callback(); methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
Ok(()) Ok(this.callback(move |controller: CodempCursorController|
});
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
this.callback(move |controller: CodempCursorController| {
super::ext::callback().invoke(cb.clone(), controller) super::ext::callback().invoke(cb.clone(), controller)
}); ))
Ok(()) );
});
} }
} }

View file

@ -51,10 +51,7 @@ impl LuaUserData for Promise {
}); });
methods.add_method_mut("cancel", |_, this, ()| match this.0.take() { methods.add_method_mut("cancel", |_, this, ()| match this.0.take() {
None => Err(LuaError::runtime("Promise already awaited")), None => Err(LuaError::runtime("Promise already awaited")),
Some(x) => { Some(x) => Ok(x.abort()),
x.abort();
Ok(())
}
}); });
methods.add_method_mut("and_then", |_, this, (cb,): (LuaFunction,)| { methods.add_method_mut("and_then", |_, this, (cb,): (LuaFunction,)| {
match this.0.take() { match this.0.take() {

View file

@ -60,17 +60,15 @@ impl LuaUserData for CodempWorkspace {
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? }); methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| { methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
this.callback(move |controller: CodempWorkspace| { Ok(this.callback(move |controller: CodempWorkspace|
super::ext::callback().invoke(cb.clone(), controller) super::ext::callback().invoke(cb.clone(), controller)
}); ))
Ok(()) );
});
methods.add_method("clear_callbacl", |_, this, ()| { methods.add_method("clear_callbacl", |_, this, ()|
this.clear_callback(); Ok(this.clear_callback())
Ok(()) );
});
} }
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) { fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {