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 "zstring_view.hh"
7 #include <tcl.h>
8 #include <string_view>
9 #include <string>
10 
11 namespace openmsx {
12 
13 class Command;
14 class BaseSetting;
15 class InterpreterOutput;
16 
18 {
19 public:
20  Interpreter(const Interpreter&) = delete;
21  Interpreter& operator=(const Interpreter&) = delete;
22 
23  Interpreter();
24  ~Interpreter();
25 
26  void setOutput(InterpreterOutput* output_) { output = output_; }
27 
28  void init(const char* programName);
29  bool hasCommand(zstring_view name) const;
30  void registerCommand(zstring_view name, Command& command);
31  void unregisterCommand(Command& command);
32  [[nodiscard]] TclObject getCommandNames();
33  [[nodiscard]] bool isComplete(zstring_view command) const;
36 
37  void setVariable(const TclObject& name, const TclObject& value);
38  void unsetVariable(const char* name);
39  void registerSetting(BaseSetting& variable);
40  void unregisterSetting(BaseSetting& variable);
41 
45  void createNamespace(const std::string& name);
46 
50  void deleteNamespace(const std::string& name);
51 
52  [[nodiscard]] TclParser parse(std::string_view command);
53 
54  void poll();
55 
56  void wrongNumArgs(unsigned argc, span<const TclObject> tokens, const char* message);
57 
58 private:
59  static int outputProc(ClientData clientData, const char* buf,
60  int toWrite, int* errorCodePtr);
61  static int commandProc(ClientData clientData, Tcl_Interp* interp,
62  int objc, Tcl_Obj* const objv[]);
63  static char* traceProc(ClientData clientData, Tcl_Interp* interp,
64  const char* part1, const char* part2, int flags);
65 
66  static Tcl_ChannelType channelType;
67  Tcl_Interp* interp;
68  InterpreterOutput* output;
69 
70  friend class TclObject;
71 };
72 
73 } // namespace openmsx
74 
75 #endif
void unsetVariable(const char *name)
Definition: Interpreter.cc:258
TclObject execute(zstring_view command)
Definition: Interpreter.cc:216
TclObject getCommandNames()
Definition: Interpreter.cc:206
void init(const char *programName)
Definition: Interpreter.cc:71
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
Definition: Interpreter.cc:445
void wrongNumArgs(unsigned argc, span< const TclObject > tokens, const char *message)
Definition: Interpreter.cc:461
void registerSetting(BaseSetting &variable)
Definition: Interpreter.cc:270
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:26
void createNamespace(const std::string &name)
Create the global namespace with given name.
Definition: Interpreter.cc:440
void unregisterCommand(Command &command)
Definition: Interpreter.cc:163
void setVariable(const TclObject &name, const TclObject &value)
Definition: Interpreter.cc:249
Interpreter(const Interpreter &)=delete
TclParser parse(std::string_view command)
Definition: Interpreter.cc:456
TclObject executeFile(zstring_view filename)
Definition: Interpreter.cc:225
bool isComplete(zstring_view command) const
Definition: Interpreter.cc:211
Interpreter & operator=(const Interpreter &)=delete
void unregisterSetting(BaseSetting &variable)
Definition: Interpreter.cc:322
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:148
void registerCommand(zstring_view name, Command &command)
Definition: Interpreter.cc:155
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:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename