config: type the registration function arguments
The Value matches existed only to keep conversion inside the frame
where caller_position could prefix the config line; deferring that for
simpler signatures, with mlua bad-argument errors surfacing the call
site in the traceback meanwhile.
Assisted-by: GLM-5.3 via pi
diff --git a/src/parallax.rs b/src/parallax.rs
index b71b355..63c2c52 100644
--- a/src/parallax.rs
+++ b/src/parallax.rs
@@ -29,10 +29,7 @@ struct Registrations {
}
impl Registrations {
- fn setup(&mut self, lua: &Lua, table: Value) -> Result<(), mlua::Error> {
- let Value::Table(table) = table else {
- return Err(error_at(lua, "setup takes a table"));
- };
+ fn setup(&mut self, lua: &Lua, table: Table) -> Result<(), mlua::Error> {
if self.setup.is_some() {
return Err(error_at(lua, "setup must be called exactly once"));
}
@@ -46,10 +43,7 @@ impl Registrations {
Ok(())
}
- fn server(&mut self, lua: &Lua, call: Value) -> Result<(), mlua::Error> {
- let Value::Function(call) = call else {
- return Err(error_at(lua, "server takes a function"));
- };
+ fn server(&mut self, lua: &Lua, call: Function) -> Result<(), mlua::Error> {
if self.server.is_some() {
return Err(error_at(lua, "server must be called exactly once"));
}
@@ -57,10 +51,7 @@ impl Registrations {
Ok(())
}
- fn flow(&mut self, lua: &Lua, call: Value) -> Result<(), mlua::Error> {
- let Value::Function(call) = call else {
- return Err(error_at(lua, "flow takes a function"));
- };
+ fn flow(&mut self, lua: &Lua, call: Function) -> Result<(), mlua::Error> {
if self.flow.is_some() {
return Err(error_at(lua, "flow must be called exactly once"));
}
@@ -165,19 +156,19 @@ fn install_module(lua: &Lua) -> Result<AnyUserData, mlua::Error> {
let setup = {
let module = module.clone();
- lua.create_function(move |lua, table: Value| {
+ lua.create_function(move |lua, table: Table| {
module.borrow_mut::<Registrations>()?.setup(lua, table)
})?
};
let server = {
let module = module.clone();
- lua.create_function(move |lua, call: Value| {
+ lua.create_function(move |lua, call: Function| {
module.borrow_mut::<Registrations>()?.server(lua, call)
})?
};
let flow = {
let module = module.clone();
- lua.create_function(move |lua, call: Value| {
+ lua.create_function(move |lua, call: Function| {
module.borrow_mut::<Registrations>()?.flow(lua, call)
})?
};
diff --git a/tests/cli.rs b/tests/cli.rs
index ade03eb..38ab3b9 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -181,9 +181,7 @@ fn duplicate_flow_registration_fails() {
.arg(&path)
.assert()
.failure()
- .stderr(
- predicate::str::contains("config.fnl:5:").and(predicate::str::contains("exactly")),
- );
+ .stderr(predicate::str::contains("config.fnl:5:").and(predicate::str::contains("exactly")));
}
#[test]
@@ -201,7 +199,8 @@ fn malformed_flow_registration_fails() {
.assert()
.failure()
.stderr(
- predicate::str::contains("config.fnl:4:").and(predicate::str::contains("flow takes")),
+ predicate::str::contains("bad argument #1")
+ .and(predicate::str::contains("config.fnl:4:")),
);
}