It is not clear, after reading Critcl pages, exactly what files have to be installed on a Windows machine to use Critcl. Does one have to install the critcl source code and then some other piece(s)?
June 2002 - Yes, you need critcl installed as a normal Tcl package (i.e. so "package require critcl" works in tclsh or tclkit) and you need to set things up so "gcc" works. What I do is install the mingw system, and set up the PATH so "gcc" works from the command line. That's it. -jcw
Q: When does the code get compiled? In an example such as
critcl::cproc triple {int i} int { return i * 3; /* this is C code */ } puts "three times 123 is [triple 123]"
when is the C-coded triple command created?
A: When it is called the first time. The critcl::cproc command creates an auto_index entry for the command it defines. The script in this entry causes complete C sources to be written, the compiler to be run, and the resulting dynamic library to be loaded. (It takes longer time than the source or load you'd normally find in such entries, and there are more ways in which it can go wrong, but there is no difference in principle.) Compiled commands are created on a per source-file basis.
Paolo Noli: A little question: How to call a tcl commands from inside a c funcion declared with the statement "ccode"? (I need this to implement a callback procedure.. but I think this can be an interesting tip for others people. :)
Instructions for installing critcl in an existing "traditional" (i.e. non-starkit) Tcl installation
tclkit critcl.kit test-critcl.tcl
tclkit sdx.kit critcl.kit
cd critcl.vfs/lib
cp -a * /path/to/tcl/lib cd /path/to/tcl/lib
ln -s /path/to/tcl/lib/app-critcl/critcl.tcl /usr/local/bin/critcl
tclsh test-critcl.tcl
critcl test-critcl.tcl
The file test-critcl.tcl:
lappend auto_path . package require critcl critcl::cproc triple {int i} int { return i * 3; /* this is C code */ } puts "three times 123 is [triple 123]"
At present (June 2006), there is a severe bug [L1 ] in the pkgIndex scripts generated by the Critcl package builder. These scripts will, if they are at all installed in your system (it doesn't matter whether you required them), evaluate the command
package provide critcl 0.0
and that blocks loading any functional form of critcl. In order to make it work, you may have to do something like the following trickery instead of a normal package require:
# Save [package ifneeded] scripts for functional versions of critcl. set cmds "" foreach ver [package versions critcl] { if {$ver ne "0.0"} then { append cmds [list package ifneeded critcl $ver [package ifneeded critcl $ver]] \n } } # Forget critcl package declarations package forget critcl # Restore useful critcl package declarations eval $cmds # Now load a working package package require critcl