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 <span>
9#include <string_view>
10#include <string>
11
12namespace openmsx {
13
14class Command;
15class BaseSetting;
16class InterpreterOutput;
17
19{
20public:
21 Interpreter(const Interpreter&) = delete;
23
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, std::span<const TclObject> tokens, const char* message);
58
59private:
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: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 wrongNumArgs(unsigned argc, std::span< const TclObject > tokens, const char *message)
Definition: Interpreter.cc:461
Interpreter & operator=(const Interpreter &)=delete
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
Definition: Interpreter.cc:445
void registerSetting(BaseSetting &variable)
Definition: Interpreter.cc:270
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:27
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
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
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