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:
22 Interpreter(const Interpreter&) = delete;
27
28 void setOutput(InterpreterOutput* output_) { output = output_; }
29
30 void init(const char* programName) const;
31 [[nodiscard]] bool hasCommand(zstring_view name) const;
32 void registerCommand(zstring_view name, Command& command);
33 void unregisterCommand(Command& command);
34 [[nodiscard]] TclObject getCommandNames();
35 [[nodiscard]] bool isComplete(zstring_view command) const;
38
39 void setVariable(const TclObject& name, const TclObject& value);
40 void setVariable(const TclObject& arrayName, const TclObject& arrayIndex, const TclObject& value);
41 void unsetVariable(const char* name);
42 void registerSetting(BaseSetting& variable);
43 void unregisterSetting(BaseSetting& variable);
44
48 void createNamespace(const std::string& name);
49
53 void deleteNamespace(const std::string& name);
54
55 [[nodiscard]] TclParser parse(std::string_view command);
56 [[nodiscard]] bool validExpression(std::string_view expression);
57 [[nodiscard]] std::string parseCommandError(std::string_view command);
58 [[nodiscard]] std::string parseExpressionError(std::string_view expression);
59
60 void poll() const;
61
62 [[noreturn]] void wrongNumArgs(unsigned argc, std::span<const TclObject> tokens, const char* message);
63
64private:
65 static int outputProc(ClientData clientData, const char* buf,
66 int toWrite, int* errorCodePtr);
67 static int commandProc(ClientData clientData, Tcl_Interp* interp,
68 int objc, Tcl_Obj* const* objv);
69 static char* traceProc(ClientData clientData, Tcl_Interp* interp,
70 const char* part1, const char* part2, int flags);
71
72 static Tcl_ChannelType channelType;
73 Tcl_Interp* interp;
74 InterpreterOutput* output;
75
76 friend class TclObject;
77};
78
79} // namespace openmsx
80
81#endif
void unsetVariable(const char *name)
TclObject execute(zstring_view command)
TclObject getCommandNames()
void init(const char *programName) const
Interpreter(Interpreter &&)=delete
void wrongNumArgs(unsigned argc, std::span< const TclObject > tokens, const char *message)
std::string parseCommandError(std::string_view command)
Interpreter & operator=(Interpreter &&)=delete
Interpreter & operator=(const Interpreter &)=delete
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
std::string parseExpressionError(std::string_view expression)
bool validExpression(std::string_view expression)
void registerSetting(BaseSetting &variable)
void setOutput(InterpreterOutput *output_)
void createNamespace(const std::string &name)
Create the global namespace with given name.
void unregisterCommand(Command &command)
void setVariable(const TclObject &name, const TclObject &value)
Interpreter(const Interpreter &)=delete
TclParser parse(std::string_view command)
TclObject executeFile(zstring_view filename)
bool isComplete(zstring_view command) const
void unregisterSetting(BaseSetting &variable)
bool hasCommand(zstring_view name) const
void registerCommand(zstring_view name, Command &command)
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11