Skip to content

Instantly share code, notes, and snippets.

@anekos
Created February 11, 2010 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anekos/301407 to your computer and use it in GitHub Desktop.
Save anekos/301407 to your computer and use it in GitHub Desktop.
Components.utils.import("resource://gre/modules/ctypes.jsm");
let RUBYLIB_DEF = {
ruby_init: [ctypes.void_t],
rb_eval_string_protect: [ctypes.uint32_t, ctypes.string, ctypes.uint32_t],
};
let rubydll = ctypes.open('msvcrt-ruby18.dll');
let ruby = {};
for (let [name, def] in Iterator(RUBYLIB_DEF))
ruby[name] = rubydll.declare.apply(rubydll, [name, ctypes.default_abi].concat(def));
ruby.ruby_init();
let rbResult =
ruby.rb_eval_string_protect(
<>
666
</>.toString(),
0
);
// 返値が (Fixnum|true|false|nil) ならば、簡単な操作で答えが得られる。
// それ以外は普通には受け取れないかも。
function fromRb ()
({
0: function() false,
2: function() true,
4: function() null,
__noSuchMethod__: function (name) (parseInt(name) >> 1)
})[rbResult]();
liberator.echo(fromRb(rbResult));
rubydll.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment