ffi-tk 2010.08.23 → 2018.02.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +371 -0
  5. data/AUTHORS +4 -2
  6. data/CHANGELOG +302 -262
  7. data/Gemfile +10 -0
  8. data/Gemfile.lock +45 -0
  9. data/MANIFEST +6 -6
  10. data/README.md +1 -1
  11. data/Rakefile +12 -11
  12. data/bin/rwish +6 -5
  13. data/example/choose_color.rb +5 -4
  14. data/example/choose_directory.rb +5 -4
  15. data/example/dialog.rb +9 -8
  16. data/example/hello.rb +2 -1
  17. data/example/message_box.rb +8 -5
  18. data/example/option_menu.rb +4 -3
  19. data/example/popup.rb +4 -3
  20. data/example/set_palette.rb +5 -4
  21. data/example/text.rb +30 -30
  22. data/example/tile/kroc_demo_small.rb +51 -55
  23. data/example/tile/kroc_rb_demo.rb +74 -83
  24. data/example/tile/notebook.rb +6 -9
  25. data/example/tile/theme_hello.rb +6 -8
  26. data/example/tile/themes.rb +4 -2
  27. data/example/tile/treeview.rb +16 -14
  28. data/example/tkgo.rb +120 -88
  29. data/example/various.rb +8 -7
  30. data/example/wait.rb +3 -2
  31. data/ffi-tk.gemspec +21 -20
  32. data/gemset.nix +134 -0
  33. data/lib/ffi-tk.rb +10 -11
  34. data/lib/ffi-tk/command.rb +3 -2
  35. data/lib/ffi-tk/command/after.rb +8 -7
  36. data/lib/ffi-tk/command/bell.rb +2 -1
  37. data/lib/ffi-tk/command/bind.rb +1 -0
  38. data/lib/ffi-tk/command/bindtags.rb +1 -0
  39. data/lib/ffi-tk/command/cget.rb +31 -24
  40. data/lib/ffi-tk/command/choose_color.rb +2 -1
  41. data/lib/ffi-tk/command/choose_directory.rb +2 -1
  42. data/lib/ffi-tk/command/clipboard.rb +6 -5
  43. data/lib/ffi-tk/command/configure.rb +23 -21
  44. data/lib/ffi-tk/command/destroy.rb +2 -1
  45. data/lib/ffi-tk/command/dialog.rb +4 -3
  46. data/lib/ffi-tk/command/event.rb +1 -0
  47. data/lib/ffi-tk/command/focus.rb +2 -1
  48. data/lib/ffi-tk/command/font.rb +12 -9
  49. data/lib/ffi-tk/command/get_open_file.rb +1 -0
  50. data/lib/ffi-tk/command/get_save_file.rb +1 -0
  51. data/lib/ffi-tk/command/grab.rb +2 -1
  52. data/lib/ffi-tk/command/grid.rb +7 -6
  53. data/lib/ffi-tk/command/image.rb +5 -4
  54. data/lib/ffi-tk/command/lower.rb +1 -0
  55. data/lib/ffi-tk/command/message_box.rb +2 -1
  56. data/lib/ffi-tk/command/option_menu.rb +3 -2
  57. data/lib/ffi-tk/command/pack.rb +5 -4
  58. data/lib/ffi-tk/command/place.rb +5 -4
  59. data/lib/ffi-tk/command/popup.rb +2 -1
  60. data/lib/ffi-tk/command/raise.rb +1 -0
  61. data/lib/ffi-tk/command/scrollable.rb +7 -10
  62. data/lib/ffi-tk/command/selection.rb +4 -3
  63. data/lib/ffi-tk/command/set_palette.rb +2 -1
  64. data/lib/ffi-tk/command/tk_cmd.rb +1 -0
  65. data/lib/ffi-tk/command/vars.rb +2 -1
  66. data/lib/ffi-tk/command/wait.rb +2 -1
  67. data/lib/ffi-tk/command/winfo.rb +9 -8
  68. data/lib/ffi-tk/command/wm.rb +11 -10
  69. data/lib/ffi-tk/core_extensions.rb +5 -4
  70. data/lib/ffi-tk/event/data.rb +32 -31
  71. data/lib/ffi-tk/event/handler.rb +4 -3
  72. data/lib/ffi-tk/ffi/tcl.rb +42 -31
  73. data/lib/ffi-tk/ffi/tcl/cmd_proc.rb +2 -1
  74. data/lib/ffi-tk/ffi/tcl/eval_result.rb +47 -8
  75. data/lib/ffi-tk/ffi/tcl/interp.rb +7 -4
  76. data/lib/ffi-tk/ffi/tcl/obj.rb +7 -32
  77. data/lib/ffi-tk/ffi/tcl/time.rb +2 -1
  78. data/lib/ffi-tk/ffi/tk.rb +8 -7
  79. data/lib/ffi-tk/geometry.rb +20 -17
  80. data/lib/ffi-tk/thread_sender.rb +1 -0
  81. data/lib/ffi-tk/tk.rb +23 -23
  82. data/lib/ffi-tk/variable.rb +25 -3
  83. data/lib/ffi-tk/version.rb +1 -1
  84. data/lib/ffi-tk/widget.rb +2 -1
  85. data/lib/ffi-tk/widget/button.rb +4 -1
  86. data/lib/ffi-tk/widget/canvas.rb +18 -15
  87. data/lib/ffi-tk/widget/canvas/arc.rb +2 -1
  88. data/lib/ffi-tk/widget/canvas/bitmap.rb +2 -1
  89. data/lib/ffi-tk/widget/canvas/image.rb +2 -1
  90. data/lib/ffi-tk/widget/canvas/item.rb +4 -4
  91. data/lib/ffi-tk/widget/canvas/line.rb +2 -1
  92. data/lib/ffi-tk/widget/canvas/oval.rb +2 -1
  93. data/lib/ffi-tk/widget/canvas/polygon.rb +2 -1
  94. data/lib/ffi-tk/widget/canvas/rectangle.rb +2 -1
  95. data/lib/ffi-tk/widget/canvas/text.rb +2 -1
  96. data/lib/ffi-tk/widget/canvas/window.rb +2 -1
  97. data/lib/ffi-tk/widget/checkbutton.rb +4 -1
  98. data/lib/ffi-tk/widget/entry.rb +4 -1
  99. data/lib/ffi-tk/widget/frame.rb +4 -1
  100. data/lib/ffi-tk/widget/label.rb +4 -1
  101. data/lib/ffi-tk/widget/labelframe.rb +4 -1
  102. data/lib/ffi-tk/widget/listbox.rb +5 -2
  103. data/lib/ffi-tk/widget/menu.rb +4 -1
  104. data/lib/ffi-tk/widget/menubutton.rb +4 -1
  105. data/lib/ffi-tk/widget/message.rb +4 -1
  106. data/lib/ffi-tk/widget/panedwindow.rb +5 -2
  107. data/lib/ffi-tk/widget/radiobutton.rb +4 -1
  108. data/lib/ffi-tk/widget/root.rb +1 -0
  109. data/lib/ffi-tk/widget/scale.rb +4 -1
  110. data/lib/ffi-tk/widget/scrollbar.rb +4 -1
  111. data/lib/ffi-tk/widget/spinbox.rb +4 -1
  112. data/lib/ffi-tk/widget/text.rb +20 -16
  113. data/lib/ffi-tk/widget/text/peer.rb +1 -0
  114. data/lib/ffi-tk/widget/tile.rb +2 -1
  115. data/lib/ffi-tk/widget/tile/button.rb +4 -1
  116. data/lib/ffi-tk/widget/tile/checkbutton.rb +4 -1
  117. data/lib/ffi-tk/widget/tile/combobox.rb +5 -2
  118. data/lib/ffi-tk/widget/tile/entry.rb +4 -1
  119. data/lib/ffi-tk/widget/tile/frame.rb +4 -1
  120. data/lib/ffi-tk/widget/tile/label.rb +4 -2
  121. data/lib/ffi-tk/widget/tile/labelframe.rb +4 -1
  122. data/lib/ffi-tk/widget/tile/menubutton.rb +4 -1
  123. data/lib/ffi-tk/widget/tile/notebook.rb +4 -1
  124. data/lib/ffi-tk/widget/tile/panedwindow.rb +4 -1
  125. data/lib/ffi-tk/widget/tile/progressbar.rb +4 -2
  126. data/lib/ffi-tk/widget/tile/radiobutton.rb +4 -1
  127. data/lib/ffi-tk/widget/tile/scale.rb +4 -1
  128. data/lib/ffi-tk/widget/tile/scrollbar.rb +7 -4
  129. data/lib/ffi-tk/widget/tile/separator.rb +4 -1
  130. data/lib/ffi-tk/widget/tile/sizegrip.rb +4 -1
  131. data/lib/ffi-tk/widget/tile/style.rb +16 -17
  132. data/lib/ffi-tk/widget/tile/treeview.rb +11 -5
  133. data/lib/ffi-tk/widget/toplevel.rb +4 -1
  134. data/shell.nix +19 -0
  135. data/spec/ffi-tk/command/bind.rb +5 -4
  136. data/spec/ffi-tk/command/bindtags.rb +2 -1
  137. data/spec/ffi-tk/command/clipboard.rb +4 -3
  138. data/spec/ffi-tk/command/font.rb +20 -19
  139. data/spec/ffi-tk/command/image.rb +13 -5
  140. data/spec/ffi-tk/command/pack.rb +3 -2
  141. data/spec/ffi-tk/command/place.rb +4 -3
  142. data/spec/ffi-tk/command/selection.rb +2 -1
  143. data/spec/ffi-tk/command/vars.rb +3 -2
  144. data/spec/ffi-tk/command/winfo.rb +10 -10
  145. data/spec/ffi-tk/command/wm.rb +23 -22
  146. data/spec/ffi-tk/event.rb +23 -21
  147. data/spec/ffi-tk/tile/button.rb +8 -8
  148. data/spec/ffi-tk/tile/checkbutton.rb +1 -1
  149. data/spec/ffi-tk/tile/combobox.rb +11 -12
  150. data/spec/ffi-tk/tile/entry.rb +18 -19
  151. data/spec/ffi-tk/tile/frame.rb +13 -13
  152. data/spec/ffi-tk/tile/label.rb +2 -2
  153. data/spec/ffi-tk/tile/labelframe.rb +1 -1
  154. data/spec/ffi-tk/tile/menubutton.rb +1 -1
  155. data/spec/ffi-tk/tile/notebook.rb +22 -20
  156. data/spec/ffi-tk/tile/panedwindow.rb +1 -1
  157. data/spec/ffi-tk/tile/progressbar.rb +1 -1
  158. data/spec/ffi-tk/tile/radiobutton.rb +1 -1
  159. data/spec/ffi-tk/tile/scale.rb +1 -1
  160. data/spec/ffi-tk/tile/scrollbar.rb +1 -16
  161. data/spec/ffi-tk/tile/separator.rb +2 -2
  162. data/spec/ffi-tk/tile/sizegrip.rb +1 -1
  163. data/spec/ffi-tk/tile/style.rb +63 -65
  164. data/spec/ffi-tk/tile/treeview.rb +11 -10
  165. data/spec/ffi-tk/variable.rb +5 -4
  166. data/spec/ffi-tk/widget/button.rb +3 -2
  167. data/spec/ffi-tk/widget/canvas.rb +59 -58
  168. data/spec/ffi-tk/widget/checkbutton.rb +6 -5
  169. data/spec/ffi-tk/widget/entry.rb +112 -103
  170. data/spec/ffi-tk/widget/frame.rb +2 -1
  171. data/spec/ffi-tk/widget/label.rb +2 -1
  172. data/spec/ffi-tk/widget/labelframe.rb +1 -0
  173. data/spec/ffi-tk/widget/listbox.rb +5 -4
  174. data/spec/ffi-tk/widget/menu.rb +3 -2
  175. data/spec/ffi-tk/widget/menubutton.rb +1 -0
  176. data/spec/ffi-tk/widget/message.rb +1 -0
  177. data/spec/ffi-tk/widget/panedwindow.rb +1 -0
  178. data/spec/ffi-tk/widget/radiobutton.rb +1 -0
  179. data/spec/ffi-tk/widget/root.rb +2 -1
  180. data/spec/ffi-tk/widget/scale.rb +1 -0
  181. data/spec/ffi-tk/widget/scrollbar.rb +1 -0
  182. data/spec/ffi-tk/widget/spinbox.rb +1 -0
  183. data/spec/ffi-tk/widget/text.rb +63 -54
  184. data/spec/ffi-tk/widget/toplevel.rb +1 -0
  185. data/spec/helper.rb +3 -1
  186. data/tasks/authors.rake +3 -2
  187. data/tasks/bacon.rake +13 -11
  188. data/tasks/changelog.rake +1 -0
  189. data/tasks/gem.rake +13 -11
  190. data/tasks/manifest.rake +2 -1
  191. data/tasks/release.rake +11 -32
  192. data/tasks/reversion.rake +2 -1
  193. metadata +52 -75
  194. data/spec/ffi-tk/command/grid.rb +0 -6
  195. data/tasks/gem_setup.rake +0 -113
  196. data/tasks/grancher.rake +0 -12
  197. data/tasks/rcov.rake +0 -17
  198. data/tasks/setup.rake +0 -12
  199. data/tasks/ycov.rake +0 -84
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  # Communicate with window manager
3
4
  # The wm command is used to interact with window managers in order to control
