openMSX
Interpreter.hh
Go to the documentation of this file.
1 #ifndef INTERPRETER_HH
2 #define INTERPRETER_HH
3 
4 #include "TclParser.hh"
5 #include "TclObject.hh"
6 #include "string_view.hh"
7 #include <tcl.h>
8 #include <string>
9 
10 namespace openmsx {
11 
12 class Command;
13 class BaseSetting;
14 class InterpreterOutput;
15 
17 {
18 public:
19  Interpreter(const Interpreter&) = delete;
20  Interpreter& operator=(const Interpreter&) = delete;
21 
22  Interpreter();
23  ~Interpreter();
24 
25  void setOutput(InterpreterOutput* output_) { output = output_; }
26 
27  void init(const char* programName);
28  void registerCommand(const std::string& name, Command& command);
29  void unregisterCommand(Command& command);
31  bool isComplete(const std::string& command) const;
32  TclObject execute(const std::string& command);
33  TclObject executeFile(const std::string& filename);
34 
35  void setVariable(const TclObject& name, const TclObject& value);
36  void unsetVariable(const char* name);
37  void registerSetting(BaseSetting& variable);
38  void unregisterSetting(BaseSetting& variable);
39 
43  void createNamespace(const std::string& name);
44 
48  void deleteNamespace(const std::string& name);
49 
50  TclParser parse(string_view command);
51 
52  void poll();
53 
54  void wrongNumArgs(unsigned argc, span<const TclObject> tokens, const char* message);
55 
56 private:
57  static int outputProc(ClientData clientData, const char* buf,
58  int toWrite, int* errorCodePtr);
59  static int commandProc(ClientData clientData, Tcl_Interp* interp,
60  int objc, Tcl_Obj* const objv[]);
61  static char* traceProc(ClientData clientData, Tcl_Interp* interp,
62  const char* part1, const char* part2, int flags);
63 
64  static Tcl_ChannelType channelType;
65  Tcl_Interp* interp;
66  InterpreterOutput* output;
67 
68  friend class TclObject;
69 };
70 
71 } // namespace openmsx
72 
73 #endif
void registerCommand(const std::string &name, Command &command)
Definition: Interpreter.cc:145
TclObject executeFile(const std::string &filename)
Definition: Interpreter.cc:215
void init(const char *programName)
Definition: Interpreter.cc:68
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
Definition: Interpreter.cc:436
Definition: span.hh:34
TclParser parse(string_view command)
Definition: Interpreter.cc:447
Interpreter & operator=(const Interpreter &)=delete
void wrongNumArgs(unsigned argc, span< const TclObject > tokens, const char *message)
Definition: Interpreter.cc:452
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void unsetVariable(const char *name)
Definition: Interpreter.cc:248
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
void createNamespace(const std::string &name)
Create the global namespace with given name.
Definition: Interpreter.cc:431
void unregisterCommand(Command &command)
Definition: Interpreter.cc:153
void setVariable(const TclObject &name, const TclObject &value)
Definition: Interpreter.cc:239
TclObject getCommandNames()
Definition: Interpreter.cc:196
TclObject execute(const std::string &command)
Definition: Interpreter.cc:206
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:25
void registerSetting(BaseSetting &variable)
Definition: Interpreter.cc:261
void unregisterSetting(BaseSetting &variable)
Definition: Interpreter.cc:313
bool isComplete(const std::string &command) const
Definition: Interpreter.cc:201