ADVANCED TOPICS
Scripting Languages
Pad++ is a prototyping system. It is intrinsically connected to an interpreted scripting language for writing programs that create items and interact with them. By default Pad++ comes with the Tcl scripting language, however, other languages may be added. Note that these other scripting languages can access the full functionality of Pad++, but can not access any of the Tk interface system. The Pad++ substrate supports a fairly general mechanism for incorporating new scripting languages. We have done this with the Elk version of Scheme. The README.SCHEME file describes specifically how to build Pad++ with Scheme support, and how to access Pad++ from Scheme. If Pad++ is built with Scheme included, then the setlanguage and settoplevel commands will apply to Scheme as well as Tcl. These commands control which language is to be used.
The setlanguage command specifies what language is to be used to evaluate all callback scripts that are created in the future. The settoplevel command specifies what language the toplevel interpreter should use. In addition, the padwish executable has a -language option that specifies what language the interpreter should start using. It defaults to Tcl. The following session trace shows how the two languages work together:
surf[164] padwish -language scheme
Real-time image zooming supported.
> (+ 2 2)
4
> (pad '.pad 'create 'line 0 0 50 50)
22
> (pad '.pad 'itemconfig 22 '-penwidth 5)
> (pad '.pad 'bind 22 '<Enter> "(pad '.pad 'ic %O '-pen 'red)")
> (pad '.pad 'bind 22 '<Leave> "(pad '.pad 'ic %O '-pen 'black)")
> (settoplevel 'tcl)
%
% puts [expr 2 + 2]
4
% .pad create line 0 0 0 50
23
% .pad settoplevel scheme
scheme
>
>
> (exit)
surf[165]
Adding a new interpreted scripting language to Pad++ requires creating some C++ interface code, modifying the Pad++ C++ substrate to access that code, and building a new padwish executable. Several callback procedures must be defined to add a language. Then a new instance of the Pad_Language class must be created in tkMain.C. The necessary callback procedures are:
- Callback when a pad widget is created. This routine gets called whenever a new Pad++ widget is created. This leads to the creation of a function for accessing the new widget in the new scripting language.
Pad_CreateProc *create_proc;
- Callback to process pad command. There should be a command for accessing the new scripting language from Tcl, without using the top-level interpreter. For example, it should be possible to load and evaluate files, and access variables from that language. This routine gets called when the Tcl command is evaluated, and it must implement this functionality.
Pad_CommandProc *command_proc;
- Callback that specifies if command is complete and should be evaluated. Given a command in the scripting language, this routine typically counts parenthesis, quotes, and braces, and determines if the command is partial or complete. This routine is called whenever the user presses the return key at the top-level interpreter to determine if the command should be evaluated yet.
Pad_CompleteProc *complete_proc;
- Callback to generate a prompt. Given a flag specifying whether a command is, or is not complete (according to the complete_proc), this routine should generate a distinctive prompt for this language.
Pad_PromptProc *prompt_proc;
- Callback to evaluate a string. This routine should evaluate the specified string as a command in the scripting language.
Pad_EvalProc *eval_proc;
There are several relevant C++ files that should be examined to see how Scheme is currently connected to Pad++. The files are all in the PADHOME/src directory. pad-scheme.C implements all of the callback routines that form the connection between C++ and scheme. script.h declares the Pad_Language and Pad_Script classes. script.C implements those classes. tkMain.C instantiates the Pad_Language class for each available scripting language.
Pad++ Programmer's Guide - 10 JUN 1996
Generated with Harlequin WebMaker
Web Accessibility