made client Lua scriptable

This commit is contained in:
michael-bailey 2022-03-03 10:48:47 +00:00
parent b33db558e7
commit 0681f2ea65
1 changed files with 30 additions and 1 deletions

View File

@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
use async_trait::async_trait;
use mlua::prelude::LuaUserData;
use mlua::{UserDataFields, UserDataMethods};
use tokio::select;
use tokio::sync::mpsc::{channel, Receiver, Sender};
@ -184,7 +186,7 @@ impl<Out> PartialOrd for Client<Out>
}
}
impl<Out> Ord for Client<Out>
impl<Out: 'static> Ord for Client<Out>
where
Out: From<ClientMessage> + Send
{
@ -193,6 +195,33 @@ impl<Out> Ord for Client<Out>
}
}
pub struct ClientLua<Out: 'static>(pub Arc<Client<Out>>)
where
Out: From<ClientMessage> + Send;
impl<Out: 'static> LuaUserData for ClientLua<Out>
where
Out: From<ClientMessage> + Send
{
fn add_fields<'lua, F: UserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_method_get("uuid", |_lua, this| {
Ok(this.0.details.uuid.to_string())
});
fields.add_field_method_get("username", |_lua, this| {
Ok(this.0.details.username.to_string())
});
fields.add_field_method_get("address", |_lua, this| {
Ok(this.0.details.address.to_string())
});
}
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(_methods: &mut M) {
}
}
#[cfg(test)]
mod test {
use std::io::Error;