From 5f1f6dab7a6d1f31979419f8760b20d6bd5ed5a9 Mon Sep 17 00:00:00 2001 From: luaneko Date: Fri, 27 Jun 2025 23:47:52 +1000 Subject: [PATCH] Improve doc --- crates/lb/src/net.rs | 10 ++-- crates/luaffi_impl/src/metatype.rs | 84 ++++++++++++++++++------------ 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/crates/lb/src/net.rs b/crates/lb/src/net.rs index 49ac1d7..3cfae98 100644 --- a/crates/lb/src/net.rs +++ b/crates/lb/src/net.rs @@ -52,27 +52,27 @@ impl lb_netlib { Self } - /// See [`Ipv4Addr::LOCALHOST`]. + /// An IPv4 address representing localhost: `127.0.0.1` pub extern "Lua-C" fn localhost_v4(&self) -> lb_ipaddr { lb_ipaddr(Ipv4Addr::LOCALHOST.into()) } - /// See [`Ipv6Addr::LOCALHOST`]. + /// An IPv6 address representing localhost: `::1` pub extern "Lua-C" fn localhost_v6(&self) -> lb_ipaddr { lb_ipaddr(Ipv6Addr::LOCALHOST.into()) } - /// See [`Ipv4Addr::UNSPECIFIED`]. + /// An IPv4 address representing an unspecified address: `0.0.0.0` pub extern "Lua-C" fn unspecified_v4(&self) -> lb_ipaddr { lb_ipaddr(Ipv4Addr::UNSPECIFIED.into()) } - /// See [`Ipv6Addr::UNSPECIFIED`]. + /// An IPv6 address representing an unspecified address: `::` pub extern "Lua-C" fn unspecified_v6(&self) -> lb_ipaddr { lb_ipaddr(Ipv6Addr::UNSPECIFIED.into()) } - /// See [`Ipv4Addr::BROADCAST`]. + /// An IPv4 address representing the broadcast address: `255.255.255.255` pub extern "Lua-C" fn broadcast_v4(&self) -> lb_ipaddr { lb_ipaddr(Ipv4Addr::BROADCAST.into()) } diff --git a/crates/luaffi_impl/src/metatype.rs b/crates/luaffi_impl/src/metatype.rs index c18fe57..384e4cf 100644 --- a/crates/luaffi_impl/src/metatype.rs +++ b/crates/luaffi_impl/src/metatype.rs @@ -798,55 +798,73 @@ fn inject_merged_drop(registry: &mut Registry, lua: Option<&LuaFunction>) -> Res fn document_ffi_function(func: &mut ImplItemFn) { func.attrs.insert(0, parse_quote!(#[doc = - r#"FFI"# + r#"FFI"# ])); } fn document_lua_function(func: &mut ImplItemFn) { func.attrs.insert(0, parse_quote!(#[doc = - r#"Lua"# + r#"Lua"# ])); } fn document_async(func: &mut ImplItemFn) { func.attrs.insert(0, parse_quote!(#[doc = - r#"Async"# + r#"Async"# ])); } fn document_metamethod(func: &mut ImplItemFn, method: Metamethod) { - let s = match method { - Metamethod::Eq => "This is a metamethod which is called by the `==` operator.", - Metamethod::Len => "This is a metamethod which is called by the `#` operator.", - Metamethod::Lt => "This is a metamethod which is called by the `<` operator.", - Metamethod::Le => "This is a metamethod which is called by the `<=` operator.", - Metamethod::Concat => "This is a metamethod which is called by the `..` operator.", - Metamethod::Call => { - "This is a metamethod which can be called by calling `(...)` on the value directly." - } - Metamethod::Add => "This is a metamethod which is called by the `+` operator.", - Metamethod::Sub => "This is a metamethod which is called by the `-` operator.", - Metamethod::Mul => "This is a metamethod which is called by the `*` operator.", - Metamethod::Div => "This is a metamethod which is called by the `/` operator.", - Metamethod::Mod => "This is a metamethod which is called by the `%` operator.", - Metamethod::Pow => "This is a metamethod which is called by the `^` operator.", - Metamethod::Unm => "This is a metamethod which is called by the `-` operator.", - Metamethod::ToString => { - "This is a metamethod which is called by the [`tostring(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-tostring) built-in function." - } - Metamethod::Pairs => { - "This is a metamethod which is called by the [`pairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-pairs) built-in function." - } - Metamethod::Ipairs => { - "This is a metamethod which is called by the [`ipairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-ipairs) built-in function." - } - _ => "This is a metamethod and cannot be called directly.", - }; - func.attrs.insert(0, parse_quote!(#[doc = - r#"Metamethod"# + r#"Metamethod"# ])); + let doc = match method { + Metamethod::Eq => "This function is a metamethod which is called by the `==` operator.", + Metamethod::Len => "This function is a metamethod which is called by the `#` operator.", + Metamethod::Lt => "This function is a metamethod which is called by the `<` operator.", + Metamethod::Le => "This function is a metamethod which is called by the `<=` operator.", + Metamethod::Concat => "This function is a metamethod which is called by the `..` operator.", + Metamethod::Call => { + "This function is a metamethod which can be called by calling `(...)` on the value directly." + } + Metamethod::Add => "This function is a metamethod which is called by the `+` operator.", + Metamethod::Sub => "This function is a metamethod which is called by the `-` operator.", + Metamethod::Mul => "This function is a metamethod which is called by the `*` operator.", + Metamethod::Div => "This function is a metamethod which is called by the `/` operator.", + Metamethod::Mod => "This function is a metamethod which is called by the `%` operator.", + Metamethod::Pow => "This function is a metamethod which is called by the `^` operator.", + Metamethod::Unm => "This function is a metamethod which is called by the `-` operator.", + Metamethod::ToString => { + "This function is a metamethod which is called by the [`tostring(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-tostring) built-in function." + } + Metamethod::Pairs => { + "This function is a metamethod which is called by the [`pairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-pairs) built-in function." + } + Metamethod::Ipairs => { + "This function is a metamethod which is called by the [`ipairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-ipairs) built-in function." + } + _ => "This function is a metamethod and cannot be called directly.", + }; + func.attrs.push(parse_quote!(#[doc = ""])); - func.attrs.push(parse_quote!(#[doc = #s])); + func.attrs.push(parse_quote!(#[doc = "# Metamethod"])); + func.attrs.push(parse_quote!(#[doc = ""])); + func.attrs.push(parse_quote!(#[doc = #doc])); }