In Files

  • tk/lib/multi-tk.rb
  • tk/lib/tk.rb
  • tk/tcltklib.c

Class/Module Index [+]

Quicksearch

TclTkIp

add ThreadGroup check to ::new

Public Class Methods

__new__(*args) click to toggle source
Alias for: new
new(*args) click to toggle source

initialize interpreter

 
               # File tk/lib/multi-tk.rb, line 27
def new(*args)
  if Thread.current.group != ThreadGroup::Default
    raise SecurityError, 'only ThreadGroup::Default can call TclTkIp.new'
  end
  obj = __new__(*args)
  obj.instance_eval{
    @force_default_encoding ||= TkUtil.untrust([false])
    @encoding ||= TkUtil.untrust([nil])
    def @encoding.to_s; self.join(nil); end
  }
  obj
end
            
Also aliased as: __new__
new(*args) click to toggle source
 
               # File tk/lib/tk.rb, line 30
def initialize(*args)
  __initialize__(*args)

  @force_default_encoding ||= TkUtil.untrust([false])
  @encoding ||= TkUtil.untrust([nil])
  def @encoding.to_s; self.join(nil); end
end
            
Also aliased as: __initialize__

Public Instance Methods

__eval(cmd) click to toggle source
Alias for: _eval
__eval__(cmd) click to toggle source
Alias for: _eval
__fromUTF8(str, enc = nil) click to toggle source
Alias for: _fromUTF8
__initialize__(*args) click to toggle source
Alias for: new
__invoke(*cmds) click to toggle source
Alias for: _invoke
__invoke__(*cmds) click to toggle source
Alias for: _invoke
__toUTF8(str, enc = nil) click to toggle source
Alias for: _toUTF8
_cancel_eval(p1 = v1) click to toggle source
 
               static VALUE
ip_cancel_eval(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    VALUE retval;

    if (rb_scan_args(argc, argv, "01", &retval) == 0) {
        retval = Qnil;
    }
    if (ip_cancel_eval_core(get_ip(self)->ip, retval, 0) == TCL_OK) {
      return Qtrue;
    } else {
      return Qfalse;
    }
}
            
_cancel_eval_unwind(p1 = v1) click to toggle source
 
               static VALUE
ip_cancel_eval_unwind(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    int flag = 0;
    VALUE retval;

    if (rb_scan_args(argc, argv, "01", &retval) == 0) {
        retval = Qnil;
    }

    flag |= TCL_CANCEL_UNWIND;
    if (ip_cancel_eval_core(get_ip(self)->ip, retval, flag) == TCL_OK) {
      return Qtrue;
    } else {
      return Qfalse;
    }
}
            
_conv_listelement(p1) click to toggle source
 
               static VALUE
lib_conv_listelement(self, src)
    VALUE self;
    VALUE src;
{
    int   len, scan_flag;
    volatile VALUE dst;
    int   taint_flag = OBJ_TAINTED(src);
    int thr_crit_bup;

    tcl_stubs_check();

    thr_crit_bup = rb_thread_critical;
    rb_thread_critical = Qtrue;

    StringValue(src);

#if TCL_MAJOR_VERSION >= 8
    len = Tcl_ScanCountedElement(RSTRING_PTR(src), RSTRING_LENINT(src),
                                 &scan_flag);
    dst = rb_str_new(0, len + 1);
    len = Tcl_ConvertCountedElement(RSTRING_PTR(src), RSTRING_LENINT(src),
                                    RSTRING_PTR(dst), scan_flag);
#else /* TCL_MAJOR_VERSION < 8 */
    len = Tcl_ScanElement(RSTRING_PTR(src), &scan_flag);
    dst = rb_str_new(0, len + 1);
    len = Tcl_ConvertElement(RSTRING_PTR(src), RSTRING_PTR(dst), scan_flag);
#endif

    rb_str_resize(dst, len);
    if (taint_flag) RbTk_OBJ_UNTRUST(dst);

    rb_thread_critical = thr_crit_bup;

    return dst;
}
            
