Hi,

I am writing a ruby binding for C library implements an automaton
for supporting non-english keyboard input. Following shows an example
usage:

  require 'hangul'

  hic = Hangul::InputContext.new(Hangul::KEYBOARD_2)
  input = "fnql gksrmf fkdlqmfjfl xptmxm"
  buffer = ''
  input.each_byte do |c|
    ret = hic.filter(c)         # filtering [a-zA-Z] for automaton
    commit = hic.commit_string  # output produced by automaton
    buffer << commit if commit
    buffer << c.chr unless ret  # just append unfiltered chars.
  end
  hic.flush
  buffer << hic.commit_string.to_s

It works as I expected when I paste the code on IRB, or run it with
built-in ruby debugger(-r debug). See the actual session:

  $ irb -f
  irb(main):001:0> require 'hangul'
  => true
  irb(main):002:0> hic = Hangul::InputContext.new(Hangul::KEYBOARD_2)
  => #<Hangul::InputContext:0xb7d50494>
  (...)
  irb(main):012:0> buffer << hic.commit_string.to_s    # bottom line
  => "\353\243\250\353\271\204 \355\225\234\352\270\200
\353\235\274\354\235\264\353\270\214\353\237\254\353\246\254
\355\205\214\354\212\244\355\212\270"

FYI, the variable 'buffer' is finally utf-8 encoded string, expected
result.

But it returns strange result when I run the code directly from
command-line. After running the code, the 'buffer' would be filled with
only 3 spaces(0x20). The 'hic.commit_string' always returns nil. I don't
know why the result differs. It doesn't relate with concurrency issues.

My extension codes can be found at:
http://nohmad.sub-port.net/tmp/ruby-hangul/

Any comment will be appreciated.

--
http://nohmad.sub-port.net