Skip to main content

module

Function module 

Source
pub fn module(lua: &Lua) -> LuaResult<LuaTable>
Expand description

Create the math module table with all functions registered.

§Examples

use mlua::prelude::*;

let lua = Lua::new();
let math = mlua_mathlib::module(&lua).unwrap();
lua.globals().set("math", math).unwrap();

// RNG
lua.load("local rng = math.rng_create(42); print(math.rng_float(rng))").exec().unwrap();

// Statistics
let mean: f64 = lua.load("return math.mean({1, 2, 3, 4, 5})").eval().unwrap();
assert!((mean - 3.0).abs() < 1e-10);