00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034
00035 #ifndef GROOVX_TCL_INTERP_H_UTC20050628162420_DEFINED
00036 #define GROOVX_TCL_INTERP_H_UTC20050628162420_DEFINED
00037
00038 #include "tcl/conversions.h"
00039 #include "tcl/obj.h"
00040
00041 #include "rutz/fileposition.h"
00042 #include "rutz/shared_ptr.h"
00043
00044 struct Tcl_Interp;
00045 typedef struct Tcl_Obj Tcl_Obj;
00046
00047 namespace rutz
00048 {
00049 class fstring;
00050 }
00051
00052 namespace tcl
00053 {
00054 class interpreter;
00055 class list;
00056
00058 enum error_strategy
00059 {
00060 THROW_ERROR,
00061 IGNORE_ERROR
00062 };
00063 }
00064
00065
00066
00068
00072 class tcl::interpreter
00073 {
00074 interpreter& operator=(const interpreter&);
00075
00076 public:
00077 interpreter(Tcl_Interp* interp);
00078 interpreter(const interpreter& other) throw();
00079 ~interpreter() throw();
00080
00081
00082 bool is_valid() const throw() { return m_interp != 0; }
00083
00085 Tcl_Interp* intp() const;
00086
00087 bool is_deleted() const throw();
00088 void forget_interp() throw();
00089 void destroy() throw();
00090
00092 void pkg_provide(const char* name, const char* version);
00093
00095 bool eval_boolean_expr(const tcl::obj& obj) const;
00096
00098
00102 bool eval(const char* code, error_strategy strategy = THROW_ERROR);
00103
00105
00109 bool eval(const rutz::fstring& code, error_strategy strategy = THROW_ERROR);
00110
00112
00116 bool eval(const tcl::obj& code, error_strategy strategy = THROW_ERROR);
00117
00119
00123 bool eval_objv(const tcl::list& objv, error_strategy strategy = THROW_ERROR);
00124
00126
00127 bool eval_file(const char* fname);
00128
00129 void source_rc_file();
00130
00131
00132 void reset_result() const;
00133 void append_result(const char* msg) const;
00134 void append_result(const rutz::fstring& msg) const;
00135
00136 template <class T>
00137 T get_result() const
00138 {
00139 return tcl::convert_to<T>(get_obj_result());
00140 }
00141
00142 template <class T>
00143 void set_result(const T& x)
00144 {
00145 set_obj_result(tcl::convert_from(x).get());
00146 }
00147
00148
00149 void set_global_var(const char* var_name, const tcl::obj& var) const;
00150 void unset_global_var(const char* var_name) const;
00151
00152 template <class T>
00153 T get_global_var(const char* name1, const char* name2=0) const
00154 {
00155 return tcl::convert_to<T>(get_obj_global_var(name1, name2));
00156 }
00157
00158 void link_int(const char* var_name, int* addr, bool read_only);
00159 void link_double(const char* var_name, double* addr, bool read_only);
00160 void link_boolean(const char* var_name, int* addr, bool read_only);
00161
00162
00163 void handle_live_exception(const char* where,
00164 const rutz::file_pos& pos) throw();
00165 void background_error() throw();
00166
00167 void add_error_info(const char* info);
00168
00169
00170 static void clear_event_queue();
00171
00172
00173 bool has_command(const char* cmd_name) const;
00174 void delete_command(const char* cmd_name);
00175
00176 rutz::fstring get_proc_body(const char* proc_name);
00177 void create_proc(const char* namesp, const char* proc_name,
00178 const char* args, const char* body);
00179 void delete_proc(const char* namesp, const char* proc_name);
00180
00181 private:
00182 Tcl_Obj* get_obj_result() const;
00183 Tcl_Obj* get_obj_global_var(const char* name1, const char* name2) const;
00184 void set_obj_result(Tcl_Obj* obj);
00185
00186 Tcl_Interp* m_interp;
00187 };
00188
00189 static const char __attribute__((used)) vcid_groovx_tcl_interp_h_utc20050628162420[] = "$Id: interp.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00190 #endif // !GROOVX_TCL_INTERP_H_UTC20050628162420_DEFINED