37 const char* data = str.data();
38 int size = str.length();
39 if (size>0 && data[size-1]==
'\n') size -= 1;
40 return Tcl_NewStringObj(data, size);
48 if (size == 0)
return Tcl_NewListObj(0,
nullptr);
50 vector<Tcl_Obj*> vobj;
53 for (
size_t i=0; i<size; i++) {
54 vobj.push_back(Tcl_NewIntObj(
int(data[i])));
56 return Tcl_NewListObj(vobj.size(), vobj.data());
64 if (size == 0)
return Tcl_NewListObj(0,
nullptr);
66 vector<Tcl_Obj*> vobj;
69 for (
size_t i=0; i<size; i++) {
70 vobj.push_back(Tcl_NewIntObj(
int(data[i])));
72 return Tcl_NewListObj(vobj.size(), vobj.data());
94bool Rtcl::SetVar(Tcl_Interp* interp,
const std::string& varname, Tcl_Obj* pobj)
96 Tcl_Obj* pret =
nullptr;
98 size_t pos_pbeg = varname.find_first_of(
'(');
99 size_t pos_pend = varname.find_first_of(
')');
100 if (pos_pbeg != string::npos || pos_pend != string::npos) {
101 if (pos_pbeg == string::npos || pos_pbeg == 0 ||
102 pos_pend == string::npos || pos_pend != varname.length()-1 ||
103 pos_pend-pos_pbeg <= 1) {
104 Tcl_AppendResult(interp,
"illformed array name '", varname.c_str(),
108 string arrname(varname.substr(0,pos_pbeg));
109 string elename(varname.substr(pos_pbeg+1, pos_pend-pos_pbeg-1));
111 pret = Tcl_SetVar2Ex(interp, arrname.c_str(), elename.c_str(), pobj,
114 pret = Tcl_SetVar2Ex(interp, varname.c_str(),
nullptr, pobj,
127 if (varname !=
"-") {
128 return SetVar(interp, varname, pobj);
130 Tcl_SetObjResult(interp, pobj);
141 const char* res = Tcl_GetStringResult(interp);
143 Tcl_AppendResult(interp,
"\n",
nullptr);
void SetResult(Tcl_Interp *interp, const std::string &str)
bool SetVarOrResult(Tcl_Interp *interp, const std::string &varname, Tcl_Obj *pobj)
void AppendResultNewLines(Tcl_Interp *interp)
Tcl_Obj * NewLinesObj(const std::string &str)
bool SetVar(Tcl_Interp *interp, const std::string &varname, Tcl_Obj *pobj)
Tcl_Obj * NewListIntObj(const uint8_t *data, size_t size)
Declaration of class ReventLoop.