Started work on generating definitions
This commit is contained in:
parent
113f9f926c
commit
e30b8e6608
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
.env
|
||||
/definitions/generated
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::DeriveInput;
|
||||
|
@ -24,5 +27,19 @@ pub fn impl_lua_device_macro(ast: &DeriveInput) -> TokenStream {
|
|||
}
|
||||
};
|
||||
|
||||
let def = format!(
|
||||
r#"--- @meta
|
||||
--- @class {name}
|
||||
{name} = {{}}
|
||||
--- @param config {name}Config
|
||||
--- @return Config
|
||||
function {name}.new(config) end"#
|
||||
);
|
||||
|
||||
File::create(format!("./definitions/generated/{name}.lua"))
|
||||
.unwrap()
|
||||
.write_all(def.as_bytes())
|
||||
.unwrap();
|
||||
|
||||
gen
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use itertools::Itertools;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{quote, quote_spanned};
|
||||
|
@ -276,5 +279,15 @@ pub fn impl_lua_device_config_macro(ast: &DeriveInput) -> TokenStream {
|
|||
}
|
||||
};
|
||||
|
||||
let mut def = format!("--- @meta\n--- @class {name}\n");
|
||||
for field in fields {
|
||||
def += &format!("--- @field {} any\n", field.ident.clone().unwrap())
|
||||
}
|
||||
|
||||
File::create(format!("./definitions/generated/{name}.lua"))
|
||||
.unwrap()
|
||||
.write_all(def.as_bytes())
|
||||
.unwrap();
|
||||
|
||||
impl_from_lua
|
||||
}
|
||||
|
|
27
definitions/definitions.lua
Normal file
27
definitions/definitions.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
--- @meta
|
||||
|
||||
automation = {}
|
||||
|
||||
--- @class Device
|
||||
--- @class Config
|
||||
|
||||
--- @class DeviceManager
|
||||
automation.device_manager = {}
|
||||
|
||||
--- @class MqttClient
|
||||
automation.mqtt_client = {}
|
||||
|
||||
--- @param identifier string
|
||||
--- @param config Config
|
||||
--- @return Device
|
||||
function automation.device_manager:create(identifier, config) end
|
||||
|
||||
--- @class DebugBridge
|
||||
DebugBridge = {}
|
||||
|
||||
--- @class DebugBridgeConfig
|
||||
--- @field topic string
|
||||
|
||||
--- @param config DebugBridgeConfig
|
||||
--- @return Config
|
||||
function DebugBridge.new(config) end
|
Loading…
Reference in New Issue
Block a user