{"id":16594767,"url":"https://github.com/ahabhgk/rusty_qjs","last_synced_at":"2025-03-21T13:31:56.369Z","repository":{"id":36980397,"uuid":"413260285","full_name":"ahabhgk/rusty_qjs","owner":"ahabhgk","description":"(WIP) Rust bindings to QuickJS","archived":false,"fork":false,"pushed_at":"2023-03-13T03:58:48.000Z","size":707,"stargazers_count":8,"open_issues_count":11,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T23:47:21.760Z","etag":null,"topics":["ffi","quickjs","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/ahabhgk.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}},"created_at":"2021-10-04T03:19:56.000Z","updated_at":"2023-06-14T02:39:42.000Z","dependencies_parsed_at":"2023-02-18T13:01:19.243Z","dependency_job_id":null,"html_url":"https://github.com/ahabhgk/rusty_qjs","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/ahabhgk%2Frusty_qjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahabhgk%2Frusty_qjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahabhgk%2Frusty_qjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahabhgk%2Frusty_qjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahabhgk","download_url":"https://codeload.github.com/ahabhgk/rusty_qjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221815696,"owners_count":16885207,"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":["ffi","quickjs","rust"],"created_at":"2024-10-11T23:47:22.777Z","updated_at":"2024-10-28T10:13:19.110Z","avatar_url":"https://github.com/ahabhgk.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (WIP) rusty_qjs\n\nRust bindings to QuickJS.\n\n## Todo\n\n- [ ] JSValue::new_... returns a Result\n- [ ] specific JSValue type, like JsString, JsNumber...?\n- [ ] catch unwind for extern \"C\" fn?\n\n## Feature\n\n### local\n\nThe JSValue of QuickJS is using reference counting to manage the memory. So we\ncreate a Local handle to help you free the JSValue. The Local will call\nJS_FreeValue when it drops. You can simply use `to_local` to convert a JSValue\ninto a Local handle, then enjoy the conveniences of it.\n\n## Example\n\n```rust\nuse rusty_qjs::{JSContext, JSRuntime, JSValue};\nuse std::io::Write;\n\nfn js_print(ctx: \u0026mut JSContext, _this: JSValue, argv: \u0026[JSValue]) -\u003e JSValue {\n  let output = argv\n    .iter()\n    .map(|value| value.to_rust_string(ctx))\n    .collect::\u003cVec\u003cString\u003e\u003e()\n    .join(\" \");\n  let mut stdout = std::io::stdout();\n  stdout.write_all(output.as_bytes()).unwrap();\n  stdout.write_all(b\"\\n\").unwrap();\n  JSValue::new_undefined()\n}\n\nfn setup_console(ctx: \u0026mut JSContext) {\n  let global = ctx.get_global_object().to_local(ctx);\n  let console = JSValue::new_object(ctx).to_local(ctx);\n  let log = JSValue::new_function(ctx, js_print, \"log\", 1).to_local(ctx);\n\n  console.set_property_str(\"log\", log).unwrap();\n  global.set_property_str(\"console\", console).unwrap();\n}\n\nfn main() {\n  let rt = \u0026mut JSRuntime::new();\n  let ctx = \u0026mut JSContext::new(rt);\n\n  setup_console(ctx);\n  ctx.eval_script(\"console.log(\\\"hello world\\\")\", \"\u003ctest\u003e\");\n}\n```\n\nFor a more in-depth example, look at\n[qtok](https://github.com/ahabhgk/rusty_qjs/tree/main/qtok)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahabhgk%2Frusty_qjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahabhgk%2Frusty_qjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahabhgk%2Frusty_qjs/lists"}