c# - Tcl Channel in GUI Application -
im trying embedded tcl interpreter c# gui application, , works fine, attachingnewfunction tclcommand. 1 thing hard me, want redirect stdout, stdin, stderr textbox'es. im working c++, becouse easier debug , compile. using code
tcl_channel stdout = tcl_getstdchannel(tcl_stdout); tcl_unregisterchannel(interp,stdout); tcl_channel mystdout = tcl_createchannel(typeptr, "stdout", null, tcl_readable | tcl_writable); tcl_registerchannel(interp, mystdout); tcl_setstdchannel(mystdout, tcl_stdout);
to register new stdout, typeptr like
typeptr->typename = "stdout"; typeptr->version = tcl_channel_version_2; typeptr->gethandleproc = tcl_mydrivergethandleproc; typeptr->inputproc = tcl_mydriverinputproc; typeptr->outputproc = tcl_mydriveroutputproc; typeptr->flushproc = tcl_mydriverflushproc; typeptr->watchproc = tcl_mydriverwatchproc; typeptr->closeproc = tcl_mydrivercloseproc; typeptr->blockmodeproc = tcl_mydriverblockmodeproc; typeptr->seekproc = null; typeptr->close2proc = null; typeptr->handlerproc = null; typeptr->wideseekproc = null; typeptr->truncateproc = null; typeptr->setoptionproc = null; typeptr->getoptionproc = null; typeptr->threadactionproc = null;
and every function connect return tcl_ok or einval (i know api) , puts text file, example
int tcl_mydrivercloseproc(clientdata instancedata, tcl_interp *interp) { std::cout << "\n tcl_mydrivercloseproc\n"; file << "\n tcl_mydrivercloseproc\n"; file.flush(); return einval; }
i use std::cout debugging, dont believe him. when compile&run nothing happen, stdout doesnt work, result example
result:stderr file8adcd0 stdout stdin: result::
the code compiled
tcl_getchannelnames(interp); std::cout << "result:" << tcl_getstringresult(interp) << ":\n"; tcl_eval(interp, "puts someonehelp"); std::cout << "result:" << tcl_getstringresult(interp) << ":\n";
i cannot create custom channel , used like
"puts mychannel plehdeeni"
when done c++ im going make function in c# writing 3 tcl standart channels textbox'es, easy.
the documentation of low level of tcl channels isn't easiest, instructive @ example code. generic/tkconsole.c
in tk's implementation shows how real stdout , stderr redirections done. in particular, fields need non-null values name
, version
, closeproc
(or close2proc
), inputproc
, outputproc
, watchproc
, gethandleproc
, , many of can dummies channels create handle stdout , stderr.
however, tk console widget doesn't support providing real stdin (instead, uses tcl_eval
run commands in main interpreter) , 1 provides claims @ end-of-file. it's bit of cop-out. also, none of channels at all able passed subprocesses don't have representation @ level of os. fixing require enormously more work (perhaps anonymous pipes , worker threads , tricks deal inevitable buffering issues; using expect package more complete job, though @ cost of even more complexity).
you want return non-error results things. example, returning 0
outputproc
cause great problems generic parts of tcl's channel code; assumes means things blocked , buffers things until gets told have become unblocked. real swallow-everything first try, return number of bytes written same number of bytes asked write. similarly, important make closeproc
work right; if you've no instance data dispose of or underlying os resources rid of, can return 0
there indicate ok.
Comments
Post a Comment