tags:

views:

90

answers:

2

Is there any way to do this? It seems the only possible way to do this is by using ruby/tk and creating a tcl interpreter through that api. However, I'd like to use this on a system with no GUI (x windows). Am I out of options?

Thanks

A: 

if you are on the command line you can shell out to tclsh. tcl also has a C api so you should be able to use this to embed tcl in ruby if there is no preexisting way?

jk
+2  A: 

If you can invoke arbitrary simple functions in Tcl's C API, the key ones are:

  • Tcl_FindExecutable – Call this first to initialize the library
  • Tcl_CreateInterp – This returns a handle for a new execution context
  • Tcl_Eval – This evaluates a script; returns constants TCL_OK (0) or TCL_ERROR (1) (or a few others which are rare in general code)
  • Tcl_GetResult – This returns the result value (or error message)
  • Tcl_ResetResult – This clears the result value
  • Tcl_DeleteInterp – Maybe you can guess what this does…

You can also access "global" variables in the context with Tcl_GetVar and Tcl_SetVar; this is a very convenient way to pass in values that might not be valid scripts.

Donal Fellows
Is there any way to specify the path to the tcl interpreter?
Jordan
With `mkmf.rb`, you'll need `have_library` or `find_library`. I'm not nearly a good enough Ruby programmer to tell you how to make good use of that API.
Donal Fellows