一個嵌入式的JavaScript解釋器:MuJS
MuJS 是一個使用可移植 C 編寫、輕量級的 JavaScript 解釋器。用于嵌入到其他的應用來擴展腳本功能。實現了 ECMA-262 規定的 ECMAScript 標準。
開發 MuJS 的原因是 V8、SpiderMonkey 和 JavaScriptCore 都太大、太復雜了。MuJS 專注于提供一個非常精簡、正確和簡單的實現。
用于與本機代碼的結合接口被設計為盡可能地簡單易用,和類似的Lua。A stand-alone interpreter
#include <stdio.h> #include <mujs.h> int main(int argc, char **argv) { char line[256]; js_State *J = js_newstate(NULL, NULL); while (fgets(line, sizeof line, stdin)) js_dostring(J, line, 1); js_freestate(J); }
Hello, world!
#include <stdio.h> #include <mujs.h> static void hello(js_State *J) { const char *name = js_tostring(J, 1); printf("Hello, %s!\n", name); js_pushundefined(J); } int main(int argc, char **argv) { js_State *J = js_newstate(NULL, NULL); js_newcfunction(J, hello, 1); js_setglobal(J, "hello"); js_dostring(J, "hello('world');", 0); js_freestate(J); }
本文由用戶 mxf8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!