From c28ebd973362714c6fd1db9ff0ee1b808c45f749 Mon Sep 17 00:00:00 2001 From: Johannes Wolf Date: Fri, 20 Oct 2023 06:10:36 +0200 Subject: [PATCH] controller: Call function interactive --- config/bindings.lua | 1 + rpn/controller.lua | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/config/bindings.lua b/config/bindings.lua index e7c747d..26ef04d 100644 --- a/config/bindings.lua +++ b/config/bindings.lua @@ -82,6 +82,7 @@ return { t['x'] = { function(_) ctrl:solve_interactive() end, 'Solve*' } t['d'] = { function(_) ctrl:diff_interactive() end, 'Derivative*' } t['i'] = { function(_) ctrl:integrate_interactive() end, 'Integrate*' } + t['f'] = { function(_) ctrl:call_n_interactive() end, 'Call*' } t = edit.kbd t['down'] = { function(_) ctrl.stack:swap() end, 'Swap' } diff --git a/rpn/controller.lua b/rpn/controller.lua index db5398a..cf184d4 100644 --- a/rpn/controller.lua +++ b/rpn/controller.lua @@ -611,6 +611,20 @@ function meta:integrate_interactive() end end +cmd('Call n', 'call_n_interactive') +function meta:call_n_interactive() + if not self.stack:top() then return end + + local dlg = ask_n(2, { title = string.format("Call ...", self.stack:top().infix or '?'), text = '' }) + dlg.on_done = function(text) + local fn, n = table.unpack(text) + if fn:len() == 0 then return end + if tonumber(n) < 0 then return end + + self:dispatch_function_n(fn, tonumber(n), true, false) + end +end + cmd('Explode', 'explode_interactive') function meta:explode_interactive() if not self.stack:top() then return end