LoginSignup
6
5

More than 5 years have passed since last update.

Haste は 2 パターンの FFI をサポートします。

foreign import ccall を用いた FFI

foreign import ccall jsQuerySelectorAll :: Elem -> JSString -> IO (Ptr [Elem])

この場合、以下の様な jsQuerySelectorAll 関数を持つ .js を定義し、事前に読み込んでおく必要があります。

function jsQuerySelectorAll(elem, query) {
    var els = [0], nl; 

    if (!elem || typeof elem.querySelectorAll !== 'function') {
        return els;
    }   

    nl = elem.querySelectorAll(query);

    for (var i = nl.length-1; i >= 0; --i) {
        els = [1, nl[i], els];
    }   

    return els;
}

Haste 独自 FFI

clicked :: Selector -> (MouseEvent -> IO ()) -> IO ()
clicked = ffi "(function(sel, f){$(sel).click(f);})"

Haste 独自の ffi 関数に、文字列で JavaScript を渡します。引数は 5 つまでサポートしているようです。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5