fix: store Lua provider callbacks for refresh, fix Rune Item::new parameter types

This commit is contained in:
2026-03-26 18:12:07 +01:00
parent 7da8f3c249
commit f0741f4128
2 changed files with 19 additions and 2 deletions

View File

@@ -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::<Option<String>>("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::<Value>("_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,

View File

@@ -94,7 +94,9 @@ pub fn module() -> Result<Module, ContextError> {
// Register Item type with constructor and builder methods
module.ty::<Item>()?;
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)?;