Skip to content

Instantly share code, notes, and snippets.

@teramako
Created February 9, 2010 12:59
Show Gist options
  • Save teramako/299172 to your computer and use it in GitHub Desktop.
Save teramako/299172 to your computer and use it in GitHub Desktop.
Fx3.6で導入されてるctypes.jsmメモ

js-ctypes

js-ctype に関するメモ

これは何か

  • JavaScriptからバイナリモジュール内の関数の直実行を可能にする
    • cライブラリの関数を呼び出すなど
  • XPCOMとして登録しなくても良くなる
  • Firefox 3.7 から導入? (← Fx 3.6からあった)

使い方

  1. _ctypes.jsm_のロード
  2. ライブラリファイルの_open_
  3. ライブラリにある関数の宣言(declare)
  4. 実行
  5. ライブラリのクローズ(close)

###例 Components.utils.import("resource://gre/modules/ctypes.jsm"); var libc = ctypes.open("libc.so.6"); var puts = libc.declare("puts", ctypes.default_abi, ctypes.int32_t, ctypes.string); puts("Hello ctypes"); libc.close();

制限

いつか解消されるかも

  • ポインタなど参照が必要なものはむりっぽい
    sprintf で試したが無理だった。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment