Skip to content

Commit 7cf278a

Browse files
committed
appends docs
1 parent 5873f34 commit 7cf278a

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

crates/byondapi-macros/src/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream {
4545

4646
let args = &input.sig.inputs;
4747

48+
let all_docs = input
49+
.attrs
50+
.iter()
51+
.filter(|attr| matches!(attr.style, syn::AttrStyle::Outer))
52+
.filter_map(|attr| match &attr.meta {
53+
syn::Meta::NameValue(nameval) => {
54+
let ident = nameval.path.get_ident()?;
55+
if ident.to_string() == "doc".to_string() {
56+
match &nameval.value {
57+
syn::Expr::Lit(literal) => match &literal.lit {
58+
syn::Lit::Str(docstring) => {
59+
Some(format!("///{}\n", docstring.value(),))
60+
}
61+
_ => None,
62+
},
63+
_ => None,
64+
}
65+
} else {
66+
None
67+
}
68+
}
69+
_ => None,
70+
})
71+
.collect::<String>();
72+
4873
//Check for returns
4974
let func_return = match &input.sig.output {
5075
syn::ReturnType::Default => {
@@ -103,6 +128,7 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream {
103128
proc_path: #p,
104129
func_name: #func_name_ffi_disp,
105130
func_arguments: #arg_names_disp,
131+
docs: #all_docs,
106132
is_variadic: false,
107133
}
108134
});
@@ -125,6 +151,7 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream {
125151
proc_path: #func_name_disp,
126152
func_name: #func_name_ffi_disp,
127153
func_arguments: #arg_names_disp,
154+
docs: #all_docs,
128155
is_variadic: false,
129156
}
130157
});
@@ -172,6 +199,31 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
172199
let func_name_ffi = Ident::new(&func_name_ffi, func_name.span());
173200
let func_name_ffi_disp = quote!(#func_name_ffi).to_string();
174201

202+
let all_docs = input
203+
.attrs
204+
.iter()
205+
.filter(|attr| matches!(attr.style, syn::AttrStyle::Outer))
206+
.filter_map(|attr| match &attr.meta {
207+
syn::Meta::NameValue(nameval) => {
208+
let ident = nameval.path.get_ident()?;
209+
if ident.to_string() == "doc".to_string() {
210+
match &nameval.value {
211+
syn::Expr::Lit(literal) => match &literal.lit {
212+
syn::Lit::Str(docstring) => {
213+
Some(format!("///{}\n", docstring.value(),))
214+
}
215+
_ => None,
216+
},
217+
_ => None,
218+
}
219+
} else {
220+
None
221+
}
222+
}
223+
_ => None,
224+
})
225+
.collect::<String>();
226+
175227
//Check for returns
176228
let func_return = match &input.sig.output {
177229
syn::ReturnType::Default => {
@@ -221,6 +273,7 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
221273
proc_path: #p,
222274
func_name: #func_name_ffi_disp,
223275
func_arguments: "",
276+
docs: #all_docs,
224277
is_variadic: true,
225278
}
226279
});
@@ -243,6 +296,7 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream {
243296
proc_path: #func_name_disp,
244297
func_name: #func_name_ffi_disp,
245298
func_arguments: "",
299+
docs: #all_docs,
246300
is_variadic: true,
247301
}
248302
});

crates/byondapi-rs-test/dm_project/bindings.dm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,73 @@
1111

1212
#define BYONDAPI_TEST (__byondapi_test || __detect_byondapi_test())
1313

14+
///Tests new
1415
/proc/test_new_obj()
1516
return call_ext(BYONDAPI_TEST, "byond:test_new_obj_ffi")()
1617

18+
///Tests lists read
1719
/proc/test_list_read(list)
1820
return call_ext(BYONDAPI_TEST, "byond:test_list_read_ffi")(list)
1921

22+
///Tests non-assoc lists
2023
/proc/test_non_assoc_list(list)
2124
return call_ext(BYONDAPI_TEST, "byond:test_non_assoc_list_ffi")(list)
2225

26+
///Tests ref
2327
/proc/test_ref(turf)
2428
return call_ext(BYONDAPI_TEST, "byond:test_ref_ffi")(turf)
2529

30+
///Tests lists lookup
2631
/proc/test_list_key_lookup(list)
2732
return call_ext(BYONDAPI_TEST, "byond:test_list_key_lookup_ffi")(list)
2833

34+
///Tests length with strings
2935
/proc/test_length_with_str(object)
3036
return call_ext(BYONDAPI_TEST, "byond:test_length_with_str_ffi")(object)
3137

