chore: replace meval with expr-solver-lib, drop reqwest from runtimes, fix AUR deps
- owlry-core: swap meval → expr-solver-lib for calculator and Lua math API; add ln() alias for meval compatibility - owlry-lua: remove reqwest and meval (network features belong in plugins); add vendored feature flag so distro builds can link against system lua54 - owlry-rune: remove reqwest (same reason) - aur/owlry-rune: fix depends (gcc-libs only; owlry-core → optdepends) - aur/owlry-lua: fix depends (gcc-libs + lua54; owlry-core → optdepends) - aur/owlry: add chmod -R a+rX for example plugins - justfile: log aur-local-test output to build-logs/ - .gitignore: exclude build-logs/ and test-build-output files - README: minor improvements (SIGHUP reload hint, plugin_config example)
This commit is contained in:
@@ -3,8 +3,17 @@
|
||||
//! Provides safe math expression evaluation:
|
||||
//! - `owlry.math.calculate(expression)` - Evaluate a math expression
|
||||
|
||||
use expr_solver::{SymTable, eval_with_table};
|
||||
use mlua::{Lua, Result as LuaResult, Table};
|
||||
|
||||
fn eval_math(expr: &str) -> Result<f64, String> {
|
||||
let mut table = SymTable::stdlib();
|
||||
table
|
||||
.add_func("ln", 1, false, |args| Ok(args[0].ln()), false)
|
||||
.expect("ln alias is valid");
|
||||
eval_with_table(expr, table)
|
||||
}
|
||||
|
||||
/// Register math APIs
|
||||
pub fn register_math_api(lua: &Lua, owlry: &Table) -> LuaResult<()> {
|
||||
let math_table = lua.create_table()?;
|
||||
@@ -16,7 +25,7 @@ pub fn register_math_api(lua: &Lua, owlry: &Table) -> LuaResult<()> {
|
||||
"calculate",
|
||||
lua.create_function(
|
||||
|_lua, expr: String| -> LuaResult<(Option<f64>, Option<String>)> {
|
||||
match meval::eval_str(&expr) {
|
||||
match eval_math(&expr) {
|
||||
Ok(result) => {
|
||||
if result.is_finite() {
|
||||
Ok((Some(result), None))
|
||||
@@ -24,7 +33,7 @@ pub fn register_math_api(lua: &Lua, owlry: &Table) -> LuaResult<()> {
|
||||
Ok((None, Some("Result is not a finite number".to_string())))
|
||||
}
|
||||
}
|
||||
Err(e) => Ok((None, Some(e.to_string()))),
|
||||
Err(e) => Ok((None, Some(e))),
|
||||
}
|
||||
},
|
||||
)?,
|
||||
@@ -35,7 +44,7 @@ pub fn register_math_api(lua: &Lua, owlry: &Table) -> LuaResult<()> {
|
||||
math_table.set(
|
||||
"calc",
|
||||
lua.create_function(|_lua, expr: String| {
|
||||
meval::eval_str(&expr)
|
||||
eval_math(&expr)
|
||||
.map_err(|e| mlua::Error::external(format!("Math error: {}", e)))
|
||||
.and_then(|r| {
|
||||
if r.is_finite() {
|
||||
|
||||
Reference in New Issue
Block a user