Updated 2017-06-09 08:57:11 by dbohdan

Wiki pages with Critcl examples (incomplete list):


LV: Has anyone investigated making use of Critcl to create an HTML rendering widget, perhaps based on BrowseX?

JCW: Yep, Tkhtml can be built with Critcl, though it's tricky. See [1], now in critlib.

Has someone looked at http://root.cern.ch/root/Cint.html

as a possible way to integrate C with Tcl without having to compile C...

RFox I have a project to look at other bits and pieces of Root...a slow project, however not CInt specifically though it could be addeed to that project.

SWT: I have built a working cint shared lib for tcl. It works great! Now to "run" c code the cint library is only needed for each platform that support is required for.

Brian Theado 17Dec2004 - Examples with Tcl_Obj* return type

The presence of Tcl_IncrRefCount is crucial here and nothing gets returned without it. I guess Critcl automatically decrements the reference count on this return type. Could someone provide a counter example where the automatic reference count decrement is useful?
package require critcl
critcl::cproc abc {} Tcl_Obj* {
    char test[4] = "abc";
    Tcl_Obj * rv = Tcl_NewStringObj ("abc", 3);
    Tcl_IncrRefCount (rv);
    return rv;
}
critcl::cproc 123 {} Tcl_Obj* {
    char test[3] = {1, 2, 3};
    Tcl_Obj * obj = Tcl_NewByteArrayObj (test, 3);
    Tcl_IncrRefCount (obj);
    return obj;
}
puts [abc]
binary scan [123] H* result
puts $result

Output:
abc
010203

2005-09-02 Sarnold See also Critcl example with the Mancala game and foriter - a loop command.

2006-11-21 dzach Could someone post a basic critcl snipet on how to access the snack sound library? Play a sound or record a sound, for instance?

Lars H, 2007-10-09: Saw [2], which compares performance of a native Perl operation (binary xor of two strings, now how screwy is that?!) with implementations in Java and Tcl. Thinking that the natural way for a Tcler to implement that, if performance really matters, is to code it in C, I did a Critcl implementation:
package require critcl
 
critcl::ccommand xor {cd interp objc objv} {
    char* sP;
    char* kP;
    int slen, klen;
    Tcl_Obj* resObj;
     
    if (objc != 3) { /* This can be improved. */
        return TCL_ERROR;
    }
     
    sP = Tcl_GetByteArrayFromObj(objv[1],&slen);
    resObj = Tcl_NewByteArrayObj(sP,slen);
    sP = Tcl_GetByteArrayFromObj(resObj,(int*)NULL);
    kP = Tcl_GetByteArrayFromObj(objv[2],&klen);
    for (; slen>0 && klen>0 ; slen--, klen--) {
        *sP++ ^= *kP++;
    }
    Tcl_SetObjResult(interp,resObj);
    return TCL_OK;
}
puts [xor "A!" "bB"]

Prints "#c".