Subject: [clisp-list] again: clisp and tk

From: Basim Al-Shaikhli <[email-masked]>
Date: Sat Nov 8 04:34:04 2003

Hi,

every now and then i make a new attempt to get Tk working from within 
clisp. i'm not sure if my question is rather a tcl/tk-question than a 
clisp question, but maybe someone has experience with this kind of stuff.

when i execute the following code, everything works fine: a tk-window 
with a button is drawn and the 'eventtest'-procedure is executed every 
second (which tells me that the event-loop is active).
but the button is dead. there's no reaction when clicking it.
am i missing some initialization?

(use-package "FFI")

(ffi:default-foreign-language :stdc)

(def-c-type tcl-interp c-pointer)

(def-call-out c-tcl-find-executable (:library "tcl84.dll")
  (:name "Tcl_FindExecutable")
  (:arguments (argv0 c-string)))

(def-call-out c-tcl-create-interp (:library "tcl84.dll")
 (:name "Tcl_CreateInterp")
 (:return-type tcl-interp))

(def-call-out c-tcl-eval (:library "tcl84.dll")
 (:name "Tcl_Eval")
 (:arguments (interp tcl-interp) (script c-string))
 (:return-type int))

(def-call-out c-tcl-exit (:library "tcl84.dll")
  (:name "Tcl_Exit")
  (:arguments (interp tcl-interp))
  (:return-type int))

(def-call-out c-tcl-init (:library "tcl84.dll")
  (:name "Tcl_Init")
  (:arguments (interp tcl-interp))
  (:return-type int))

(def-call-out c-tk-init (:library "tk84.dll")
  (:name "Tk_Init")
  (:arguments (interp tcl-interp))
  (:return-type int))

(def-call-out c-tk-mainloop (:library "tk84.dll")
  (:name "Tk_MainLoop")
  (:return-type nil))

(def-call-out c-tcl-get-obj-result (:library "tcl84.dll")
  (:name "Tcl_GetObjResult")
  (:arguments (interp tcl-interp))
  (:return-type c-pointer))

(def-call-out c-tcl-get-string-from-obj (:library "tcl84.dll")
  (:name "Tcl_GetStringFromObj")
  (:arguments (tcl-obj c-pointer) (length (c-ptr int)))
  (:return-type c-string))

(defparameter *tcl-interp* nil)

(defun tcl-create-interp ()
  (setq *tcl-interp* (c-tcl-create-interp))
  (if (not *tcl-interp*)
      (error "couldn't create interpreter.")))

(defun tcl-eval-script (string)
  (format t "> ~a~%" string)
  (c-tcl-eval *tcl-interp* string)
  (format t "~a~%" (tcl-result)))

(defun tcl-result ()
  (let ((obj (c-tcl-get-obj-result *tcl-interp*)))
    (if (null obj)
    ""
    (c-tcl-get-string-from-obj obj 0))))

(c-tcl-find-executable "")
(tcl-create-interp)
(c-tcl-init *tcl-interp*)
(c-tk-init *tcl-interp*)
(tcl-eval-script "package require Tk")
(tcl-eval-script "wm title . \"Hello World Window\"")
(tcl-eval-script "button .b -text HelloWorld -command \"puts hello\"")
(tcl-eval-script "pack .b")
(tcl-eval-script "proc eventtest {} {puts \"hello\"; after 1000 eventtest}")
(tcl-eval-script "after 1000 eventtest")
(c-tk-mainloop)