Started work on generating definitions

This commit is contained in:
2024-04-26 06:07:20 +02:00
parent 67ed13463a
commit 2f494a7dd6
4 changed files with 58 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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
}