@@ -303,7 +304,7 @@ module Tk
303
304
  Tk.execute_only(:wm, :aspect, window, '', '', '', '')
304
305
  else
305
306
  result = Tk.execute_only(:wm, :aspect, window,
306
- min_numer, min_denom, max_numer, max_denom)
307
+ min_numer, min_denom, max_numer, max_denom)
307
308
  if result.to_s == ''
308
309
  nil
309
310
  else
@@ -409,8 +410,8 @@ module Tk
409
410
  alpha: :float,
410
411
  topmost: :boolean,
411
412
  zoomed: :boolean,
412
- fullscreen: :boolean,
413
- }
413
+ fullscreen: :boolean
414
+ }.freeze
414
415
 
415
416
  # If name is specified, this command stores name (which should be the name
416
417
  # of the host on which the application is executing) in window's
@@ -422,7 +423,7 @@ module Tk
422
423
  # WM_CLIENT_MACHINE property from window.
423
424
  def client(window, name = None)
424
425
  if name == None
425
- Tk.execute(:wm, :client, window).to_s?
426
+ Tk.execute(:wm, :client, window)
426
427
  else
427
428
  Tk.execute_only(:wm, :client, window, name)
428
429
  end
@@ -471,7 +472,7 @@ module Tk
471
472
  # WM_COMMAND property from window.
