Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
MLua Extras
[!NOTE] Feel free to use this crate and start working with ideas and features that could be useful.
Pull requests and contribution are encouraged
If you want to discuss this project, you can do that here
The goal of this project is to add a light convenience layer wrapping the mlua crate. The goal isn't to change the way that mlua is used, but instead to make lua embedded development in Rust more enjoyable.
Similar Projects
Tealr: A project to enhance and extendmluawith a focus in type information and documentation along with a type syntax in the lua code itself with thetealrsyntax.- This crate is a great choice if you need: type syntax, type information, documentation generation
Features
-
Helper Traits
Require- call
requirewhich allows for a lua style call to get data from the lua engine. - ex:
table.require::<String>("nested.tables.name")?==local name = require('nested.tables').name
- call
Module- Syntax and API mimics
UserDataadding fields, functions and methods. Instead of createing a luauserdatatype, it adds these values to a luatable. - This allows for all the data to be held in lua
- This allows for a complex lua api without creating a bunch of userdata objects
- Syntax and API mimics
LuaExtras- Manipulate the lua
pathandcpathvariables withappend,prepend, andsetmethods for each variant. It also includes the ability to add multiple paths with each variant. - Set global variables and functions with
set_global("value", "value")andset_global_function("func", |lua, ()| Ok(()))which wold replacelua.globals().set("value", "value)andlua.globals().set("func", lua.create_function(|lua, ()| Ok(()))?)respectively
- Manipulate the lua
-
Typed Lua Traits
Typed- Generate a
TypeandParamfor a rust type so it can be used both as a type and as a parameter for a function
- Generate a
TypedUserData- Typed variant of
mlua::UserDatawith an additionaladd_documentationmethod to add doc comments to theUserDatatype - An extra
documentmethod is added to theTypedDataFieldsandTypedDataMethodsforadd_fieldsandadd_methods. This will queue doc comments to be added to the next field or method that is added. - All types from function parameters and and return types are stored for fields, functions, and methods.
- This trait is mainly used when generating type definitions. If it is called through the
UserDataderive macro it will ignore all types and documentation
- Typed variant of
TypedDataFields: Implemented on a generator forTypedUserData(add_fields)TypedDataMethods: Implemented on a generator forTypedUserData(add_methods)TypedDataDocumentation: Implemented on a generator forTypedUserData(add_documentation)
-
Derive Macros
Typed: Auto implement theTypedtrait to get type information for bothstructandenumUserData: Auto implement themlua::UserDatatrait for rust types that also implementTypedUserData. This will pass through theUserDataadd_methodsandadd_fieldsto theTypedUserData's version. This will ignore all documentation and types.
-
Macros
function: Write lua functions more like Rust's syntax
Instead of this:
lua.create_functionYou can now write this:
function!The difference isn't huge, but it could make the syntax more readable.
[!NOTE] This also helps with assigning functions to nested tables.
[!WARNING] This requires the
LuaExtrastrait when adding functions to nested tables withluaas the starting point. This requires theRequiretrait when starting from any other table.lua..set; // vs function!
Ideas and Planned Features
- Fully featured definition file generation
- Fully featured documentation generation
- Fully featured addon generator when creating a lua modules with
mlua'smodulefeature - Better and more informative type errors associated with lua type definitions and output generation
- More expressive way of defining exposed lua api types
- Generic types
- Doc comments for params and return types
References
Example Syntax
Helpers
use ;
use ;
Types
use Deserialize;
use ;
Produces the following definition file
--- init.d.lua
--- @meta
--- @alias System "Black"
--- | "Red"
--- | "Green"
--- | "Yellow"
--- | "Blue"
--- | "Cyan"
--- | "Magenta"
--- | "White"
--- @alias Color SystemColor
--- | integer
--- | [integer, integer, integer]
--- This is a doc comment section for the overall type
--- @class Example
--- Example complex type
--- @field color Color
--- Example module
--- @type Example
example = nil
--- Greet the name that was passed in
--- @param name string Name of the person to greet
--- @param param0 Color