fix(lua): add Delta object

This commit is contained in:
əlemi 2024-10-03 03:41:28 +02:00 committed by alemi.dev
parent 29fde1ad24
commit b821cdc152
2 changed files with 19 additions and 0 deletions

View file

@ -1,4 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use crate::api::change::{Acknowledgeable, Delta};
use crate::buffer::controller::BufferAck;
use mlua::prelude::*; use mlua::prelude::*;
use mlua_codemp_patch as mlua; use mlua_codemp_patch as mlua;
@ -59,3 +61,16 @@ impl LuaUserData for CodempTextChange {
methods.add_method("apply", |_, this, (txt,): (String,)| Ok(this.apply(&txt))); methods.add_method("apply", |_, this, (txt,): (String,)| Ok(this.apply(&txt)));
} }
} }
impl LuaUserData for Delta<BufferAck> {
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("change", |_, this| Ok(this.change.clone()));
fields.add_field_method_get("ack", |_, this| Ok(this.ack.clone()));
}
}
impl LuaUserData for BufferAck {
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
methods.add_method_mut("send", |_, this, ()| Ok(this.send()));
}
}

View file

@ -1,5 +1,7 @@
use crate::ext::IgnorableError; use crate::ext::IgnorableError;
use crate::prelude::*; use crate::prelude::*;
use crate::api::change::Delta;
use crate::buffer::controller::BufferAck;
use mlua::prelude::*; use mlua::prelude::*;
use mlua_codemp_patch as mlua; use mlua_codemp_patch as mlua;
@ -111,4 +113,6 @@ callback_args! {
MaybeCursor: Option<CodempCursor>, MaybeCursor: Option<CodempCursor>,
TextChange: CodempTextChange, TextChange: CodempTextChange,
MaybeTextChange: Option<CodempTextChange>, MaybeTextChange: Option<CodempTextChange>,
Delta: Delta<BufferAck>,
MaybeDelta: Option<Delta<BufferAck>>,
} }