1 ;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
4 Celtk -- Cells
, Tcl
, and Tk
6 Copyright
(C) 2006 by Kenneth Tilton
8 This library is free software
; you can redistribute it and/or
9 modify it under the terms of the Lisp Lesser GNU Public License
10 (http://opensource.franz.com
/preamble.html
), known as the LLGPL.
12 This library is distributed WITHOUT ANY WARRANTY
; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the Lisp Lesser GNU Public License for more details.
24 (define-foreign-library Tcl
25 (:darwin
(:framework
"Tcl"))
26 (:windows
(:or
"Tcl85.dll"))
28 (t (:default
"libtcl")))
30 (define-foreign-library Tk
31 (:darwin
(:framework
"Tk"))
32 (:windows
(:or
"Tk85.dll"))
34 (t (:default
"libtk")))
36 (define-foreign-library Tile
37 ;(:darwin (:framework "Tk"))
38 (:windows
(:or
"tile078.dll"))
40 (t (:default
"libtk")))
42 (defctype tcl-retcode
:int
)
44 (defcenum tcl-retcode-values
48 (defmethod translate-from-foreign (value (type (eql 'tcl-retcode
)))
49 (unless (eq value
(foreign-enum-value 'tcl-retcode-values
:tcl-ok
))
50 (error "Tcl error: ~a" (tcl-get-string-result *tki
*)))
53 ;; --- initialization ----------------------------------------
55 (defcfun ("Tcl_FindExecutable" tcl-find-executable
) :void
58 (defcfun ("Tcl_Init" Tcl_Init
) tcl-retcode
61 (defcfun ("Tk_Init" Tk_Init
) tcl-retcode
64 (defcallback Tk_AppInit tcl-retcode
67 (tk-app-init interp
)))
69 (defun tk-app-init (interp)
74 (foreign-enum-value 'tcl-retcode-values
:tcl-ok
))
78 (defcfun ("Tk_MainEx" %Tk_MainEx
) :void
81 (Tk_AppInitProc :pointer
)
85 (with-foreign-string (argv (argv0))
87 (get-callback 'Tk_AppInit
)
92 (defcfun ("Tcl_CreateInterp" Tcl_CreateInterp
) :pointer
)
94 (defcfun ("Tcl_DeleteInterp" tcl-delete-interp
) :void
97 ;;; --- windows ----------------------------------
99 (defcfun ("Tk_GetNumMainWindows" tk-get-num-main-windows
) :int
)
100 (defcfun ("Tk_MainWindow" tk-main-window
) :pointer
(interp :pointer
))
102 (defcfun ("Tk_NameToWindow" tk-name-to-window
) :pointer
105 (related-tkwin :pointer
))
107 ;;; --- eval -----------------------------------------------
109 (defcfun ("Tcl_EvalFile" %Tcl_EvalFile
) tcl-retcode
111 (filename-cstr :string
))
113 (defun Tcl_EvalFile (interp filename
)
114 (with-foreign-string (filename-cstr filename
)
115 (%Tcl_EvalFile interp filename-cstr
)))
117 (defcfun ("Tcl_Eval" %Tcl_Eval
) tcl-retcode
119 (script-cstr :string
))
121 (defun tcl-eval (i s
)
124 (defcfun ("Tcl_EvalEx" %Tcl_EvalEx
) tcl-retcode
126 (script-cstr :string
)
130 (defun tcl-eval-ex (i s
)
131 (%Tcl_EvalEx i s -
1 0))
133 (defcfun ("Tcl_GetVar" tcl-get-var
) :string
138 (defcfun ("Tcl_SetVar" tcl-set-var
) :string
144 (defcfun ("Tcl_GetStringResult" tcl-get-string-result
) :string
147 ;; ----------------------------------------------------------------------------
148 ;; Tcl_CreateCommand - used to implement direct callbacks
149 ;; ----------------------------------------------------------------------------
151 (defcfun ("Tcl_CreateCommand" tcl-create-command
) :pointer
155 (client-data :pointer
)
156 (delete-proc :pointer
))
158 ;; ----------------------------------------------------------------------------
159 ;; Tcl/Tk channel related stuff
160 ;; ----------------------------------------------------------------------------
162 (defcfun ("Tcl_RegisterChannel" Tcl_RegisterChannel
) :void
166 (defcfun ("Tcl_UnregisterChannel" Tcl_UnregisterChannel
) :void
170 (defcfun ("Tcl_MakeFileChannel" Tcl_MakeFileChannel
) :pointer
174 (defcfun ("Tcl_GetChannelName" Tcl_GetChannelName
) :string
177 (defcfun ("Tcl_GetChannelType" Tcl_GetChannelType
) :pointer
181 (defcfun ("Tcl_GetChannel" Tcl_GetChannel
) :pointer
183 (channelName :string
)
186 ;; Initialization mgmt - required to avoid multiple library loads
188 (defvar *initialized
* nil
)
190 (defun set-initialized ()
191 (setq *initialized
* t
))
193 (defun reset-initialized ()
194 (setq *initialized
* nil
))
200 #+allegro
(sys:command-line-argument
0)
201 #+lispworks
(nth 0 system
:*line-arguments-list
*) ;; portable to OS X
202 #+sbcl
(nth 0 sb-ext
:*posix-argv
*)
203 #+openmcl
(car ccl
:*command-line-argument-list
*)
204 #-
(or allegro lispworks sbcl openmcl
)
205 (error "argv0 function not implemented for this lisp"))
207 (defun tk-interp-init-ensure ()
208 (unless *initialized
*
209 (use-foreign-library Tcl
)
210 (use-foreign-library Tk
)
211 #-macosx
(use-foreign-library Tile
)
212 #-macosx
(pushnew :tile cl-user
::*features
*)
213 (use-foreign-library Togl
)
214 (tcl-find-executable (argv0))
217 ;; Send a script to a given Tcl/Tk interpreter
219 (defun eval-script (interp script
)
222 (tcl-eval interp script
))