feat(lua): .event(), userdata for WorkspaceEvent

This commit is contained in:
əlemi 2024-08-15 03:42:25 +02:00
parent 3e37d4ffe3
commit 889f745dd4
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -104,6 +104,8 @@ impl LuaUserData for CodempWorkspace {
});
methods.add_method("get_buffer", |_, this, (name,):(String,)| Ok(this.buffer_by_name(&name)));
methods.add_method("event", |_, this, ()| Ok(RT.block_on(this.event())?));
}
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
@ -113,6 +115,19 @@ impl LuaUserData for CodempWorkspace {
}
}
impl LuaUserData for CodempEvent {
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_method_get("type", |_, this| match this {
CodempEvent::FileTreeUpdated => Ok("filetree"),
CodempEvent::UserJoin(_) | CodempEvent::UserLeave(_) => Ok("user"),
});
fields.add_field_method_get("value", |_, this| match this {
CodempEvent::FileTreeUpdated => Ok(None),
CodempEvent::UserJoin(x) | CodempEvent::UserLeave(x) => Ok(Some(x.clone())),
});
}
}
impl LuaUserData for CodempCursorController {
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_meta_method(LuaMetaMethod::ToString, |_, this, ()| Ok(format!("{:?}", this)));