472
473
  def command(window, value = None)
473
474
  if value == None
474
- Tk.execute(:wm, :command, window).to_a
475
+ Tk.execute(:wm, :command, window)&.split
475
476
  else
476
477
  Tk.execute_only(:wm, :command, window, value)
477
478
  end
@@ -594,7 +595,7 @@ module Tk
594
595
  # functionality.
595
596
  def grid(window, base_width = None, base_height = None, width_inc = None, height_inc = None)
596
597
  if base_width == None
597
- Tk.execute(:wm, :grid, window).to_a?(&:to_i)
598
+ Tk.execute(:wm, :grid, window)
598
599
  else
599
600
  Tk.execute_only(:wm, :grid, window, base_width, base_height, width_inc, height_inc)
600
601
  end
@@ -611,13 +612,13 @@ module Tk
611
612
  # if window is not part of any group.
612
613
  def group(window, pathname = None)
613
614
  if None == pathname
614
- Tk.execute(:wm, :group, window).to_s?
615
+ Tk.execute(:wm, :group, window)
615
616
  else
616
617
  Tk.execute_only(:wm, :group, window, pathname)
617
618
  end
618
619
  end
619
620
 
620
- #wm iconbitmap window ?bitmap?
621
+ # wm iconbitmap window ?bitmap?
621
622
  # If bitmap is specified, then it names a bitmap in the standard forms
