{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/vm/issues/1","repository_url":"https://api.github.com/repos/nodejs/vm","labels_url":"https://api.github.com/repos/nodejs/vm/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/vm/issues/1/comments","events_url":"https://api.github.com/repos/nodejs/vm/issues/1/events","html_url":"https://github.com/nodejs/vm/issues/1","id":147519567,"number":1,"title":"C/C++ transpiling for addons","user":{"login":"indutny","id":238531,"avatar_url":"https://avatars.githubusercontent.com/u/238531?v=3","gravatar_id":"","url":"https://api.github.com/users/indutny","html_url":"https://github.com/indutny","followers_url":"https://api.github.com/users/indutny/followers","following_url":"https://api.github.com/users/indutny/following{/other_user}","gists_url":"https://api.github.com/users/indutny/gists{/gist_id}","starred_url":"https://api.github.com/users/indutny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indutny/subscriptions","organizations_url":"https://api.github.com/users/indutny/orgs","repos_url":"https://api.github.com/users/indutny/repos","events_url":"https://api.github.com/users/indutny/events{/privacy}","received_events_url":"https://api.github.com/users/indutny/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-04-11T18:53:52Z","updated_at":"2016-04-11T19:08:18Z","closed_at":null,"body":"I suggest exploring following way of writing addons.\r\n\r\n## Concept\r\n\r\nInstead of including particular engine headers and working with engine's APIs (`v8::*`), addon may look like a plain C/C++ program:\r\n\r\n```C\r\nvoid some_fn(int value, js_str_t str) {\r\n  // ...\r\n}\r\n```\r\n\r\nThe transpiler will take such function and rewrite it in a way that will make it compatible with engine. For example, the code above may result in something like this:\r\n\r\n\r\n```C++\r\nvoid some_fn(const FunctionCallbackInfo<Value>& args) {\r\n  int value = args[0]->ToInteger();\r\n  js_str_t str;\r\n  String::Utf8Value tmp(args[1]->ToString());\r\n  \r\n  str.data = *tmp;\r\n  str.length = tmp.length();\r\n\r\n  // addon code\r\n}\r\n```\r\n\r\n## Benefits\r\n\r\nThis approach provides three important benefits:\r\n\r\n* Independence of particular JS engine\r\n* No need for pre-compiling stuff, node.js will carry clang with transpiler\r\n* Simple way to test functions using just C/C++ APIs without initializing V8 or whatever engine\r\n\r\n## Some further ideas\r\n\r\nStruct-object\r\n```C++\r\ntypedef struct my_obj_t {\r\n  int x;\r\n  js_str_t str;\r\n};\r\n\r\nvoid my_fn(my_obj_t* obj) {\r\n  // Accessing object, or updating its properties will update relevant JS object\r\n}\r\n```\r\n\r\nFunction\r\n```C++\r\ntypedef void (*ext_fn_t)(int x, js_str_t str);\r\n\r\nvoid my_fn(ext_fn_t ext) {\r\n  // This will invoke JS function referenced by `ext`\r\n  ext(1, JS_STR(\"...\"));\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/nodejs/vm/issues/comments/208505340","html_url":"https://github.com/nodejs/vm/issues/1#issuecomment-208505340","issue_url":"https://api.github.com/repos/nodejs/vm/issues/1","id":208505340,"user":{"login":"indutny","id":238531,"avatar_url":"https://avatars.githubusercontent.com/u/238531?v=3","gravatar_id":"","url":"https://api.github.com/users/indutny","html_url":"https://github.com/indutny","followers_url":"https://api.github.com/users/indutny/followers","following_url":"https://api.github.com/users/indutny/following{/other_user}","gists_url":"https://api.github.com/users/indutny/gists{/gist_id}","starred_url":"https://api.github.com/users/indutny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indutny/subscriptions","organizations_url":"https://api.github.com/users/indutny/orgs","repos_url":"https://api.github.com/users/indutny/repos","events_url":"https://api.github.com/users/indutny/events{/privacy}","received_events_url":"https://api.github.com/users/indutny/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T19:08:17Z","updated_at":"2016-04-11T19:08:17Z","body":"@bnoordhuis sarcasm != argument . What are our objections to it? Binary size? Licensing?\r\n\r\n@kobalicek this is not going to be **the only one** way to compile addons. Just the suggested one.\r\n\r\n@stefanmb sorry, I wasn't participating in that discussion. May I ask you what was the motivation for it?"}}