changeset 25701:9a385fab138e

allow the gui to insert builtin functions into the cmd queue * octave-cmd.cc (octave_cmd_builtin::execute) method of the new command class for actually executing the builtin function * octave-cmd.h: new class octave_cmd_builtin derived from octave_cmd, (octave_cmd_builtin): ctor with initialization of new class variables
author Torsten <mttl@mailbox.org>
date Sun, 29 Jul 2018 11:30:33 +0200
parents ba8227df92ae
children bd30c6f8cfb7
files libgui/src/octave-cmd.cc libgui/src/octave-cmd.h
diffstat 2 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/octave-cmd.cc	Sat Jul 28 08:29:34 2018 +0200
+++ b/libgui/src/octave-cmd.cc	Sun Jul 29 11:30:33 2018 +0200
@@ -75,6 +75,11 @@
     command_editor::accept_line ();
   }
 
+  void octave_cmd_builtin::execute (interpreter& interp)
+  {
+    m_callback_f (interp, m_argin, m_nargin);
+  }
+
   void octave_cmd_debug::execute (interpreter& interp)
   {
     if (m_cmd == "step")
--- a/libgui/src/octave-cmd.h	Sat Jul 28 08:29:34 2018 +0200
+++ b/libgui/src/octave-cmd.h	Sun Jul 29 11:30:33 2018 +0200
@@ -31,6 +31,8 @@
 #include <QFileInfo>
 
 #include "octave-qt-link.h"
+#include "ovl.h"
+
 
 namespace octave
 {
@@ -73,6 +75,40 @@
     QFileInfo m_info;
   };
 
+  class octave_cmd_builtin : public octave_cmd
+  {
+    public:
+
+    enum cmd_upd {
+      CMD_UPD_NO        = 0,
+    };
+
+    octave_cmd_builtin (octave_value_list (*Ff)
+                         (octave::interpreter&, const octave_value_list&, int),
+                        octave_value_list argin = ovl (), int nargin = 0,
+                        cmd_upd update = CMD_UPD_NO,
+                        octave_qt_link *oct_qt_link = nullptr)
+      : octave_cmd ()
+    {
+      m_callback_f = Ff;
+      m_argin  = argin;
+      m_nargin = nargin;
+      m_update = update;  // later: some built in functions require updates
+      m_octave_qt_link = oct_qt_link; // octave_qt_link might be required
+    };
+
+    void execute (interpreter& interp);
+
+  protected:
+
+    octave_value_list (*m_callback_f) (
+                        octave::interpreter&, const octave_value_list&, int);
+    octave_value_list m_argin;
+    int m_nargin;
+    cmd_upd m_update;
+    octave_qt_link *m_octave_qt_link;
+  };
+
   class octave_cmd_debug : public octave_cmd_exec
   {
   public: