Documentation ¶
Overview ¶
Package tcl is a port of the Tool Command Language.
A sperate Tcl shell is in the gotclsh directory.
Do not use in production.
Changelog:
2020-09-03 v1.2.0 is now completelely CGo-free.
2020-08-04: beta2 released for linux/amd64 only. Support for threads, sockets and fork is not yet implemented. Some tests still crash, those are disabled at the moment.
Index ¶
- func Library(directory string) error
- func LibraryFileSystem() http.FileSystem
- type CmdProc
- type Command
- type DeleteProc
- type Interp
- func (in *Interp) Close() error
- func (in *Interp) Eval(script string) (string, error)
- func (in *Interp) MustClose()
- func (in *Interp) MustEval(script string) string
- func (in *Interp) MustNewCommand(name string, proc CmdProc, clientData interface{}, del DeleteProc) *Command
- func (in *Interp) NewCommand(name string, proc CmdProc, clientData interface{}, del DeleteProc) (*Command, error)
- func (in *Interp) SetResult(s string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LibraryFileSystem ¶
func LibraryFileSystem() http.FileSystem
LibraryFileSystem returns a http.FileSystem containing the Tcl library.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a Tcl command.
type DeleteProc ¶
type DeleteProc func(clientData interface{})
DeleteProc is a function called when CmdProc is deleted.
type Interp ¶
type Interp struct {
// contains filtered or unexported fields
}
Interp represents a Tcl interpreter.
func MustNewInterp ¶
func MustNewInterp() *Interp
MustNewInterp is like NewInterp but panics on error.
func (*Interp) Eval ¶
Eval evaluates script and returns the interpreter; result and error, if any.
Example ¶
in := MustNewInterp() s := in.MustEval(` # This is the Tcl script # ---------------------- set a 42 incr a # ---------------------- `) in.MustClose() fmt.Println(s)
Output: 43
func (*Interp) MustClose ¶
func (in *Interp) MustClose()
MustClose is like Close but panics on error.
func (*Interp) MustNewCommand ¶
func (in *Interp) MustNewCommand(name string, proc CmdProc, clientData interface{}, del DeleteProc) *Command
MustNewCommand is like NewCommand but panics on error.
func (*Interp) NewCommand ¶
func (in *Interp) NewCommand(name string, proc CmdProc, clientData interface{}, del DeleteProc) (*Command, error)
NewCommand returns a newly created Tcl command or an error, if any.
Example ¶
in := MustNewInterp() var delTrace string in.MustNewCommand( "::go::echo", func(clientData interface{}, in *Interp, args []string) int { // Go implementation of the Tcl ::go::echo command args = append(args[1:], fmt.Sprint(clientData)) in.SetResult(strings.Join(args, " ")) return tcl.TCL_OK }, 42, // client data func(clientData interface{}) { // Go implemetation of the command delete handler delTrace = fmt.Sprint(clientData) }, ) fmt.Println(in.MustEval("::go::echo 123 foo bar")) in.MustClose() fmt.Println(delTrace)
Output: 123 foo bar 42 42