玩一玩 V8-juice
Thu, 15 Apr 2010 10:28:23 +0800V8是一個高速的Javascript引擎,也是Google Chrome的Javascript核心。因為執行效能很好,有許多人用他來開發瀏覽器之外的應用,最有名的就是node.js,這是一個基於事件驅動的伺服器架構。如果要用V8來當作一般用途的script language,在google code上面有一個叫做v8-juice的計畫。v8-juice是一個擴展v8的plugin架構,可以透過他包裝其他的函式庫並且動態載入。不過目前已經做的plugin不算多,包括curl, sqlite, expat, ncurses, readline, socket, posix file api等等。核心則擴充了幾個函數、物件及property,包括:
- v8juice:global物件的別名
- arguments:...耶?拿來取得command line參數嗎?
- include:載入外部js檔案
- loadPlugin:載入plugin
- sprintf
- sleep:不用解釋了吧?
- mssleep
- usleep
- wait
- mswait
- uwait
- setTimeout
- setInterval
- clearTimeout
- clearInterval
- spawnTimeoutThread:以下都是threading的函數
- spawnIntervalThread
- clearTimeoutThread
- clearIntervalThread
- v8JuiceVersion:j8juice版本的string
- PathFinder:PathFinder物件,用法詳見http://code.google.com/p/v8-juice/wiki/PathFinderClass
- quit:離開v8-juice-shell
- version:顯示v8版本的函數
最近正好也在看plurk API,所以就寫了一個簡單的發噗程式。這個程式利用v8-juice及他的curl plugin。v8-juice的curl plugin雖然實作的功能還不是很完整,但是當作一個headless http client已經夠用,而且支援ssl,這樣才有辦法登入plurk發噗。簡單的程式碼,目前放在http://github.com/fillano/js_plurk,有時間再來進一步改進。目前考慮的方向有:改成支援commonjs的module標準,支援nodejs等。(nodejs雖然有http client,但是目前穩定的版本還不支援ssl,所以晚一點再來試試看。)