From f0741f412889abaeba78c6ea55dff7b18cf58694 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Thu, 26 Mar 2026 18:12:07 +0100 Subject: [PATCH] fix: store Lua provider callbacks for refresh, fix Rune Item::new parameter types --- crates/owlry-lua/src/api/provider.rs | 17 ++++++++++++++++- crates/owlry-rune/src/api.rs | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/owlry-lua/src/api/provider.rs b/crates/owlry-lua/src/api/provider.rs index 12afb76..d781523 100644 --- a/crates/owlry-lua/src/api/provider.rs +++ b/crates/owlry-lua/src/api/provider.rs @@ -22,7 +22,7 @@ pub fn register_provider_api(lua: &Lua, owlry: &Table) -> LuaResult<()> { } /// Implementation of owlry.provider.register() -fn register_provider(_lua: &Lua, config: Table) -> LuaResult<()> { +fn register_provider(lua: &Lua, config: Table) -> LuaResult<()> { let name: String = config.get("name")?; let display_name: String = config .get::>("display_name")? @@ -47,6 +47,21 @@ fn register_provider(_lua: &Lua, config: Table) -> LuaResult<()> { let is_dynamic = has_query; + // Store the config table in owlry.provider._registrations[name] + // so call_refresh/call_query can find the callback functions later + let globals = lua.globals(); + let owlry: Table = globals.get("owlry")?; + let provider: Table = owlry.get("provider")?; + let registrations: Table = match provider.get::("_registrations")? { + Value::Table(t) => t, + _ => { + let t = lua.create_table()?; + provider.set("_registrations", t.clone())?; + t + } + }; + registrations.set(name.as_str(), config)?; + REGISTRATIONS.with(|regs| { regs.borrow_mut().push(ProviderRegistration { name, diff --git a/crates/owlry-rune/src/api.rs b/crates/owlry-rune/src/api.rs index 727b786..7756977 100644 --- a/crates/owlry-rune/src/api.rs +++ b/crates/owlry-rune/src/api.rs @@ -94,7 +94,9 @@ pub fn module() -> Result { // Register Item type with constructor and builder methods module.ty::()?; module - .function("Item::new", Item::rune_new) + .function("Item::new", |id: String, name: String, command: String| -> Item { + Item::rune_new(&id, &name, &command) + }) .build()?; module .associated_function("description", Item::rune_description)?;