summaryrefslogtreecommitdiff
path: root/examples/module/src/lib.rs
blob: 38cc0fda8c232dba4a7c6db8cbce8741d532e664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use mlua::prelude::*;

fn sum(_: &Lua, (a, b): (i64, i64)) -> LuaResult<i64> {
    Ok(a + b)
}

fn used_memory(lua: &Lua, _: ()) -> LuaResult<usize> {
    Ok(lua.used_memory())
}

#[mlua::lua_module]
fn rust_module(lua: &Lua) -> LuaResult<LuaTable> {
    let exports = lua.create_table()?;
    exports.set("sum", lua.create_function(sum)?)?;
    exports.set("used_memory", lua.create_function(used_memory)?)?;
    Ok(exports)
}