From d215b4ab0bbcda388f136f55d667ad40e4c274dd Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 17 Sep 2024 23:33:37 +0200 Subject: [PATCH] chore(lua): renamed some top level methods --- dist/lua/annotations.lua | 8 +++++--- src/ffi/lua/ext/a_sync.rs | 2 +- src/ffi/lua/ext/log.rs | 2 +- src/ffi/lua/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/lua/annotations.lua b/dist/lua/annotations.lua index 85f67a0..0e9ee31 100644 --- a/dist/lua/annotations.lua +++ b/dist/lua/annotations.lua @@ -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 diff --git a/src/ffi/lua/ext/a_sync.rs b/src/ffi/lua/ext/a_sync.rs index c994cc9..54bc20c 100644 --- a/src/ffi/lua/ext/a_sync.rs +++ b/src/ffi/lua/ext/a_sync.rs @@ -70,7 +70,7 @@ impl LuaUserData for Promise { } } -pub(crate) fn spawn_runtime_driver(_: &Lua, (block,):(Option,)) -> LuaResult> { +pub(crate) fn setup_driver(_: &Lua, (block,):(Option,)) -> LuaResult> { let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); let future = async move { tracing::info!(" :: driving runtime..."); diff --git a/src/ffi/lua/ext/log.rs b/src/ffi/lua/ext/log.rs index 9d042c7..5553660 100644 --- a/src/ffi/lua/ext/log.rs +++ b/src/ffi/lua/ext/log.rs @@ -16,7 +16,7 @@ impl Write for LuaLoggerProducer { } // TODO can we make this less verbose? -pub(crate) fn logger(_: &Lua, (printer, debug): (LuaValue, Option)) -> LuaResult { +pub(crate) fn setup_tracing(_: &Lua, (printer, debug): (LuaValue, Option)) -> LuaResult { let level = if debug.unwrap_or_default() { tracing::Level::DEBUG } else {tracing::Level::INFO }; let format = tracing_subscriber::fmt::format() .with_level(true) diff --git a/src/ffi/lua/mod.rs b/src/ffi/lua/mod.rs index 188232f..df86d0d 100644 --- a/src/ffi/lua/mod.rs +++ b/src/ffi/lua/mod.rs @@ -28,7 +28,7 @@ fn entrypoint(lua: &Lua) -> LuaResult { )?)?; // 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 { })?)?; // logging - exports.set("logger", lua.create_function(ext::log::logger)?)?; + exports.set("setup_tracing", lua.create_function(ext::log::setup_tracing)?)?; Ok(exports) }