Hi, 

From: tony summerfelt <snowzone5 / hotmail.com>
Subject: Re: calling tcl/tk scripts from ruby
Date: Tue, 11 Jan 2005 13:20:27 +0900
Message-ID: <alk6u0d4s5jkadb0gqjkfb4c383ebcv66f / 4ax.com>
> there's a bit of a logistics problem. usuall tk callbacks are defined
> within the creation of the widget...
> 
> for example:
> 
> button .b -text "Quit" -command {proc_quit}
> pack .b
> 
> am i wasting my time working with this? each button would have an
> associated -command {proc} attached to it that would ideally be passed
> to the ruby program. 

Hmm...
In the procedure, if you have values that should be passed to ruby, 
the values must be able to accessed in global space, because a button 
widget's command option doesn't return a value. 

# If you don't have such values, your script will work properly
# without editing. 

When the procedure set the values to global variables, 
you can access the variables with TkVarAccess.new(varname). 
And you can trace or wait the TkVarAccess object. 

If you want to call the Tk procedure and additional Ruby operation, 
you can wrap the Tk procedure by a Ruby's procedure. 

# Then, you can get the return value of the Tk procedure. 

For example, 
   ( ... after loading your example ... )
  b = TkButton.new(:widgetname=>'.b', :without_creating=>true)
  cmd = b.command  # get the current command option's value
  b.command{ret = Tk.ip_eval(cmd); p ['ruby', ret]}

You can also use 'ruby' (or 'ruby_cmd' on Ruby-1.8.2) on the Tk. 
tcltklib adds them to the Tk interpreter.
'ruby script' calls Ruby API: rb_eval_string(script). 
'ruby_cmd receiver method ?arg ...?' calls 'receiver.method(arg, ...)'. 
However, the receiver must be a module or a class or a constant or 
a global variable.

Maybe, one of those ways helps you ...
-- 
Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)