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 validCommand(std::string_view command);
57 [[nodiscard]] bool validExpression(std::string_view expression);
58
59 void poll() const;
60
61 [[noreturn]] void wrongNumArgs(unsigned argc, std::span<const TclObject> tokens, const char* message);
62
63private:
64 static int outputProc(ClientData clientData, const char* buf,
65 int toWrite, int* errorCodePtr);
66 static int commandProc(ClientData clientData, Tcl_Interp* interp,
67 int objc, Tcl_Obj* const* objv);
68 static char* traceProc(ClientData clientData, Tcl_Interp* interp,
69 const char* part1, const char* part2, int flags);
70
71 static Tcl_ChannelType channelType;
72 Tcl_Interp* interp;
73 InterpreterOutput* output;
74
75 friend class TclObject;
76};
77
78} // namespace openmsx
79
80#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)
Interpreter & operator=(Interpreter &&)=delete
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