pub struct DefinitionBuilder<'def> {
pub entries: Vec<Entry<'def>>,
}
Expand description
Builder for definition entries
Fields§
§entries: Vec<Entry<'def>>
Implementations§
Source§impl<'def> DefinitionBuilder<'def>
impl<'def> DefinitionBuilder<'def>
Sourcepub fn function<'lua, Params, Returns>(
self,
name: impl Into<Cow<'def, str>>,
_: impl IntoTypedFunction<'lua, Params, Returns>,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
pub fn function<'lua, Params, Returns>(
self,
name: impl Into<Cow<'def, str>>,
_: impl IntoTypedFunction<'lua, Params, Returns>,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
Register a definition entry that is a function type
Sourcepub fn function_with<'lua, Params, Returns, F>(
self,
name: impl Into<Cow<'def, str>>,
_: impl IntoTypedFunction<'lua, Params, Returns>,
generator: F,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
F: Fn(&mut FunctionBuilder<Params, Returns>),
pub fn function_with<'lua, Params, Returns, F>(
self,
name: impl Into<Cow<'def, str>>,
_: impl IntoTypedFunction<'lua, Params, Returns>,
generator: F,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
F: Fn(&mut FunctionBuilder<Params, Returns>),
Register a definition entry that is a function type
Also add additional documentation
Sourcepub fn alias(self, name: impl Into<Cow<'static, str>>, ty: Type) -> Self
pub fn alias(self, name: impl Into<Cow<'static, str>>, ty: Type) -> Self
Register a definition entry that is an alias type
Sourcepub fn alias_with<S: Into<Cow<'def, str>>>(
self,
name: impl Into<Cow<'def, str>>,
ty: Type,
doc: Option<S>,
) -> Self
pub fn alias_with<S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, ty: Type, doc: Option<S>, ) -> Self
Register a definition entry that is an alias type
Also add additional documentation
Sourcepub fn register_class<T: TypedUserData>(self) -> Self
pub fn register_class<T: TypedUserData>(self) -> Self
Register a definition entry that is a class type
The name of the class is the same as the name of the type passed
Sourcepub fn register_class_with<T: TypedUserData, S: Into<Cow<'def, str>>>(
self,
doc: Option<S>,
) -> Self
pub fn register_class_with<T: TypedUserData, S: Into<Cow<'def, str>>>( self, doc: Option<S>, ) -> Self
Same as register_class
but with additional docs
Sourcepub fn register_module<T: TypedModule>(
self,
name: impl Into<Cow<'def, str>>,
) -> Self
pub fn register_module<T: TypedModule>( self, name: impl Into<Cow<'def, str>>, ) -> Self
Register a definition entry that is a class type
The name of the class is the same as the name of the type passed
Sourcepub fn register_module_with<T: TypedModule, S: Into<Cow<'def, str>>>(
self,
name: impl Into<Cow<'def, str>>,
doc: Option<S>,
) -> Self
pub fn register_module_with<T: TypedModule, S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, doc: Option<S>, ) -> Self
Same as register_module
but with additional docs
Sourcepub fn register_enum<T: Typed>(self) -> Result<Self>
pub fn register_enum<T: Typed>(self) -> Result<Self>
Register a definition entry that is a enum type
This is equal to an alias, but is usually derived from using the Typed
derive macro on an
enum object.
Returns an error response of Error::RuntimeError
if the type extracted was not Type::Enum
§Example
use mlua_extras::{Typed, typed::Type};
#[derive(Typed)]
enum Color {
Red,
White,
Green,
Yellow,
Cyan,
Blue,
Magenta,
Black
}
assert!(matches!(Color::ty(), Type::Enum(_, _)))
Sourcepub fn register_enum_with<T: Typed, S: Into<Cow<'def, str>>>(
self,
doc: Option<S>,
) -> Result<Self>
pub fn register_enum_with<T: Typed, S: Into<Cow<'def, str>>>( self, doc: Option<S>, ) -> Result<Self>
Same as register
but with additional docs
Sourcepub fn value<T: Typed>(self, name: impl Into<Cow<'def, str>>) -> Self
pub fn value<T: Typed>(self, name: impl Into<Cow<'def, str>>) -> Self
Register a value that is available
This can be a table, union/enum, literal, or any other value and it will be typed with the given type
§Example
user mlua_extras::{typed::{Definitions, TypedUserData}, Typed, UserData};
#[derive(UserData, Typed)]
struct Example {
color: String
}
impl TypedUserData for Example {
fn add_documentation<F: mlua_extras::typed::TypedDataDocumentation<Self>>(docs: &mut F) {
docs.add("This is an example");
}
fn add_fields<'lua, F: TypedDataFields<'lua, Self>>(fields: &mut F) {
fields
.document("Example field")
.add_field_method_get_set(
"color",
|_lua, this| Ok(this.color),
|_lua, this, clr: String| {
this.color = clr;
Ok(())
},
);
}
}
Definitions::generate("init")
.register::<Example>("Example")
.value::<Example>("example")
.finish();
--- init.d.lua
--- @meta
--- This is an example
--- @class Example
--- Example field
--- @field color string
--- The example module
--- @type Example
example = nil
Sourcepub fn value_with<T: Typed, S: Into<Cow<'def, str>>>(
self,
name: impl Into<Cow<'def, str>>,
doc: Option<S>,
) -> Self
pub fn value_with<T: Typed, S: Into<Cow<'def, str>>>( self, name: impl Into<Cow<'def, str>>, doc: Option<S>, ) -> Self
Same as value
but with additional docs
Sourcepub fn finish(self) -> Definition<'def>
pub fn finish(self) -> Definition<'def>
Finish the definition
Trait Implementations§
Source§impl<'def> Clone for DefinitionBuilder<'def>
impl<'def> Clone for DefinitionBuilder<'def>
Source§fn clone(&self) -> DefinitionBuilder<'def>
fn clone(&self) -> DefinitionBuilder<'def>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more