openMSX
Interpreter.hh
Go to the documentation of this file.
1 #ifndef INTERPRETER_HH
2 #define INTERPRETER_HH
3 
4 #include "TemporaryString.hh"
5 #include "TclParser.hh"
6 #include "TclObject.hh"
7 #include "zstring_view.hh"
8 #include <tcl.h>
9 #include <string_view>
10 #include <string>
11 
12 namespace openmsx {
13 
14 class Command;
15 class BaseSetting;
16 class InterpreterOutput;
17 
19 {
20 public:
21  Interpreter(const Interpreter&) = delete;
22  Interpreter& operator=(const Interpreter&) = delete;
23 
24  Interpreter();
25  ~Interpreter();
26 
27  void setOutput(InterpreterOutput* output_) { output = output_; }
28 
29  void init(const char* programName);
30  bool hasCommand(zstring_view name) const;
31  void registerCommand(zstring_view name, Command& command);
32  void unregisterCommand(Command& command);
33  [[nodiscard]] TclObject getCommandNames();
34  [[nodiscard]] bool isComplete(zstring_view command) const;
37 
38  void setVariable(const TclObject& name, const TclObject& value);
39  void unsetVariable(const char* name);
40  void registerSetting(BaseSetting& variable);
41  void unregisterSetting(BaseSetting& variable);
42 
46  void createNamespace(const std::string& name);
47 
51  void deleteNamespace(const std::string& name);
52 
53  [[nodiscard]] TclParser parse(std::string_view command);
54 
55  void poll();
56 
57  void wrongNumArgs(unsigned argc, span<const TclObject> tokens, const char* message);
58 
59 private:
60  static int outputProc(ClientData clientData, const char* buf,
61  int toWrite, int* errorCodePtr);
62  static int commandProc(ClientData clientData, Tcl_Interp* interp,
63  int objc, Tcl_Obj* const objv[]);
64  static char* traceProc(ClientData clientData, Tcl_Interp* interp,
65  const char* part1, const char* part2, int flags);
66 
67  static Tcl_ChannelType channelType;
68  Tcl_Interp* interp;
69  InterpreterOutput* output;
70 
71  friend class TclObject;
72 };
73 
74 } // namespace openmsx
75 
76 #endif
void unsetVariable(const char *name)
Definition: Interpreter.cc:255
TclObject execute(zstring_view command)
Definition: Interpreter.cc:213
TclObject getCommandNames()
Definition: Interpreter.cc:203
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:442
void wrongNumArgs(unsigned argc, span< const TclObject > tokens, const char *message)
Definition: Interpreter.cc:458
void registerSetting(BaseSetting &variable)
Definition: Interpreter.cc:267
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:27
void createNamespace(const std::string &name)
Create the global namespace with given name.
Definition: Interpreter.cc:437
void unregisterCommand(Command &command)
Definition: Interpreter.cc:160
void setVariable(const TclObject &name, const TclObject &value)
Definition: Interpreter.cc:246
Interpreter(const Interpreter &)=delete
TclParser parse(std::string_view command)
Definition: Interpreter.cc:453
TclObject executeFile(zstring_view filename)
Definition: Interpreter.cc:222
bool isComplete(zstring_view command) const
Definition: Interpreter.cc:208
Interpreter & operator=(const Interpreter &)=delete
void unregisterSetting(BaseSetting &variable)
Definition: Interpreter.cc:319
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:145
void registerCommand(zstring_view name, Command &command)
Definition: Interpreter.cc:152
Definition: span.hh:126
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:21
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename