feat: Added/expanded Typed impls
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1101,7 +1101,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lua_typed"
|
name = "lua_typed"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#d5d6fc1638bd108514899a792ee64335af50fc8b"
|
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#08f5c4533a93131e8eda6702c062fb841d14d4e1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eui48",
|
"eui48",
|
||||||
"lua_typed_macro",
|
"lua_typed_macro",
|
||||||
@@ -1110,7 +1110,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "lua_typed_macro"
|
name = "lua_typed_macro"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#d5d6fc1638bd108514899a792ee64335af50fc8b"
|
source = "git+https://git.huizinga.dev/Dreaded_X/lua_typed#08f5c4533a93131e8eda6702c062fb841d14d4e1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"convert_case",
|
"convert_case",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ pub struct ActionCallback<P> {
|
|||||||
_parameters: PhantomData<P>,
|
_parameters: PhantomData<P>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Typed for ActionCallback<()> {
|
||||||
|
fn type_name() -> String {
|
||||||
|
"fun() | fun()[]".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A: Typed> Typed for ActionCallback<A> {
|
impl<A: Typed> Typed for ActionCallback<A> {
|
||||||
fn type_name() -> String {
|
fn type_name() -> String {
|
||||||
let type_name = A::type_name();
|
let type_name = A::type_name();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use lua_typed::Typed;
|
|||||||
use rumqttc::{MqttOptions, Transport};
|
use rumqttc::{MqttOptions, Transport};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize, Typed)]
|
||||||
pub struct MqttConfig {
|
pub struct MqttConfig {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
|
use lua_typed::Typed;
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
use tokio_cron_scheduler::{Job, JobScheduler};
|
use tokio_cron_scheduler::{Job, JobScheduler};
|
||||||
use tracing::{debug, instrument, trace};
|
use tracing::{debug, instrument, trace};
|
||||||
@@ -142,3 +143,9 @@ impl mlua::UserData for DeviceManager {
|
|||||||
methods.add_method("event_channel", |_lua, this, ()| Ok(this.event_channel()))
|
methods.add_method("event_channel", |_lua, this, ()| Ok(this.event_channel()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Typed for DeviceManager {
|
||||||
|
fn type_name() -> String {
|
||||||
|
"DeviceManager".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use lua_typed::Typed;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@@ -74,3 +75,44 @@ impl mlua::UserData for Timeout {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Typed for Timeout {
|
||||||
|
fn type_name() -> String {
|
||||||
|
"Timeout".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_header() -> Option<String> {
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
Some(format!("---@class {type_name}\nlocal {type_name}\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_members() -> Option<String> {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
|
||||||
|
output += &format!(
|
||||||
|
"---@async\n---@param timeout number\n---@param callback {}\nfunction {type_name}:start(timeout, callback) end\n",
|
||||||
|
ActionCallback::<()>::type_name()
|
||||||
|
);
|
||||||
|
|
||||||
|
output += &format!("---@async\nfunction {type_name}:cancel() end\n",);
|
||||||
|
|
||||||
|
output +=
|
||||||
|
&format!("---@async\n---@return boolean\nfunction {type_name}:is_waiting() end\n",);
|
||||||
|
|
||||||
|
Some(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_footer() -> Option<String> {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
|
||||||
|
output += &format!("utils.{type_name} = {{}}\n");
|
||||||
|
output += &format!("---@return {type_name}\n");
|
||||||
|
output += &format!("function utils.{type_name}.new() end\n");
|
||||||
|
|
||||||
|
Some(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use mlua::FromLua;
|
|||||||
use rumqttc::{AsyncClient, Event, EventLoop, Incoming};
|
use rumqttc::{AsyncClient, Event, EventLoop, Incoming};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
|
use crate::config::MqttConfig;
|
||||||
use crate::event::{self, EventChannel};
|
use crate::event::{self, EventChannel};
|
||||||
|
|
||||||
#[derive(Debug, Clone, FromLua)]
|
#[derive(Debug, Clone, FromLua)]
|
||||||
@@ -14,6 +15,36 @@ impl Typed for WrappedAsyncClient {
|
|||||||
fn type_name() -> String {
|
fn type_name() -> String {
|
||||||
"AsyncClient".into()
|
"AsyncClient".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_header() -> Option<String> {
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
Some(format!("---@class {type_name}\nlocal {type_name}\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_members() -> Option<String> {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
|
||||||
|
output += &format!(
|
||||||
|
"---@async\n---@param topic string\n---@param message table?\nfunction {type_name}:send_message(topic, message) end\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
Some(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_footer() -> Option<String> {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
let type_name = Self::type_name();
|
||||||
|
|
||||||
|
output += &format!("mqtt.{type_name} = {{}}\n");
|
||||||
|
output += &format!("---@param config {}\n", MqttConfig::type_name());
|
||||||
|
output += &format!("---@return {type_name}\n");
|
||||||
|
output += "function mqtt.new(config) end\n";
|
||||||
|
|
||||||
|
Some(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for WrappedAsyncClient {
|
impl Deref for WrappedAsyncClient {
|
||||||
|
|||||||
Reference in New Issue
Block a user