622
623
  # accepted by Tk (see the Tk_GetBitmap manual entry for details).
623
624
  # This bitmap is passed to the window manager to be dis? played in window's
@@ -630,7 +631,7 @@ module Tk
630
631
  # On the Windows operating system, an additional flag is supported:
631
632
  def iconbitmap(window, bitmap = None)
632
633
  if None == bitmap
633
- Tk.execute(:wm, :iconbitmap, window).to_s?
634
+ Tk.execute(:wm, :iconbitmap, window)
634
635
  else
635
636
  Tk.execute_only(:wm, :iconbitmap, window, bitmap)
636
637
  end
@@ -780,7 +781,7 @@ module Tk
780
781
  # maximum width and height currently in effect.
781
782
  # The maximum size defaults to the size of the screen.
782
783
  # See the sections on geometry management below for more information.
783
- def maxsize(window, width = None, height = None)
784
+ def maxsize(_window, width = None, height = None)
784
785
  if width == None || height == None
785
786
  Tk.execute(:wm, :maxsize)
786
787
  else
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  # Already converted statement, don't process again
3
4
  class TclString < String
@@ -11,7 +12,7 @@ module Tk
11
12
  module CoreExtensions
12
13
  module Array
13
14
  def to_tcl
14
- TclString.new('{' << map(&:to_tcl).compact.join(' ') << '}')
15
+ TclString.new("{#{map(&:to_tcl).compact.join(' ')}}")
15
16
  end
16
17
 
17
18
  # try to convert to a Hash.
@@ -92,13 +93,13 @@ module Tk
92
93
  pattern = "(?#{embed.join})#{source}"
93
94
  end
94
95
 
