summaryrefslogtreecommitdiff
path: root/examples/module/src/lib.rs
blob: 24056a1f427f1cfcb06f7afab57c37ce414e4685 (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_derive::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)
}