fix: store Lua provider callbacks for refresh, fix Rune Item::new parameter types
This commit is contained in:
@@ -22,7 +22,7 @@ pub fn register_provider_api(lua: &Lua, owlry: &Table) -> LuaResult<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of owlry.provider.register()
|
/// 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 name: String = config.get("name")?;
|
||||||
let display_name: String = config
|
let display_name: String = config
|
||||||
.get::<Option<String>>("display_name")?
|
.get::<Option<String>>("display_name")?
|
||||||
@@ -47,6 +47,21 @@ fn register_provider(_lua: &Lua, config: Table) -> LuaResult<()> {
|
|||||||
|
|
||||||
let is_dynamic = has_query;
|
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| {
|
REGISTRATIONS.with(|regs| {
|
||||||
regs.borrow_mut().push(ProviderRegistration {
|
regs.borrow_mut().push(ProviderRegistration {
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ pub fn module() -> Result<Module, ContextError> {
|
|||||||
// Register Item type with constructor and builder methods
|
// Register Item type with constructor and builder methods
|
||||||
module.ty::<Item>()?;
|
module.ty::<Item>()?;
|
||||||
module
|
module
|
||||||
.function("Item::new", Item::rune_new)
|
.function("Item::new", |id: String, name: String, command: String| -> Item {
|
||||||
|
Item::rune_new(&id, &name, &command)
|
||||||
|
})
|
||||||
.build()?;
|
.build()?;
|
||||||
module
|
module
|
||||||
.associated_function("description", Item::rune_description)?;
|
.associated_function("description", Item::rune_description)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user