95
- TclString.new('{' << pattern.gsub(/([^\\])(?=[{}])/, '\1\\\\\2') << '}')
96
+ TclString.new(%({#{pattern.gsub(/([^\\])(?=[{}])/, '\1\\\\\2')}}))
96
97
  end
97
98
  end
98
99
 
99
100
  module String
100
101
  def to_tcl
101
- TclString.new('"' << gsub(/[\[\]{}$"\\]/, '\\\\\&') << '"')
102
+ TclString.new(%("#{gsub(/[\[\]{}$"\\]/, '\\\\\&')}"))
102
103
  end
103
104
 
104
105
  def to_tcl_option
@@ -128,7 +129,7 @@ module Tk
128
129
  end
129
130
  end
130
131
 
131
- module Fixnum
132
+ module Integer
132
133
  def tcl_to_ruby(option, hints)
133
134
  name = option.sub(/^-/, '').to_sym
134
135
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  module Event
3
4
  Data = Struct.new(
@@ -10,41 +11,41 @@ module Tk
10
11
 
11
12
  class Data
12
13
  PROPERTIES = [
13
- ['%#', :Integer, :serial ],
14
- ['%b', :Integer, :button ],
15
- ['%c', :Integer, :count ],
16
- ['%d', :String, :detail ],
17
- ['%f', :String, :focus ],
18
- ['%h', :Integer, :height ],
19
- ['%i', :String, :window ],
20
- ['%k', :Integer, :keycode ],
21
- ['%m', :String, :mode ],
22
- ['%o', :String, :override_redirect ],
23
- ['%p', :String, :place ],
24
- ['%s', :String, :state ],
25
- ['%t', :Integer, :time ],
26
- ['%w', :Integer, :width ],
27
- ['%x', :Integer, :x ],
28
- ['%y', :Integer, :y ],
29
- ['%A', :String, :unicode ],
30
- ['%B', :Integer, :border_width ],
31
- ['%D', :Integer, :mousewheel_delta ],
32
- ['%E', :Integer, :send_event ],
33
- ['%K', :String, :keysym ],
34
- ['%N', :Integer, :keysym_number ],
35
- ['%P', :String, :property ],
36
- ['%R', :String, :root ],
37
- ['%S', :String, :subwindow ],
38
- ['%T', :Integer, :type ],
39
- ['%W', :String, :window_path ],
40
- ['%X', :Integer, :x_root ],
41
- ['%Y', :Integer, :y_root ],
42
- ]
14
+ ['%#', :Integer, :serial],
15
+ ['%b', :Integer, :button],
16
+ ['%c', :Integer, :count],
17
+ ['%d', :String, :detail],
18
+ ['%f', :String, :focus],
19
+ ['%h', :Integer, :height],
20
+ ['%i', :String, :window],
21
+ ['%k', :Integer, :keycode],
22
+ ['%m', :String, :mode],
23
+ ['%o', :String, :override_redirect],
24
+ ['%p', :String, :place],
25
+ ['%s', :String, :state],
26
+ ['%t', :Integer, :time],
27
+ ['%w', :Integer, :width],
28
+ ['%x', :Integer, :x],
29
+ ['%y', :Integer, :y],
30
+ ['%A', :String, :unicode],
31
+ ['%B', :Integer, :border_width],
32
+ ['%D', :Integer, :mousewheel_delta],
33
+ ['%E', :Integer, :send_event],
34
+ ['%K', :String, :keysym],
35
+ ['%N', :Integer, :keysym_number],
36
+ ['%P', :String, :property],
37
+ ['%R', :String, :root],
38
+ ['%S', :String, :subwindow],
39
+ ['%T', :Integer, :type],
40
+ ['%W', :String, :window_path],
41
+ ['%X', :Integer, :x_root],
42
+ ['%Y', :Integer, :y_root]
43
+ ].freeze
43
44
 
44
45
  def initialize(id, pattern, *properties)
45
46
  super id, pattern
46
47
 
47
- PROPERTIES.each do |code, conv, name|
48
+ PROPERTIES.each do |_code, conv, name|
48
49
  value = properties.shift
49
50
  converted = String(value)
50
51
  next if converted == '??'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Tk
2
3
  module Event
3
4
  module Handler
@@ -17,12 +18,12 @@ module Tk
17
18
  def register_block(block)
18
19
  id = nil
19
20
 
20
- @mutex.synchronize{
21
+ @mutex.synchronize do
21
22
  @store << block
22
23
  id = @store.size - 1
23
- }
24
+ end
24
25
 
25
- return id
26
+ id
26
27
  end
27
28
 
28
29
  def register(tag, sequence, &block)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'ffi-tk/ffi/tcl/obj'
2
3
  require 'ffi-tk/ffi/tcl/interp'
3
4
  require 'ffi-tk/ffi/tcl/cmd_proc'
@@ -9,40 +10,50 @@ module FFI
9
10
  extend FFI::Library
10
11
  ffi_lib ::Tk::TCL_LIBPATH
11
12
 
12
- attach_function :Tcl_AppendAllObjTypes, [Interp, Obj], :int
13
- attach_function :Tcl_CreateInterp, [], Interp
14
- attach_function :Tcl_DeleteInterp, [Interp], :void
15
- attach_function :Tcl_DoOneEvent, [flags = :int], :int
16
- attach_function :Tcl_EvalEx, [Interp, script = :string, length = :int, flags = :int], :int
17
- attach_function :Tcl_GetBoolean, [Interp, :string, :pointer], :int
18
- attach_function :Tcl_GetBooleanFromObj, [Interp, Obj, boolean = :pointer], :int
19
- attach_function :Tcl_GetDoubleFromObj, [Interp, Obj, :pointer], :int
20
- attach_function :Tcl_GetIntFromObj, [Interp, Obj, int = :pointer], :int
21
- attach_function :Tcl_GetObjResult, [Interp], Obj
22
- attach_function :Tcl_GetObjType, [:string], ObjType
23
- attach_function :Tcl_GetString, [Obj], :string
24
- attach_function :Tcl_GetStringFromObj, [Obj, length = :pointer], :string
25
- attach_function :Tcl_GetStringResult, [Interp], :string
26
- attach_function :Tcl_GetUnicode, [Obj], :string
27
- attach_function :Tcl_Init, [Interp], :int
28
- attach_function :Tcl_ListObjGetElements, [Interp, Obj, count = :pointer, list = :pointer], :int
29
- attach_function :Tcl_ListObjIndex, [Interp, list = :pointer, index = :int, result = :pointer], :int
30
- attach_function :Tcl_ListObjLength, [Interp, list = :pointer, int = :pointer], :int
31
- attach_function :Tcl_NewBooleanObj, [:int], Obj
32
- attach_function :Tcl_NewIntObj, [:int], Obj
33
- attach_function :Tcl_NewListObj, [count = :int, values = :pointer], Obj
34
- attach_function :Tcl_NewStringObj, [:string, :int], Obj
35
- attach_function :Tcl_ObjGetVar2, [Interp, :pointer, :pointer, :int], Obj
36
- attach_function :Tcl_ObjSetVar2, [Interp, Obj, Obj, Obj, :int], Obj
37
- attach_function :Tcl_ParseVar, [Interp, :pointer, :pointer], :pointer
38
- attach_function :Tcl_SetObjResult, [Interp, Obj], :void
39
- attach_function :Tcl_WaitForEvent, [TclTime], :int
40
- attach_function :Tcl_SetMaxBlockTime, [TclTime], :void
13
+ attach_function :Tcl_AppendAllObjTypes, [:pointer, :pointer], :int
14
+ attach_function :Tcl_CreateInterp, [], :pointer
15
+ attach_function :Tcl_DeleteInterp, [:pointer], :void
16
+ attach_function :Tcl_DoOneEvent, [:int], :int
17
+ attach_function :Tcl_EvalEx, [:pointer, :string, :int, :int], :int
18
+ attach_function :Tcl_GetBoolean, [:pointer, :string, :pointer], :int
19
+ attach_function :Tcl_GetBooleanFromObj, [:pointer, :pointer, :pointer], :int
20
+ attach_function :Tcl_GetDoubleFromObj, [:pointer, :pointer, :pointer], :int
21
+ attach_function :Tcl_GetIntFromObj, [:pointer, :pointer, :pointer], :int
22
+ attach_function :Tcl_GetObjResult, [:pointer], :pointer
23
+ attach_function :Tcl_GetObjType, [:string], :pointer
24
+ attach_function :Tcl_GetString, [:pointer], :string
25
+ attach_function :Tcl_GetStringFromObj, [:pointer, :pointer], :string
26
+ attach_function :Tcl_GetStringResult, [:pointer], :string
27
+ attach_function :Tcl_GetUnicode, [:pointer], :string
28
+ attach_function :Tcl_Init, [:pointer], :int
29
+ attach_function :Tcl_ListObjGetElements, [:pointer, :pointer, :pointer, :pointer], :int
30
+ attach_function :Tcl_ListObjIndex, [:pointer, :pointer, :int, :pointer], :int
31
+ attach_function :Tcl_ListObjLength, [:pointer, :pointer, :pointer], :int
32
+ attach_function :Tcl_NewBooleanObj, [:int], :pointer
33
+ attach_function :Tcl_NewIntObj, [:int], :pointer
34
+ attach_function :Tcl_NewListObj, [:int, :pointer], :pointer
35
+ attach_function :Tcl_NewStringObj, [:string, :int], :pointer
36
+ attach_function :Tcl_NewDictObj, [], :pointer
37
+ attach_function :Tcl_ObjGetVar2, [:pointer, :pointer, :pointer, :int], :pointer
38
+ attach_function :Tcl_ObjSetVar2, [:pointer, :pointer, :pointer, :pointer, :int], :pointer
39
+ attach_function :Tcl_ParseVar, [:pointer, :pointer, :pointer], :pointer
40
+ attach_function :Tcl_SetObjResult, [:pointer, :pointer], :void
41
+ attach_function :Tcl_WaitForEvent, [:pointer], :int
42
+ attach_function :Tcl_SetMaxBlockTime, [:pointer], :void
43
+ attach_function :Tcl_DictObjGet, [:pointer, :pointer, :pointer, :pointer], :int
44
+ attach_function :Tcl_DictObjPut, [:pointer, :pointer, :pointer, :pointer], :int
45
+ attach_function :Tcl_DictObjRemove, [:pointer, :pointer, :pointer], :int
46
+ attach_function :Tcl_DictObjSize, [:pointer, :pointer, :pointer], :int
47
+ attach_function :Tcl_DictObjFirst, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int
48
+ attach_function :Tcl_DictObjNext, [:pointer, :pointer, :pointer, :pointer], :void
49
+ attach_function :Tcl_DictObjDone, [:pointer], :void
50
+ attach_function :Tcl_DictObjPutKeyList, [:pointer, :pointer, :int, :pointer, :pointer], :int
51
+ attach_function :Tcl_DictObjRemoveKeyList, [:pointer, :pointer, :int, :pointer], :int
41
52
 
42
- callback :obj_cmd_proc, [:int, Interp, :int, :pointer], :int
53
+ callback :obj_cmd_proc, [:int, :pointer, :int, :pointer], :int
43
54
  callback :obj_delete_proc, [:int], :void
44
55
  attach_function :Tcl_CreateObjCommand, [
45
- Interp, name = :string, :obj_cmd_proc, :int, :obj_delete_proc], :pointer
56
+ :pointer, :string, :obj_cmd_proc, :int, :obj_delete_proc], :pointer
46
57
 
47
58
  module_function
48
59
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tcl
3
4
  class CmdProc < PrettyStruct
@@ -7,4 +8,4 @@ module FFI
7
8
  :argv, :pointer
8
9
  end
9
10
  end
10
- end
11
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tcl
3
4
  # This whole class feels very awkward, maybe it should be merged with Obj.
@@ -15,6 +16,7 @@ module FFI
15
16
  string_length_ptr = MemoryPointer.new(:int)
16
17
 
17
18
  if Tcl.list_obj_get_elements(interp, list, objc_ptr, objv_ptr) == 0
19
+ return [] if objv_ptr.get_pointer(0).null?
18
20
  array_ptr = objv_ptr.get_pointer(0)
19
21
  array_length = objc_ptr.get_int(0)
20
22
  array = array_ptr.read_array_of_pointer(array_length)
@@ -30,6 +32,7 @@ module FFI
30
32
 
31
33
  def self.guess(interp, obj, fallback = nil)
32
34
  obj = Obj.new(obj) unless obj.respond_to?(:type)
35
+ # p obj: obj, obj_type: obj.type
33
36
  type = TYPES[obj.type.to_i]
34
37
 
35
38
  case type
@@ -41,16 +44,49 @@ module FFI
41
44
  to_int(interp, obj)
42
45
  when :double
43
46
  to_double(interp, obj)
47
+ when :dict
48
+ to_dict(interp, obj)
49
+ when :window
50
+ to_window(interp, obj)
44
51
  else
45
52
  if fallback
46
53
  __send__(fallback, interp, obj)
54
+ elsif type.nil? && obj.bytes == ''
55
+ nil
56
+ elsif type.nil?
57
+ to_string(interp, obj)
47
58
  else
48
- raise "Unknown type: %p" % [type] if type
49
- new(interp, obj)
59
+ raise 'Unknown type: %p' % [type]
50
60
  end
51
61
  end
52
62
  end
53
63
 
64
+ def self.to_window(interp, obj)
65
+ p interp: interp, obj: obj
66
+ end
67
+
68
+ def self.to_dict(interp, obj)
69
+ out = {}
70
+
71
+ search = MemoryPointer.new(:pointer)
72
+ done = MemoryPointer.new(:int)
73
+ key_ptr = MemoryPointer.new(:pointer)
74
+ value_ptr = MemoryPointer.new(:pointer)
75
+ strlen = MemoryPointer.new(:int)
76
+
77
+ Tcl.dict_obj_first(interp, obj, search, key_ptr, value_ptr, done)
78
+
79
+ while done.get_int(0) != 1
80
+ key = Tcl.get_string_from_obj(key_ptr.get_pointer(0), strlen)
81
+ value = Tcl.get_string_from_obj(value_ptr.get_pointer(0), strlen)
82
+ out[key] = value
83
+
84
+ Tcl.dict_obj_next(search, key_ptr, value_ptr, done)
85
+ end
86
+
87
+ out
88
+ end
89
+
54
90
  def self.to_double(interp, obj)
55
91
  double_pointer = MemoryPointer.new(:double)
56
92
 
@@ -73,9 +109,10 @@ module FFI
73
109
  objv_ptr = MemoryPointer.new(:pointer)
74
110
 
75
111
  if Tcl.list_obj_get_elements(interp, obj, objc_ptr, objv_ptr) == 0
76
- objv_ptr.get_pointer(0).
77
- read_array_of_pointer(objc_ptr.get_int(0)).
78
- map(&block)
112
+ return [] if objv_ptr.get_pointer(0).null?
113
+ objv_ptr.get_pointer(0)
114
+ .read_array_of_pointer(objc_ptr.get_int(0))
115
+ .map(&block)
79
116
  else
80
117
  panic(interp, 'Tcl_ListObjGetElements')
81
118
  end
@@ -94,14 +131,16 @@ module FFI
94
131
  def self.to_int(interp, obj)
95
132
  int_pointer = MemoryPointer.new(:int)
96
133
 
97
- if Tcl.get_int_from_obj(interp, obj, int_pointer) == 0
134
+ if obj.bytes == ''
135
+ '' # used by text widget -endline
136
+ elsif Tcl.get_int_from_obj(interp, obj, int_pointer) == 0
98
137
  int_pointer.get_int(0)
99
138
  else
100
139
  panic(interp, 'Tcl_GetIntFromObj')
101
140
  end
102
141
  end
103
142
 
104
- def self.to_string(interp, obj)
143
+ def self.to_string(_interp, obj)
105
144
  length_pointer = MemoryPointer.new(:int)
106
145
 
107
146
  string = Tcl.get_string_from_obj(obj, length_pointer)
@@ -162,7 +201,7 @@ module FFI
162
201
  end
163
202
 
164
203
  def inspect
165
- "#<EvalResult #{to_s}>"
204
+ "#<EvalResult #{self}>"
166
205
  end
167
206
  end
168
207
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module FFI
2
3
  module Tcl
3
4
  class Interp < PrettyStruct
@@ -11,7 +12,7 @@ module FFI
11
12
  EVAL_DIRECT = 0x40000
12
13
 
13
14
  def inspect
14
- "Interp"
15
+ 'Interp'
15
16
  end
16
17
 
17
18
  def guess_result
@@ -31,7 +32,7 @@ module FFI
31
32
  Tcl.new_boolean_obj(0)
32
33
  when String
33
34
  Tcl.new_string_obj(ruby_obj, ruby_obj.bytesize)
34
- when Fixnum
35
+ when Integer
35
36
  Tcl.new_int_obj(ruby_obj)
36
37
  when Exception
37
38
  string = [ruby_obj.message, *ruby_obj.backtrace].join("\n")
@@ -79,16 +80,18 @@ module FFI
79
80
  def eval(string)
80
81
  if $DEBUG
81
82
  if string =~ /\n/
82
- puts "eval: %p" % [string]
83
+ puts "\neval: %p" % [string]
83
84
  else
84
- puts "eval: %s" % [string]
85
+ puts "\neval: %s" % [string]
85
86
  end
86
87
  end
87
88
 
88
89
  code = Tcl.eval_ex(self, string, string.bytesize, EVAL_DIRECT)
90
+ puts 'eval= %p' % [code] if $DEBUG
89
91
  return true if code == 0
90
92
 
91
93
  message = guess_result.to_s
94
+ puts 'eval= %p' % [message] if $DEBUG
92
95
 
93
96
  if message.empty?
94
97
  raise 'Failure during eval of: %p' % [string]