diff --git a/README.md b/README.md index db26f7e..dfbf719 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,7 @@ Besides the [Legacy Syntax](https://www.autohotkey.com/docs/v1/Language.htm#lega - `x := 1` -> `x = 1` - `x := y` -> `x = %y%` - `b := a + 3` -> + Simple math instructions with `:=` like this one are actually wonkily supported, so chances are you can leave it as is. In this case, you'd omit the percent signs `%` unless you want to double-deref, just like on Windows. But for more complicated stuff such as string concatenation, you'll have to resort back to classic syntax: ```ahk b = %a% diff --git a/src/cmd/math/env-math.cr b/src/cmd/math/env-math.cr index ce3bf2a..2876098 100644 --- a/src/cmd/math/env-math.cr +++ b/src/cmd/math/env-math.cr @@ -6,17 +6,17 @@ class Cmd::Math::EnvMath < Cmd::Base def run(thread, args) var = args[0] formula = args[1]? || "" - formula = formula.replace_all /\b[^0-9.()%/*<>+-]\w*\b/g do |word| - thread.runner.get_var(word) + formula = formula.gsub /\b[^0-9.()%\/*<>+-]\w*\b/ do |word| + thread.get_var(word) end stdout_m = IO::Memory.new stderr_m = IO::Memory.new - result = Process.run "awk", "BEGIN {print #{formula}}", output: stdout_m, error: stderr_m + result = Process.run "awk", ["BEGIN {print #{formula}}"], output: stdout_m, error: stderr_m if result.exit_code != 0 thread.runner.set_user_var var, "" return stderr_m.to_s end - thread.runner.set_user_var var, stdout_m.to_s + thread.runner.set_user_var var, stdout_m.to_s.strip return "0" end end \ No newline at end of file