SNOBOL4STCL(3) | CSNOBOL4 Manual | SNOBOL4STCL(3) |
NAME¶
snobol4tcl - SNOBOL4 Tcl/Tk interface
SYNOPSIS¶
-INCLUDE 'stcl.sno'
DESCRIPTION¶
Tcl is an embedable scripting language developed by John Osterhout, while at the University of California, Berkeley. Tk is a graphical user interface toolkit developed for Tcl.
This page describes a facility for invoking Tcl and Tk from SNOBOL4 programs, inspired by Arjen Markus' "ftcl" FORTRAN/Tcl interface
- tclhandle = STCL_CREATEINTERP()
- creates a Tcl interpreter and returns a handle which can be passed to the remaining functions.
- STCL_EVALFILE(tclhandle,filename)
- reads a Tcl script file into the referenced Tcl interpreter.
- STCL_GETVAR(tclhandle,varname)
- retrieves the string value of named variable from a Tcl interpreter.
- STCL_SETVAR(tclhandle,varname,value)
- sets the string value of named variable in a Tcl interpreter.
- STCL_EVAL(tclhandle,tclstmt)
- evaluates a string containing Tcl code in a Tcl interpreter.
- STCL_DELETEINTERP(tclhandle)
- destroys a Tcl interpreter.
- STCL_NEWSTRINGOBJ(string)
- Creates a tcl string object, and returns a handle for it.
- STCL_GETSTRINGFROMOBJ(objhandle)
- Get string from an Object (given object handle).
- STCL_APPENDTOOBJ(objhandle, string)
- Append string to an Object returns null string, or failure
- STCL_EVALOBJEX(tclhandle, objhandle, flags)
- Evaluate (execute) an object -- saves compiled byte code. Returns integer.
- objhandle = STCL_GETOBJRESULT(tclhandle)
- return a result object from an interpreter (after TCL_EVALOBJEX)
- STCL_OBJSETVAR2(tclhandle, oh_name1, oh_name2, oh_value, flags)
- STCL_OBJGETVAR2(tclhandle, oh_name1, oh_name2, flags)
- STCL_RELEASEOBJ(objhandle)
- release a Tcl Object
EXAMPLE¶
-INCLUDE 'stcl.sno'
INTERP = STCL_CREATEINTERP()
TCL_VERSION = STCL_GETVAR(INTERP, "tcl_version")
OUTPUT = IDENT(TCL_VERSION) "Could not get tcl_version" :S(END)
OUTPUT = "Tcl Version: " TCL_VERSION
# check Tcl version
NUM = SPAN('0123456789')
VPAT = NUM '.' NUM
TCL_VERSION VPAT . VER :S(CHECKV)
OUTPUT = "could not parse tcl_version" :(END)
CHECKV LT(VER, 8.4) :S(CHECKTK)
# Tcl 8.4 and later can dynamicly load Tk!
STCL_EVAL(INTERP, "package require Tk") :F(END)
# Check for Tk CHECKTK TK_VERSION = STCL_GETVAR(INTERP, "tk_version") :F(NO_TK)
DIFFER(TK_VERSION) :S(HAVETK) NO_TK OUTPUT = "Could not find tk_version" :(END)
HAVETK OUTPUT = "Tk version: " TK_VERSION
LOOP OUTPUT = STCL_EVAL(INTERP, + 'tk_messageBox -message "Alert!"' + ' -type ok -icon info')
VAL = STCL_EVAL(INTERP, + 'tk_messageBox -message "Really quit?"' + ' -type yesno -icon question')
OUTPUT = VAL
DIFFER(VAL, "yes") :S(LOOP) END
SEE ALSO¶
AUTHOR¶
Philip L. Budne
March 31, 2022 | CSNOBOL4B 2.3.1 |