mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat(lua): .event(), userdata for WorkspaceEvent
This commit is contained in:
parent
3e37d4ffe3
commit
889f745dd4
1 changed files with 15 additions and 0 deletions
|
@ -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("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) {
|
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 {
|
impl LuaUserData for CodempCursorController {
|
||||||
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
methods.add_meta_method(LuaMetaMethod::ToString, |_, this, ()| Ok(format!("{:?}", this)));
|
methods.add_meta_method(LuaMetaMethod::ToString, |_, this, ()| Ok(format!("{:?}", this)));
|
||||||
|
|
Loading…
Reference in a new issue