From 9b1b45ec53e3cdd1029b4ba40a167eaaaff62dd3 Mon Sep 17 00:00:00 2001 From: Srlion Date: Tue, 8 Oct 2024 12:50:17 +0300 Subject: [PATCH] Add "goobie_mysql.Poll" function for more control --- src/conn/on_gmod_open.rs | 4 ---- src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/conn/on_gmod_open.rs b/src/conn/on_gmod_open.rs index 1135c7c..c017829 100644 --- a/src/conn/on_gmod_open.rs +++ b/src/conn/on_gmod_open.rs @@ -8,10 +8,6 @@ const CONNECT_METHODS: &[LuaReg] = lua_regs![ pub fn init(l: lua::State) { l.register(GLOBAL_TABLE_NAME_C.as_ptr(), CONNECT_METHODS.as_ptr()); - { - l.push_string(crate::VERSION); - l.set_field(-2, c"VERSION"); - } l.pop(); l.new_metatable(super::META_NAME); diff --git a/src/lib.rs b/src/lib.rs index b5c86fc..f4b99b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,10 @@ pub use runtime::{run_async, wait_async}; pub static mut GMOD_CLOSED: bool = false; +const METHODS: &[LuaReg] = lua_regs![ + "Poll" => poll, +]; + #[inline] pub fn is_gmod_closed() -> bool { unsafe { GMOD_CLOSED } @@ -23,6 +27,13 @@ fn gmod13_open(l: lua::State) -> i32 { GMOD_CLOSED = false; } + l.register(GLOBAL_TABLE_NAME_C.as_ptr(), METHODS.as_ptr()); + { + l.push_string(crate::VERSION); + l.set_field(-2, c"VERSION"); + } + l.pop(); + runtime::load(get_max_worker_threads(l)); conn::on_gmod_open::init(l); @@ -41,6 +52,13 @@ fn gmod13_close(l: lua::State) -> i32 { 0 } +#[lua_function] +fn poll(l: lua::State) -> i32 { + task_queue::run_callbacks(l); + + 0 +} + fn get_max_worker_threads(l: lua::State) -> u16 { let mut max_worker_threads = DEFAULT_WORKER_THREADS;