Go to the first, previous, next, last section, table of contents.


Low level interface library to Tcl/Tk

Version: 1.7#74 (2001/3/26, 12:12:29 CEST)

Version of last change: 0.9#79 (1999/5/4, 20:18:41 MEST)

The tcltk low level library permit obtain the results of the tcltk. This module defines a low level interface to be used by the library Tcl/Tk. Includes all the code related directly to the handling of sockets. This library should not be used by any user program, because is a low-level connection to Tcl/Tk.

How the Tcl/Tk interface works

Two sockets are created in Tcl/Tk to connect the TclInterpreter and the prolog process, the event_socket and the term_socket. There are two global variables: prolog_variables and terms. The value of any of the variables in the goal that is bound to a term will be stored in the array prolog_variables with the variable name as index. The string which contains the printed representation of prolog terms is Terms. There are Tcl/Tk procedures used to develop the interface:

prolog
Sends to term_socket the predicate tcl_result which contains the goal to execute. Returns the string execute and the goal.
prolog_event
Adds the new term to the terms queue.
prolog_delete_event
Deletes the first term of the terms queue.
prolog_list_events
Sends all the terms of the terms queue by the event_socket. The last element will be end_of_event_list.
prolog_cmd
Receives as an argument the tcltk code. Evaluates the code and returns throught the term_socket the predicate tcl_error if there was a mistake in the code or the predicate tcl_result with the result of the command executed. If the argument is prolog with a goal to execute, before finishing, the predicate evaluated by prolog is received. In order to get the value of the variables, predicates are compared using the unify_term procedure. Returs 0 when the sripts runs without errors, and 1 if there is an error.
prolog_one_event
Receives as an argument the term which is associated with one of the tk events. Sends through the event_socket the term and waits the unificated term by prolog. After that to obtain the value of the prolog_variables, calls the unify_term procedure.
prolog_thread_event
Receives as an argument the term which is associated with one of the tk events. Sends through the event_socket the term and waits the unificated term by prolog. After that to obtain the value of the prolog_variables, calls the unify_term procedure. In this case the term_socket is non blocking.
convert_variables
Receives as an argument, a string which contains symbols that can't be sends by the sockets. This procedure deletes them from the input string and returns the new string.
unify_term
Receives as arguments, a prolog term.

Usage and interface (tcltk_low_level)

  • Library usage: :- use_module(library(tcltk_low_level)).
  • Exports:
    • Predicates: new_interp/1, new_interp/2, new_interp_file/2, tcltk/2, tcltk_raw_code/2, receive_result/2, send_term/2, receive_event/2, receive_list/2, receive_confirm/2, delete/1.
  • Other modules used:
    • System library modules: terms, sockets/sockets, system, write, read, strings, lists, format.

Documentation on exports (tcltk_low_level)

PREDICATE: new_interp/1:

Usage: new_interp(-TclInterpreter)

  • Description: Creates two sockets to connect to the wish process, the term socket and the event socket and opens a pipe to process wish in a new shell.
  • Call and exit should be compatible with: -TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: new_interp/2:

Usage: new_interp(-TclInterpreter,+Options)

  • Description: Creates two sockets, the term socket and the event socket, and opens a pipe to process wish in a new shell invoked with the Options.
  • Call and exit should be compatible with: -TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1) +Options is currently instantiated to an atom. (term_typing:atom/1)

PREDICATE: new_interp_file/2:

Usage: new_interp_file(+FileName,-TclInterpreter)

  • Description: Creates two sockets, the term socket and the event socket, and opens a pipe to process wish in a new shell invoked with a FileName. FileName is treated as a name of a sript file
  • Call and exit should be compatible with: +FileName is a string (a list of character codes). (basic_props:string/1) -TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: tcltk/2:

Usage: tcltk(+Code,+TclInterpreter)

  • Description: Sends the Code converted to string to the TclInterpreter
  • Call and exit should be compatible with: +Code is a Tcl command. (tcltk_low_level:tclCommand/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: tcltk_raw_code/2:

Usage: tcltk_raw_code(+String,+TclInterpreter)

  • Description: Sends the tcltk code items of the Stream to the TclInterpreter
  • Call and exit should be compatible with: +String is a string (a list of character codes). (basic_props:string/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: receive_result/2:

Usage: receive_result(-Result,+TclInterpreter)

  • Description: Receives the Result of the last TclCommand into the TclInterpreter. If the TclCommand is not correct the wish process is terminated and a message appears showing the error
  • Call and exit should be compatible with: -Result is a string (a list of character codes). (basic_props:string/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: send_term/2:

Usage: send_term(+String,+TclInterpreter)

  • Description: Sends the goal executed to the TclInterpreter. String has the predicate with unified variables
  • Call and exit should be compatible with: +String is a string (a list of character codes). (basic_props:string/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: receive_event/2:

Usage: receive_event(-Event,+TclInterpreter)

  • Description: Receives the Event from the event socket of the TclInterpreter.
  • Call and exit should be compatible with: -Event is a list. (basic_props:list/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: receive_list/2:

Usage: receive_list(-List,+TclInterpreter)

  • Description: Receives the List from the event socket of the TclInterpreter.The List has all the predicates that have been inserted from Tcl/Tk with the command prolog_event. It is a list of terms.
  • Call and exit should be compatible with: -List is a list. (basic_props:list/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: receive_confirm/2:

Usage: receive_confirm(-String,+TclInterpreter)

  • Description: Receives the String from the event socket of the TclInterpreter when a term inserted into the event queue is managed.
  • Call and exit should be compatible with: -String is a string (a list of character codes). (basic_props:string/1) +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

PREDICATE: delete/1:

Usage: delete(+TclInterpreter)

  • Description: Terminates the wish process and closes pipe, term socket and event socket. Deletes the interpreter TclInterpreter from the system
  • Call and exit should be compatible with: +TclInterpreter is a reference to a Tcl interpreter. (tcltk_low_level:tclInterpreter/1)

Documentation on internals (tcltk_low_level)

PREDICATE: core/1:

Usage: core(+String)

  • Description: core/1 is a set of facts which contain Strings to be sent to the Tcl/Tk interpreter on startup. They implement miscelaneous Tcl/Tk procedures which are used by the Tcl/Tk interface.
  • Call and exit should be compatible with: +String is a string (a list of character codes). (basic_props:string/1)


Go to the first, previous, next, last section, table of contents.