{"id":18559282,"url":"https://github.com/linux-china/embind_demo","last_synced_at":"2025-04-10T02:30:43.403Z","repository":{"id":136595306,"uuid":"214039553","full_name":"linux-china/embind_demo","owner":"linux-china","description":"Emscripten embind demo","archived":false,"fork":false,"pushed_at":"2019-10-23T16:25:38.000Z","size":48,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:51:08.898Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linux-china.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-09T22:54:37.000Z","updated_at":"2025-03-16T13:25:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"199627cd-b6ef-4d9c-b20c-7e9802f1b571","html_url":"https://github.com/linux-china/embind_demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fembind_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fembind_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fembind_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fembind_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linux-china","download_url":"https://codeload.github.com/linux-china/embind_demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144158,"owners_count":21054876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:42:26.981Z","updated_at":"2025-04-10T02:30:43.395Z","avatar_url":"https://github.com/linux-china.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Embind Demo\n===================\n\nWebAssembly bind demo with embind \u0026 Web IDL\n\n# WebIDL Binder\n\nhttps://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html\n\n* Create WebIDL, for example hello.idl\n* Generate cpp file from idl\n* Create C++ header file with Class definition\n* Implement C++ class\n* Compile cpp to wasm and js \n\n# Wasm call JS functions\n\n* Implement a C API in JavaScript: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html\n* Using val to transliterate JavaScript to C++: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#using-val-to-transliterate-javascript-to-c\n* Memory views and Access memory from JavaScript: \n\n```c\nunsigned char *byteBuffer;\n\nval getBytes(offset, lenth) {\n    return val(typed_memory_view(lenth, byteBuffer+offset));\n}\n\n```\n\n* Passing and returning WebAssembly array parameters: https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97\n* Access memory from JavaScript: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html\n\n# Reactive communication between Wasm and Hosting\n\n### receive connection \u0026 messages from peer\n\n* void send(int id, int type, String metadata, String data)\n* void receive(int id, int type, String metadata, String data)\n\nWasm的唯一标识在初始化wasm的js中进行设置，然后在通讯过程中进行拦截。\n\nAsyncify: https://emscripten.org/docs/porting/asyncify.html\n\nTinyFSM: a simple finite state machine library for C++, designed for optimal performance and low memory footprint. https://digint.ch/tinyfsm/index.html\n\n# Extension\n\n* EventBus: 可以利用Hosting runtime提供的EventBus特性，这样可以实现pub/sub https://nodejs.org/dist/latest-v13.x/docs/api/events.html\n\n# Clion Integration\n\nCLion with emscripten: Settings \u003e Build, Execution, Deployment \u003e CMake,  add following in CMake options: \n\n```\n-DCMAKE_TOOLCHAIN_FILE=/usr/local/opt/emscripten/libexec/cmake/Modules/Platform/Emscripten.cmake\n```\n\n# References\n\n* Google Developer WebAssembly: https://developers.google.cn/web/updates/tags/webassembly\n* Embind: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html\n* Emscripten’s embind: https://developers.google.cn/web/updates/2018/08/embind\n* Emscripten and npm: https://developers.google.cn/web/updates/2019/01/emscripten-npm\n* Replacing a hot path in your app's JavaScript with WebAssembly: https://developers.google.cn/web/updates/2019/02/hotpath-with-wasm\n* Emscripten Compiler Frontend: https://emscripten.org/docs/tools_reference/emcc.html\n* Web IDL: https://heycam.github.io/webidl/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fembind_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinux-china%2Fembind_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fembind_demo/lists"}