made client Lua scriptable
This commit is contained in:
parent
b33db558e7
commit
0681f2ea65
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue