chore(lua): renamed some top level methods

This commit is contained in:
əlemi 2024-09-17 23:33:37 +02:00
parent 3047d21870
commit d215b4ab0b
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 9 additions and 7 deletions

View file

@ -403,12 +403,14 @@ local RuntimeDriver = {}
---stops the runtime thread, returns false if driver was already stopped
function RuntimeDriver:stop() end
---@return RuntimeDriver
---@param block? boolean block current thread if true, otherwise spawn a background thread
---@return RuntimeDriver | nil
---spawns a background thread and uses it to run the codemp runtime
function Codemp.spawn_runtime_driver() end
---returns the driver handle only if another thread has been spawned (block=true)
function Codemp.setup_driver(block) end
---@param printer? string | fun(string) | nil log sink used for printing, if string will go to file, otherwise use given function
---@param debug? boolean show more verbose debug logs, default false
---@return boolean true if logger was setup correctly, false otherwise
---setup a global logger for codemp, note that can only be done once
function Codemp.logger(printer, debug) end
function Codemp.setup_tracing(printer, debug) end

View file

@ -70,7 +70,7 @@ impl LuaUserData for Promise {
}
}
pub(crate) fn spawn_runtime_driver(_: &Lua, (block,):(Option<bool>,)) -> LuaResult<Option<Driver>> {
pub(crate) fn setup_driver(_: &Lua, (block,):(Option<bool>,)) -> LuaResult<Option<Driver>> {
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let future = async move {
tracing::info!(" :: driving runtime...");

View file

@ -16,7 +16,7 @@ impl Write for LuaLoggerProducer {
}
// TODO can we make this less verbose?
pub(crate) fn logger(_: &Lua, (printer, debug): (LuaValue, Option<bool>)) -> LuaResult<bool> {
pub(crate) fn setup_tracing(_: &Lua, (printer, debug): (LuaValue, Option<bool>)) -> LuaResult<bool> {
let level = if debug.unwrap_or_default() { tracing::Level::DEBUG } else {tracing::Level::INFO };
let format = tracing_subscriber::fmt::format()
.with_level(true)

View file

@ -28,7 +28,7 @@ fn entrypoint(lua: &Lua) -> LuaResult<LuaTable> {
)?)?;
// runtime
exports.set("spawn_runtime_driver", lua.create_function(ext::a_sync::spawn_runtime_driver)?)?;
exports.set("setup_driver", lua.create_function(ext::a_sync::setup_driver)?)?;
exports.set("poll_callback", lua.create_function(|lua, ()| {
let mut val = LuaMultiValue::new();
match ext::callback().recv() {
@ -45,7 +45,7 @@ fn entrypoint(lua: &Lua) -> LuaResult<LuaTable> {
})?)?;
// logging
exports.set("logger", lua.create_function(ext::log::logger)?)?;
exports.set("setup_tracing", lua.create_function(ext::log::setup_tracing)?)?;
Ok(exports)
}