_create_console() click to toggle source
 
               static VALUE
ip_create_console(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    return tk_funcall(ip_create_console_core, 0, (VALUE*)NULL, self);
}
            
_eval(cmd) click to toggle source
 
               # File tk/lib/tk.rb, line 3018
def _eval(cmd)
  _fromUTF8(__eval(_toUTF8(cmd)))
end
            
Also aliased as: _eval_without_enc, __eval__, __eval, _eval_with_enc, __eval, _eval_with_enc
_eval_with_enc(cmd) click to toggle source
Alias for: _eval
_eval_without_enc(cmd) click to toggle source

backup original (without encoding) _eval and _invoke

Alias for: _eval
_fromUTF8(str, enc = nil) click to toggle source
 
               # File tk/lib/tk.rb, line 2977
def _fromUTF8(str, enc = nil)
  # str must be UTF-8 or binary.
  enc_name = str.instance_variable_get(:@encoding)
  enc_name ||=
    Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil

  # is 'binary' encoding?
  if enc_name == Tk::Encoding::BINARY_NAME
    return str.dup.force_encoding(Tk::Encoding::BINARY_NAME)
  end

  # get target encoding name (if enc == nil, use default encoding)
  begin
    enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc)
  rescue
    # then, enc != nil
    # unknown encoding for Tk -> try to convert encoding on Ruby
    str = str.dup.force_encoding(Tk::Encoding::UTF8_NAME)
    str.encode!(enc) # modify self !!
    return str  # if no error, probably succeed converting
  end

  encstr = __fromUTF8(str, enc_name)
  encstr.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj(enc_name))
  encstr
end
            
Also aliased as: __fromUTF8
_get_global_var(p1) click to toggle source
 
               static VALUE
