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) const;
30 [[nodiscard]] 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 setVariable(const TclObject& arrayName, const TclObject& arrayIndex, const TclObject& value);
40 void unsetVariable(const char* name);
41 void registerSetting(BaseSetting& variable);
42 void unregisterSetting(BaseSetting& variable);
43
47 void createNamespace(const std::string& name);
48
52 void deleteNamespace(const std::string& name);
53
54 [[nodiscard]] TclParser parse(std::string_view command);
55 [[nodiscard]] bool validCommand(std::string_view command);
56 [[nodiscard]] bool validExpression(std::string_view expression);
57
58 void poll() const;
59
60 [[noreturn]] void wrongNumArgs(unsigned argc, std::span<const TclObject> tokens, const char* message);
61
62private:
63 static int outputProc(ClientData clientData, const char* buf,
64 int toWrite, int* errorCodePtr);
65 static int commandProc(ClientData clientData, Tcl_Interp* interp,
66 int objc, Tcl_Obj* const* objv);
67 static char* traceProc(ClientData clientData, Tcl_Interp* interp,
68 const char* part1, const char* part2, int flags);
69
70 static Tcl_ChannelType channelType;
71 Tcl_Interp* interp;
72 InterpreterOutput* output;
73
74 friend class TclObject;
75};
76
77} // namespace openmsx
78
79#endif
void unsetVariable(const char *name)
TclObject execute(zstring_view command)
TclObject getCommandNames()
void init(const char *programName) const
void wrongNumArgs(unsigned argc, std::span< const TclObject > tokens, const char *message)
Interpreter & operator=(const Interpreter &)=delete
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
bool validCommand(std::string_view command)
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