Created
February 11, 2010 10:38
-
-
Save anekos/301407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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