ip_get_global_var(self, varname)
    VALUE self;
    VALUE varname;
{
    return ip_get_variable(self, varname,
                           INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_get_global_var2(p1, p2) click to toggle source
 
               static VALUE
ip_get_global_var2(self, varname, index)
    VALUE self;
    VALUE varname;
    VALUE index;
{
    return ip_get_variable2(self, varname, index,
                            INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_get_variable(p1, p2) click to toggle source
 
               static VALUE
ip_get_variable(self, varname, flag)
    VALUE self;
    VALUE varname;
    VALUE flag;
{
    return ip_get_variable2(self, varname, Qnil, flag);
}
            
_get_variable2(p1, p2, p3) click to toggle source
 
               static VALUE
ip_get_variable2(self, varname, index, flag)
    VALUE self;
    VALUE varname;
    VALUE index;
    VALUE flag;
{
    VALUE argv[3];
    VALUE retval;

    StringValue(varname);
    if (!NIL_P(index)) StringValue(index);

    argv[0] = varname;
    argv[1] = index;
    argv[2] = flag;

    retval = tk_funcall(ip_get_variable2_core, 3, argv, self);

    if (NIL_P(retval)) {
        return rb_tainted_str_new2("");
    } else {
        return retval;
    }
}
            
_immediate_invoke(*args) click to toggle source
 
               static VALUE
ip_invoke_immediate(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    /* POTENTIALY INSECURE : can create infinite loop */
    return ip_invoke_with_position(argc, argv, obj, TCL_QUEUE_HEAD);
}
            
_invoke(*cmds) click to toggle source
 
               # File tk/lib/tk.rb, line 3022
def _invoke(*cmds)
  _fromUTF8(__invoke(*(cmds.collect{|cmd| _toUTF8(cmd)})))
end
            
Also aliased as: _invoke_without_enc, __invoke__, __invoke, _invoke_with_enc, __invoke, _invoke_with_enc
_invoke_with_enc(*cmds) click to toggle source
Alias for: _invoke
_invoke_without_enc(*cmds) click to toggle source
Alias for: _invoke
_ip_id_() click to toggle source
 
               # File tk/lib/tk.rb, line 22
def _ip_id_
  # for RemoteTkIp
  ''
end
            
_make_menu_embeddable(p1) click to toggle source
 
               static VALUE
ip_make_menu_embeddable(interp, menu_path)
    VALUE interp;
    VALUE menu_path;
{
    VALUE argv[1];

    argv[0] = menu_path;
    return tk_funcall(ip_make_menu_embeddable_core, 1, argv, interp);
}
            
_merge_tklist(*args) click to toggle source
 
               static VALUE
lib_merge_tklist(argc, argv, obj)
    int argc;
    VALUE *argv;
    VALUE obj;
{
    int  num, len;
    int  *flagPtr;
    char *dst, *result;
    volatile VALUE str;
    int taint_flag = 0;
    int thr_crit_bup;
    VALUE old_gc;

    if (argc == 0) return rb_str_new2("");

    tcl_stubs_check();

    thr_crit_bup = rb_thread_critical;
    rb_thread_critical = Qtrue;
    old_gc = rb_gc_disable();

    /* based on Tcl/Tk's Tcl_Merge() */
    /* flagPtr = ALLOC_N(int, argc); */
    flagPtr = RbTk_ALLOC_N(int, argc);
#if 0 /* use Tcl_Preserve/Release */
    Tcl_Preserve((ClientData)flagPtr); /* XXXXXXXXXX */
#endif

    /* pass 1 */
    len = 1;
    for(num = 0; num < argc; num++) {
        if (OBJ_TAINTED(argv[num])) taint_flag = 1;
        dst = StringValuePtr(argv[num]);
#if TCL_MAJOR_VERSION >= 8
        len += Tcl_ScanCountedElement(dst, RSTRING_LENINT(argv[num]),
                                      &flagPtr[num]) + 1;
#else /* TCL_MAJOR_VERSION < 8 */
        len += Tcl_ScanElement(dst, &flagPtr[num]) + 1;
#endif
    }

    /* pass 2 */
    /* result = (char *)Tcl_Alloc(len); */
    result = (char *)ckalloc(len);
#if 0 /* use Tcl_Preserve/Release */
    Tcl_Preserve((ClientData)result);
#endif
    dst = result;
    for(num = 0; num < argc; num++) {
#if TCL_MAJOR_VERSION >= 8
        len = Tcl_ConvertCountedElement(RSTRING_PTR(argv[num]),
                                        RSTRING_LENINT(argv[num]),
                                        dst, flagPtr[num]);
#else /* TCL_MAJOR_VERSION < 8 */
        len = Tcl_ConvertElement(RSTRING_PTR(argv[num]), dst, flagPtr[num]);
#endif
        dst += len;
        *dst = ' ';
        dst++;
    }
    if (dst == result) {
        *dst = 0;
    } else {
        dst[-1] = 0;
    }

#if 0 /* use Tcl_EventuallyFree */
    Tcl_EventuallyFree((ClientData)flagPtr, TCL_DYNAMIC); /* XXXXXXXX */
#else
#if 0 /* use Tcl_Preserve/Release */
    Tcl_Release((ClientData)flagPtr);
#else
    /* free(flagPtr); */
    ckfree((char*)flagPtr);
#endif
#endif

    /* create object */
    str = rb_str_new(result, dst - result - 1);
    if (taint_flag) RbTk_OBJ_UNTRUST(str);
#if 0 /* use Tcl_EventuallyFree */
    Tcl_EventuallyFree((ClientData)result, TCL_DYNAMIC); /* XXXXXXXX */
#else
#if 0 /* use Tcl_Preserve/Release */
    Tcl_Release((ClientData)result); /* XXXXXXXXXXX */
#else
    /* Tcl_Free(result); */
    ckfree(result);
#endif
#endif

    if (old_gc == Qfalse) rb_gc_enable();
    rb_thread_critical = thr_crit_bup;

    return str;
}
            
_return_value() click to toggle source

get return code from Tcl_Eval()

 
               static VALUE
ip_retval(self)
    VALUE self;
{
    struct tcltkip *ptr;        /* tcltkip data struct */

    /* get the data strcut */
    ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return rb_tainted_str_new2("");
    }

    return (INT2FIX(ptr->return_value));
}
            
_set_global_var(p1, p2) click to toggle source
 
               static VALUE
ip_set_global_var(self, varname, value)
    VALUE self;
    VALUE varname;
    VALUE value;
{
    return ip_set_variable(self, varname, value,
                           INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_set_global_var2(p1, p2, p3) click to toggle source
 
               static VALUE
ip_set_global_var2(self, varname, index, value)
    VALUE self;
    VALUE varname;
    VALUE index;
    VALUE value;
{
    return ip_set_variable2(self, varname, index, value,
                            INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_set_variable(p1, p2, p3) click to toggle source
 
               static VALUE
ip_set_variable(self, varname, value, flag)
    VALUE self;
    VALUE varname;
    VALUE value;
    VALUE flag;
{
    return ip_set_variable2(self, varname, Qnil, value, flag);
}
            
_set_variable2(p1, p2, p3, p4) click to toggle source
 
               static VALUE
ip_set_variable2(self, varname, index, value, flag)
    VALUE self;
    VALUE varname;
    VALUE index;
    VALUE value;
    VALUE flag;
{
    VALUE argv[4];
    VALUE retval;

    StringValue(varname);
    if (!NIL_P(index)) StringValue(index);
    StringValue(value);

    argv[0] = varname;
    argv[1] = index;
    argv[2] = value;
    argv[3] = flag;

    retval = tk_funcall(ip_set_variable2_core, 4, argv, self);

    if (NIL_P(retval)) {
        return rb_tainted_str_new2("");
    } else {
        return retval;
    }
}
            
_split_tklist(p1) click to toggle source
 
               static VALUE
ip_split_tklist(self, list_str)
    VALUE self;
    VALUE list_str;
{
    return lib_split_tklist_core(self, list_str);
}
            
_thread_tkwait(p1, p2) click to toggle source
 
               static VALUE
ip_thread_tkwait(self, mode, target)
    VALUE self;
    VALUE mode;
    VALUE target;
{
    VALUE argv[3];
    volatile VALUE cmd_str = rb_str_new2("thread_tkwait");

    argv[0] = cmd_str;
    argv[1] = mode;
    argv[2] = target;

    return ip_invoke_with_position(3, argv, self, TCL_QUEUE_TAIL);
}
            
_thread_vwait(p1) click to toggle source
 
               static VALUE
ip_thread_vwait(self, var)
    VALUE self;
    VALUE var;
{
    VALUE argv[2];
    volatile VALUE cmd_str = rb_str_new2("thread_vwait");

    argv[0] = cmd_str;
    argv[1] = var;

    return ip_invoke_with_position(2, argv, self, TCL_QUEUE_TAIL);
}
            
_toUTF8(str, enc = nil) click to toggle source

with Encoding (Ruby 1.9+)

use functions on Tcl as default. but when unsupported encoding on Tcl, use methods on Ruby.

 
               # File tk/lib/tk.rb, line 2927
def _toUTF8(str, enc = nil)
  if enc
    # use given encoding
    begin
      enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc)
    rescue
      # unknown encoding for Tk -> try to convert encoding on Ruby
      str = str.dup.force_encoding(enc)
      str.encode!(Tk::Encoding::UTF8_NAME) # modify self !!
      return str  # if no error, probably succeed converting
    end
  end

  enc_name ||= str.instance_variable_get(:@encoding)

  enc_name ||=
    Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil

  if enc_name
    # str has its encoding information
    encstr = __toUTF8(str, enc_name)
    encstr.force_encoding(Tk::Encoding::UTF8_NAME)
    return encstr
  else
    # str.encoding isn't supported by Tk -> try to convert on Ruby
    begin
      return str.encode(Tk::Encoding::UTF8_NAME) # new string
    rescue
      # error -> ignore, try to use default encoding of Ruby/Tk
    end
  end

  #enc_name ||=
  #  Tk::Encoding::ENCODING_TABLE.get_name(Tk.encoding) rescue nil
  enc_name ||= Tk::Encoding::ENCODING_TABLE.get_name(nil)

  # is 'binary' encoding?
  if enc_name == Tk::Encoding::BINARY_NAME
    return str.dup.force_encoding(Tk::Encoding::BINARY_NAME)
  end

  # force default encoding?
  if ! str.kind_of?(Tk::EncodedString) && self.force_default_encoding?
    enc_name = Tk::Encoding::ENCODING_TABLE.get_name(Tk.default_encoding)
  end

  encstr = __toUTF8(str, enc_name)
  encstr.force_encoding(Tk::Encoding::UTF8_NAME)
  encstr
end
            
Also aliased as: __toUTF8
_unset_global_var(p1) click to toggle source
 
               static VALUE
ip_unset_global_var(self, varname)
    VALUE self;
    VALUE varname;
{
    return ip_unset_variable(self, varname,
                             INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_unset_global_var2(p1, p2) click to toggle source
 
               static VALUE
ip_unset_global_var2(self, varname, index)
    VALUE self;
    VALUE varname;
    VALUE index;
{
    return ip_unset_variable2(self, varname, index,
                              INT2FIX(TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG));
}
            
_unset_variable(p1, p2) click to toggle source
 
               static VALUE
ip_unset_variable(self, varname, flag)
    VALUE self;
    VALUE varname;
    VALUE flag;
{
    return ip_unset_variable2(self, varname, Qnil, flag);
}
            
_unset_variable2(p1, p2, p3) click to toggle source
 
               static VALUE
ip_unset_variable2(self, varname, index, flag)
    VALUE self;
    VALUE varname;
    VALUE index;
    VALUE flag;
{
    VALUE argv[3];
    VALUE retval;

    StringValue(varname);
    if (!NIL_P(index)) StringValue(index);

    argv[0] = varname;
    argv[1] = index;
    argv[2] = flag;

    retval = tk_funcall(ip_unset_variable2_core, 3, argv, self);

    if (NIL_P(retval)) {
        return rb_tainted_str_new2("");
    } else {
        return retval;
    }
}
            
allow_ruby_exit=(p1) click to toggle source

allow_ruby_exit = mode

 
               static VALUE
ip_allow_ruby_exit_set(self, val)
    VALUE self, val;
{
    struct tcltkip *ptr = get_ip(self);
    Tk_Window mainWin;


    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    if (Tcl_IsSafe(ptr->ip)) {
        rb_raise(rb_eSecurityError,
                 "insecure operation on a safe interpreter");
    }

    /*
     *  Because of cross-threading, the following line may fail to find
     *  the MainWindow, even if the Tcl/Tk interpreter has one or more.
     *  But it has no problem. Current implementation of both type of
     *  the "exit" command don't need maiinWin token.
     */
    mainWin = (tk_stubs_init_p())? Tk_MainWindow(ptr->ip): (Tk_Window)NULL;

    if (RTEST(val)) {
        ptr->allow_ruby_exit = 1;
#if TCL_MAJOR_VERSION >= 8
        DUMP1("Tcl_CreateObjCommand(\"exit\") --> \"ruby_exit\"");
        Tcl_CreateObjCommand(ptr->ip, "exit", ip_RubyExitObjCmd,
                             (ClientData)mainWin, (Tcl_CmdDeleteProc *)NULL);
#else /* TCL_MAJOR_VERSION < 8 */
        DUMP1("Tcl_CreateCommand(\"exit\") --> \"ruby_exit\"");
        Tcl_CreateCommand(ptr->ip, "exit", ip_RubyExitCommand,
                          (ClientData)mainWin, (Tcl_CmdDeleteProc *)NULL);
#endif
        return Qtrue;

    } else {
        ptr->allow_ruby_exit = 0;
#if TCL_MAJOR_VERSION >= 8
        DUMP1("Tcl_CreateObjCommand(\"exit\") --> \"interp_exit\"");
        Tcl_CreateObjCommand(ptr->ip, "exit", ip_InterpExitObjCmd,
                             (ClientData)mainWin, (Tcl_CmdDeleteProc *)NULL);
#else /* TCL_MAJOR_VERSION < 8 */
        DUMP1("Tcl_CreateCommand(\"exit\") --> \"interp_exit\"");
        Tcl_CreateCommand(ptr->ip, "exit", ip_InterpExitCommand,
                          (ClientData)mainWin, (Tcl_CmdDeleteProc *)NULL);
#endif
        return Qfalse;
    }
}
            
allow_ruby_exit?() click to toggle source

allow_ruby_exit?

 
               static VALUE
ip_allow_ruby_exit_p(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    if (ptr->allow_ruby_exit) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}
            
create_dummy_encoding_for_tk(p1) click to toggle source
 
               static VALUE
create_dummy_encoding_for_tk(interp, name)
     VALUE interp;
     VALUE name;
{
  return create_dummy_encoding_for_tk_core(interp, name, Qtrue);
}
            
create_slave(p1, p2 = v2) click to toggle source
 
               static VALUE
ip_create_slave(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    struct tcltkip *master = get_ip(self);
    VALUE safemode;
    VALUE name;
    VALUE callargv[2];

    /* ip is deleted? */
    if (deleted_ip(master)) {
        rb_raise(rb_eRuntimeError,
                 "deleted master cannot create a new slave interpreter");
    }

    /* argument check */
    if (rb_scan_args(argc, argv, "11", &name, &safemode) == 1) {
        safemode = Qfalse;
    }
    if (Tcl_IsSafe(master->ip) != 1
        && (safemode == Qfalse || NIL_P(safemode))) {
    }

    StringValue(name);
    callargv[0] = name;
    callargv[1] = safemode;

    return tk_funcall(ip_create_slave_core, 2, callargv, self);
}
            
default_encoding() click to toggle source
Alias for: encoding_name
default_encoding=(name) click to toggle source
 
               # File tk/lib/tk.rb, line 2892
def default_encoding=(name)
  name = name.name if Tk::WITH_ENCODING && name.kind_of?(::Encoding)
  @encoding[0] = name.to_s.dup
end
            
delete() click to toggle source

delete interpreter

 
               static VALUE
ip_delete(self)
    VALUE self;
{
    int  thr_crit_bup;
    struct tcltkip *ptr = get_ip(self);

    /* if (ptr == (struct tcltkip *)NULL || ptr->ip == (Tcl_Interp*)NULL) { */
    if (deleted_ip(ptr)) {
        DUMP1("delete deleted IP");
        return Qnil;
    }

    thr_crit_bup = rb_thread_critical;
    rb_thread_critical = Qtrue;

    DUMP1("delete interp");
    if (!Tcl_InterpDeleted(ptr->ip)) {
      DUMP1("call ip_finalize");
      ip_finalize(ptr->ip);

      Tcl_DeleteInterp(ptr->ip);
      Tcl_Release(ptr->ip);
    }

    rb_thread_critical = thr_crit_bup;

    return Qnil;
}
            
deleted?() click to toggle source
 
               static VALUE
ip_is_deleted_p(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    if (deleted_ip(ptr)) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}
            
do_one_event(*args) click to toggle source
 
               static VALUE
ip_do_one_event(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    return lib_do_one_event_core(argc, argv, self, 0);
}
            
encoding() click to toggle source
Alias for: encoding_name
encoding=(name) click to toggle source
from tkencoding.rb by ttate@jaist.ac.jp

attr_accessor :encoding

 
               # File tk/lib/tk.rb, line 2899
def encoding=(name)
  self.force_default_encoding = true  # for comaptibility
  self.default_encoding = name
end
            
encoding_name() click to toggle source
 
               # File tk/lib/tk.rb, line 2904
def encoding_name
  (@encoding[0])? @encoding[0].dup: nil
end
            
Also aliased as: encoding, default_encoding
encoding_obj() click to toggle source
 
               # File tk/lib/tk.rb, line 2910
def encoding_obj
  if Tk::WITH_ENCODING
    Tk::Encoding.tcl2rb_encoding(@encoding[0])
  else
    (@encoding[0])? @encoding[0].dup: nil
  end
end
            
encoding_table() click to toggle source
 
               static VALUE
ip_get_encoding_table(interp)
     VALUE interp;
{
  volatile VALUE table = Qnil;

  table = rb_ivar_get(interp, ID_encoding_table);

  if (NIL_P(table)) {
    /* initialize encoding_table */
    table = create_encoding_table(interp);
    rb_define_singleton_method(table, "get_name", encoding_table_get_name, 1);
    rb_define_singleton_method(table, "get_obj",  encoding_table_get_obj,  1);
  }

  return table;
}
            
force_default_encoding=(mode) click to toggle source
 
               # File tk/lib/tk.rb, line 2884
def force_default_encoding=(mode)
  @force_default_encoding[0] = (mode)? true: false
end
            
force_default_encoding?() click to toggle source
 
               # File tk/lib/tk.rb, line 2888
def force_default_encoding?
  @force_default_encoding[0] ||= false
end
            
get_eventloop_tick() click to toggle source
 
               static VALUE
ip_get_eventloop_tick(self)
    VALUE self;
{
    return get_eventloop_tick(self);
}
            
get_eventloop_weight() click to toggle source
 
               static VALUE
ip_get_eventloop_weight(self)
    VALUE self;
{
    return get_eventloop_weight(self);
}
            
get_no_event_wait() click to toggle source
 
               static VALUE
ip_get_no_event_wait(self)
    VALUE self;
{
    return get_no_event_wait(self);
}
            
has_mainwindow?() click to toggle source
 
               static VALUE
ip_has_mainwindow_p(self)
    VALUE self;
{
    return tk_funcall(ip_has_mainwindow_p_core, 0, (VALUE*)NULL, self);
}
            
invalid_namespace?() click to toggle source

is deleted?

 
               static VALUE
ip_has_invalid_namespace_p(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    if (ptr == (struct tcltkip *)NULL || ptr->ip == (Tcl_Interp *)NULL) {
        /* deleted IP */
        return Qtrue;
    }

#if TCL_NAMESPACE_DEBUG
    if (rbtk_invalid_namespace(ptr)) {
        return Qtrue;
    } else {
        return Qfalse;
    }
#else
    return Qfalse;
#endif
}
            
mainloop(*args) click to toggle source
 
               static VALUE
ip_mainloop(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    volatile VALUE ret;
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return Qnil;
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return Qnil;
    }

    eventloop_interp = ptr->ip;
    ret = lib_mainloop(argc, argv, self);
    eventloop_interp = (Tcl_Interp*)NULL;
    return ret;
}
            
mainloop_abort_on_exception() click to toggle source
 
               static VALUE
ip_evloop_abort_on_exc(self)
    VALUE self;
{
    return lib_evloop_abort_on_exc(self);
}
            
mainloop_abort_on_exception=(p1) click to toggle source
 
               static VALUE
ip_evloop_abort_on_exc_set(self, val)
    VALUE self, val;
{
    struct tcltkip *ptr = get_ip(self);


    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return lib_evloop_abort_on_exc(self);
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return lib_evloop_abort_on_exc(self);
    }
    return lib_evloop_abort_on_exc_set(self, val);
}
            
mainloop_watchdog(*args) click to toggle source
 
               static VALUE
ip_mainloop_watchdog(argc, argv, self)
    int   argc;
    VALUE *argv;
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return Qnil;
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return Qnil;
    }
    return lib_mainloop_watchdog(argc, argv, self);
}
            
make_safe() click to toggle source
 
               static VALUE
ip_make_safe(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    return tk_funcall(ip_make_safe_core, 0, (VALUE*)NULL, self);
}
            
restart() click to toggle source
 
               static VALUE
ip_restart(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);


    tcl_stubs_check();

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return Qnil;
    }
    return lib_restart(self);
}
            
safe?() click to toggle source

is safe?

 
               static VALUE
ip_is_safe_p(self)
    VALUE self;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        rb_raise(rb_eRuntimeError, "interpreter is deleted");
    }

    if (Tcl_IsSafe(ptr->ip)) {
        return Qtrue;
    } else {
        return Qfalse;
    }
}
            
set_eventloop_tick(p1) click to toggle source
 
               static VALUE
ip_set_eventloop_tick(self, tick)
    VALUE self;
    VALUE tick;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return get_eventloop_tick(self);
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return get_eventloop_tick(self);
    }
    return set_eventloop_tick(self, tick);
}
            
set_eventloop_weight(p1, p2) click to toggle source
 
               static VALUE
ip_set_eventloop_weight(self, loop_max, no_event)
    VALUE self;
    VALUE loop_max;
    VALUE no_event;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return get_eventloop_weight(self);
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return get_eventloop_weight(self);
    }
    return set_eventloop_weight(self, loop_max, no_event);
}
            
set_max_block_time(p1) click to toggle source
 
               static VALUE
set_max_block_time(self, time)
    VALUE self;
    VALUE time;
{
    struct Tcl_Time tcl_time;
    VALUE divmod;

    switch(TYPE(time)) {
    case T_FIXNUM:
    case T_BIGNUM:
        /* time is micro-second value */
        divmod = rb_funcall(time, rb_intern("divmod"), 1, LONG2NUM(1000000));
        tcl_time.sec  = NUM2LONG(RARRAY_PTR(divmod)[0]);
        tcl_time.usec = NUM2LONG(RARRAY_PTR(divmod)[1]);
        break;

    case T_FLOAT:
        /* time is second value */
        divmod = rb_funcall(time, rb_intern("divmod"), 1, INT2FIX(1));
        tcl_time.sec  = NUM2LONG(RARRAY_PTR(divmod)[0]);
        tcl_time.usec = (long)(NUM2DBL(RARRAY_PTR(divmod)[1]) * 1000000);

    default:
        {
            VALUE tmp = rb_funcall(time, ID_inspect, 0, 0);
            rb_raise(rb_eArgError, "invalid value for time: '%s'",
                     StringValuePtr(tmp));
        }
    }

    Tcl_SetMaxBlockTime(&tcl_time);

    return Qnil;
}
            
set_no_event_wait(p1) click to toggle source
 
               static VALUE
ip_set_no_event_wait(self, wait)
    VALUE self;
    VALUE wait;
{
    struct tcltkip *ptr = get_ip(self);

    /* ip is deleted? */
    if (deleted_ip(ptr)) {
        return get_no_event_wait(self);
    }

    if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) {
        /* slave IP */
        return get_no_event_wait(self);
    }
    return set_no_event_wait(self, wait);
}
            
slave_of?(p1) click to toggle source

self is slave of master?

 
               static VALUE
ip_is_slave_of_p(self, master)
    VALUE self, master;
{
    if (!rb_obj_is_kind_of(master, tcltkip_class)) {
        rb_raise(rb_eArgError, "expected TclTkIp object");
    }

    if (Tcl_GetMaster(get_ip(self)->ip) == get_ip(master)->ip) {
      return Qtrue;
    } else {
      return Qfalse;
    }
}