38+
///Tests block
3239
/proc/test_block()
3340
return call_ext(BYONDAPI_TEST, "byond:test_block_ffi")()
3441

42+
///Tests lists length
3543
/proc/test_length_with_list(list)
3644
return call_ext(BYONDAPI_TEST, "byond:test_length_with_list_ffi")(list)
3745

46+
///Tests lists popping
3847
/proc/test_list_pop(list)
3948
return call_ext(BYONDAPI_TEST, "byond:test_list_pop_ffi")(list)
4049

50+
///Tests lists indexing
4151
/proc/test_list_index(list)
4252
return call_ext(BYONDAPI_TEST, "byond:test_list_index_ffi")(list)
4353

54+
///Tests lists
4455
/proc/test_list_double(list)
4556
return call_ext(BYONDAPI_TEST, "byond:test_list_double_ffi")(list)
4657

58+
///Tests list pushes
4759
/proc/test_list_push(list)
4860
return call_ext(BYONDAPI_TEST, "byond:test_list_push_ffi")(list)
4961

62+
///Tests readwrite vars
5063
/proc/test_readwrite_var(object)
5164
return call_ext(BYONDAPI_TEST, "byond:test_readwrite_var_ffi")(object)
5265

66+
///Tests proccalls
5367
/proc/test_proc_call(object)
5468
return call_ext(BYONDAPI_TEST, "byond:test_proc_call_ffi")(object)
5569

70+
///Tests pointers
5671
/proc/test_ptr(ptr)
5772
return call_ext(BYONDAPI_TEST, "byond:test_ptr_ffi")(ptr)
5873

74+
///Tests raw args binds
5975
/proc/test_args(...)
6076
var/list/args_copy = args.Copy()
6177
args_copy.Insert(1, src)
6278
return call_ext(BYONDAPI_TEST, "byond:test_args_ffi")(arglist(args_copy))
6379

80+
///Tests main lib connection
6481
/proc/test_connection()
6582
return call_ext(BYONDAPI_TEST, "byond:test_connection_ffi")()
6683

crates/byondapi-rs-test/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ fn setup_panic_handler() {
1818
}))
1919
}
2020

21+
///Tests main lib connection
2122
#[byondapi::bind]
2223
fn test_connection() -> Result<ByondValue> {
2324
setup_panic_handler();
2425
Ok(ByondValue::new_num(69.0))
2526
}
2627

28+
///Tests raw args binds
2729
#[byondapi::bind_raw_args]
2830
fn test_args() -> Result<ByondValue> {
2931
setup_panic_handler();
3032
assert_eq!(args.len(), 2);
3133
Ok(args[1])
3234
}
3335

