More user-friendly error message about missing value for `name` attribute in module macro
Update the `[lua_module]` doc
This commit is contained in:
parent
0f937b0a03
commit
e182d474e0
|
@ -18,7 +18,14 @@ struct ModuleAttributes {
|
||||||
impl ModuleAttributes {
|
impl ModuleAttributes {
|
||||||
fn parse(&mut self, meta: ParseNestedMeta) -> Result<()> {
|
fn parse(&mut self, meta: ParseNestedMeta) -> Result<()> {
|
||||||
if meta.path.is_ident("name") {
|
if meta.path.is_ident("name") {
|
||||||
self.name = Some(meta.value()?.parse::<LitStr>()?.parse()?);
|
match meta.value() {
|
||||||
|
Ok(value) => {
|
||||||
|
self.name = Some(value.parse::<LitStr>()?.parse()?);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
return Err(meta.error(format!("`name` attribute must have a value")));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(meta.error("unsupported module attribute"));
|
return Err(meta.error("unsupported module attribute"));
|
||||||
}
|
}
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -230,6 +230,17 @@ pub use mlua_derive::chunk;
|
||||||
///
|
///
|
||||||
/// Internally in the code above the compiler defines C function `luaopen_my_module`.
|
/// Internally in the code above the compiler defines C function `luaopen_my_module`.
|
||||||
///
|
///
|
||||||
|
/// You can also pass options to the attribute:
|
||||||
|
///
|
||||||
|
/// name - name of the module, defaults to the name of the function
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// #[mlua::lua_module(name = "alt_module")]
|
||||||
|
/// fn my_module(lua: &Lua) -> Result<Table> {
|
||||||
|
/// ...
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
#[cfg(any(feature = "module", docsrs))]
|
#[cfg(any(feature = "module", docsrs))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "module")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "module")))]
|
||||||
pub use mlua_derive::lua_module;
|
pub use mlua_derive::lua_module;
|
||||||
|
|
Loading…
Reference in New Issue