mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 23:34:49 +01:00
feat: add close_client helper in lua
This commit is contained in:
parent
898ab22e22
commit
e736646b8c
1 changed files with 14 additions and 0 deletions
|
@ -34,6 +34,19 @@ fn get_client(_: &Lua, (id,): (String,)) -> LuaResult<Option<CodempClient>> {
|
||||||
Ok(STORE.get(&id).map(|x| x.value().clone()))
|
Ok(STORE.get(&id).map(|x| x.value().clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close_client(_: &Lua, (id,): (String,)) -> LuaResult<bool> {
|
||||||
|
if let Some((_id, client)) = STORE.remove(&id) {
|
||||||
|
for ws in client.active_workspaces() {
|
||||||
|
if !client.leave_workspace(&ws) {
|
||||||
|
tracing::warn!("could not leave workspace {ws}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LuaUserData for CodempClient {
|
impl LuaUserData for CodempClient {
|
||||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||||
fields.add_field_method_get("id", |_, this| Ok(this.user_id().to_string()));
|
fields.add_field_method_get("id", |_, this| Ok(this.user_id().to_string()));
|
||||||
|
@ -248,6 +261,7 @@ fn codemp_lua(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
// entrypoint
|
// entrypoint
|
||||||
exports.set("connect", lua.create_function(connect)?)?;
|
exports.set("connect", lua.create_function(connect)?)?;
|
||||||
exports.set("get_client", lua.create_function(get_client)?)?;
|
exports.set("get_client", lua.create_function(get_client)?)?;
|
||||||
|
exports.set("close_client", lua.create_function(close_client)?)?;
|
||||||
|
|
||||||
// runtime
|
// runtime
|
||||||
exports.set("runtime_drive_forever", lua.create_function(runtime_drive_forever)?)?;
|
exports.set("runtime_drive_forever", lua.create_function(runtime_drive_forever)?)?;
|
||||||
|
|
Loading…
Reference in a new issue