For those broad-minded enough to replace "function" by process, TV recommends IPC:

TV Don't forget that a possibly completely platform independent method is to pass messages over a socket to a C-code based process. Example: [1 ]. Long ago I've made some automation scripts to generate the frame for this sort of method which is quite possible in tcl.