36+
///Tests pointers
3437
#[byondapi::bind]
3538
fn test_ptr(ptr: ByondValue) -> Result<ByondValue> {
3639
setup_panic_handler();
@@ -44,11 +47,13 @@ fn test_ptr(ptr: ByondValue) -> Result<ByondValue> {
4447
Ok(ByondValue::null())
4548
}
4649

50+
///Tests proccalls
4751
#[byondapi::bind]
4852
fn test_proc_call(object: ByondValue) -> Result<ByondValue> {
4953
Ok(object.call("get_name", &[])?)
5054
}
5155

56+
///Tests readwrite vars
5257
#[byondapi::bind]
5358
fn test_readwrite_var(object: ByondValue) -> Result<ByondValue> {
5459
setup_panic_handler();
@@ -57,6 +62,8 @@ fn test_readwrite_var(object: ByondValue) -> Result<ByondValue> {
5762

5863
Ok(object.read_string("name")?.try_into()?)
5964
}
65+
66+
///Tests list pushes
6067
#[byondapi::bind]
6168
fn test_list_push(mut list: ByondValue) -> Result<ByondValue> {
6269
setup_panic_handler();
@@ -66,6 +73,7 @@ fn test_list_push(mut list: ByondValue) -> Result<ByondValue> {
6673
Ok(list)
6774
}
6875

76+
///Tests lists
6977
#[byondapi::bind]
7078
fn test_list_double(list: ByondValue) -> Result<ByondValue> {
7179
setup_panic_handler();
@@ -78,13 +86,15 @@ fn test_list_double(list: ByondValue) -> Result<ByondValue> {
7886
Ok(collection.as_slice().try_into()?)
7987
}
8088

89+
///Tests lists indexing
8190
#[byondapi::bind]
8291
fn test_list_index(list: ByondValue) -> Result<ByondValue> {
8392
setup_panic_handler();
8493

8594
Ok(list.read_list_index(3.0)?)
8695
}
8796

97+
///Tests lists popping
8898
#[byondapi::bind]
8999
fn test_list_pop(mut list: ByondValue) -> Result<ByondValue> {
90100
setup_panic_handler();
@@ -98,12 +108,14 @@ fn test_list_pop(mut list: ByondValue) -> Result<ByondValue> {
98108
Ok(element.unwrap())
99109
}
100110

111+
///Tests lists length
101112
#[byondapi::bind]
102113
fn test_length_with_list(list: ByondValue) -> Result<ByondValue> {
103114
setup_panic_handler();
104115
Ok(list.builtin_length()?)
105116
}
106117

118+
///Tests block
107119
#[byondapi::bind]
108120
fn test_block() -> Result<ByondValue> {
109121
setup_panic_handler();
@@ -123,12 +135,15 @@ fn test_block() -> Result<ByondValue> {
123135
Ok((block.len() as f32).into())
124136
}
125137

138+
///Tests length with strings
126139
#[byondapi::bind]
127140
fn test_length_with_str(object: ByondValue) -> Result<ByondValue> {
128141
setup_panic_handler();
129142

130143
Ok(object.builtin_length()?)
131144
}
145+
146+
///Tests lists lookup
132147
#[byondapi::bind]
133148
fn test_list_key_lookup(mut list: ByondValue) -> Result<ByondValue> {
134149
setup_panic_handler();
@@ -165,6 +180,7 @@ fn test_list_key_lookup(mut list: ByondValue) -> Result<ByondValue> {
165180
Ok(Default::default())
166181
}
167182

183+
///Tests ref
168184
#[byondapi::bind]
169185
fn test_ref(turf: ByondValue) -> Result<ByondValue> {
170186
setup_panic_handler();
@@ -177,6 +193,7 @@ fn test_ref(turf: ByondValue) -> Result<ByondValue> {
177193
))?)
178194
}
179195

196+
///Tests non-assoc lists
180197
#[byondapi::bind]
181198
fn test_non_assoc_list(list: ByondValue) -> Result<ByondValue> {
182199
setup_panic_handler();
@@ -199,6 +216,7 @@ fn test_non_assoc_list(list: ByondValue) -> Result<ByondValue> {
199216
Ok(Default::default())
200217
}
201218

219+
///Tests lists read
202220
#[byondapi::bind]
203221
fn test_list_read(list: ByondValue) -> Result<ByondValue> {
204222
setup_panic_handler();
@@ -217,6 +235,7 @@ fn test_list_read(list: ByondValue) -> Result<ByondValue> {
217235
Ok(Default::default())
218236
}
219237

238+
///Tests new
220239
#[byondapi::bind]
221240
fn test_new_obj() -> Result<ByondValue> {
222241
Ok(ByondValue::builtin_new(

crates/byondapi-rs/src/binds.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub struct Bind {
44
pub proc_path: &'static str,
55
pub func_name: &'static str,
66
pub func_arguments: &'static str,
7+
pub docs: &'static str,
78
pub is_variadic: bool,
89
}
910

@@ -32,6 +33,7 @@ pub fn generate_bindings(libname: &str) {
3233
.unwrap();
3334
for thing in inventory::iter::<Bind> {
3435
let path = thing.proc_path;
36+
let docs = thing.docs;
3537
let func_name = thing.func_name;
3638
let func_arguments = thing.func_arguments;
3739
let func_arguments_srcless = func_arguments
@@ -41,7 +43,7 @@ pub fn generate_bindings(libname: &str) {
4143
if thing.is_variadic {
4244
//can't directly modify args, fuck you byond
4345
file.write_fmt(format_args!(
44-
r#"{path}(...)
46+
r#"{docs}{path}(...)
4547
var/list/args_copy = args.Copy()
4648
args_copy.Insert(1, src)
4749
return call_ext({libname_upper}, "byond:{func_name}")(arglist(args_copy))
@@ -51,7 +53,7 @@ pub fn generate_bindings(libname: &str) {
5153
.unwrap()
5254
} else {
5355
file.write_fmt(format_args!(
54-
r#"{path}({func_arguments_srcless})
56+
r#"{docs}{path}({func_arguments_srcless})
5557
return call_ext({libname_upper}, "byond:{func_name}")({func_arguments})
5658
5759
"#

0 commit comments

Comments
 (0)