chore(lua): module at the bottom

This commit is contained in:
əlemi 2024-09-01 03:11:43 +02:00 committed by zaaarf
parent 89dbc89225
commit e50703fc77
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B

View file

@ -341,30 +341,6 @@ impl LuaUserData for CodempTextChange {
} }
// define module and exports
#[mlua::lua_module]
fn codemp_native(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
// entrypoint
exports.set("connect", lua.create_function(|_, (host, username, password):(String,String,String)|
a_sync! { => Ok(CodempClient::connect(host, username, password).await?) }
)?)?;
// utils
exports.set("hash", lua.create_function(|_, (txt,):(String,)|
Ok(crate::hash(txt))
)?)?;
// runtime
exports.set("spawn_runtime_driver", lua.create_function(spawn_runtime_driver)?)?;
// logging
exports.set("logger", lua.create_function(logger)?)?;
Ok(exports)
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct LuaLoggerProducer(mpsc::UnboundedSender<String>); struct LuaLoggerProducer(mpsc::UnboundedSender<String>);
@ -455,3 +431,27 @@ fn logger(_: &Lua, (printer, debug): (LuaValue, Option<bool>)) -> LuaResult<bool
Ok(success) Ok(success)
} }
// define module and exports
#[mlua::lua_module]
fn codemp_native(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
// entrypoint
exports.set("connect", lua.create_function(|_, (host, username, password):(String,String,String)|
a_sync! { => Ok(CodempClient::connect(host, username, password).await?) }
)?)?;
// utils
exports.set("hash", lua.create_function(|_, (txt,):(String,)|
Ok(crate::hash(txt))
)?)?;
// runtime
exports.set("spawn_runtime_driver", lua.create_function(spawn_runtime_driver)?)?;
// logging
exports.set("logger", lua.create_function(logger)?)?;
Ok(exports)
}