{"id":20459741,"url":"https://github.com/rosbit/go-quickjs","last_synced_at":"2025-07-01T06:35:27.657Z","repository":{"id":57694298,"uuid":"485798549","full_name":"rosbit/go-quickjs","owner":"rosbit","description":"make quickjs be embedded easily in Golang. it is NOT a binding.","archived":false,"fork":false,"pushed_at":"2024-03-02T12:42:44.000Z","size":1246,"stargazers_count":17,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T05:51:39.210Z","etag":null,"topics":["embeddable","golang","helper","quickjs"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-04-26T13:29:22.000Z","updated_at":"2025-04-09T10:21:23.000Z","dependencies_parsed_at":"2024-03-02T14:20:52.031Z","dependency_job_id":null,"html_url":"https://github.com/rosbit/go-quickjs","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/go-quickjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-quickjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-quickjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-quickjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-quickjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/go-quickjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-quickjs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262914214,"owners_count":23383846,"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":["embeddable","golang","helper","quickjs"],"created_at":"2024-11-15T12:17:08.326Z","updated_at":"2025-07-01T06:35:27.631Z","avatar_url":"https://github.com/rosbit.png","language":"Go","readme":"# go-quickjs, make quickjs be embedded easily\n\n[QuickJS](https://bellard.org/quickjs/) is a small and embeddable Javascript engine written by [Fabrice Bellard](https://bellard.org).\n\n`go-quickjs` is a package wrapping quickjs and making it a **pragmatic embeddable** language.\nWith some helper functions provided by `go-quickjs`, calling Golang functions from Javascript, \nor calling Javascript functions from Golang are both very simple. So, with the help of `go-quickjs`, quickjs\ncan be embedded in Golang application easily.\n\n### Install\n\nThe package is fully go-getable, So, just type\n\n  `go get github.com/rosbit/go-quickjs`\n\nto install.\n\n### Usage\n\n#### 1. Evaluates expressions\n\n```go\npackage main\n\nimport (\n  \"github.com/rosbit/go-quickjs\"\n  \"fmt\"\n)\n\nfunc main() {\n  ctx, err := quickjs.NewContext()\n  if err != nil {\n    fmt.Printf(\"%v\\n\", err)\n    return\n  }\n\n  res, _ := ctx.Eval(\"a + b\", map[string]interface{}{\n     \"a\": 10,\n     \"b\": 1,\n  })\n  fmt.Println(\"result is:\", res)\n}\n```\n\n#### 2. Go calls Javascript function\n\nSuppose there's a Javascript file named `a.js` like this:\n\n```javascript\nfunction add(a, b) {\n    return a+b\n}\n```\n\none can call the Javascript function `add()` in Go code like the following:\n\n```go\npackage main\n\nimport (\n  \"github.com/rosbit/go-quickjs\"\n  \"fmt\"\n)\n\nvar add func(int, int)int\n\nfunc main() {\n  ctx, err := quickjs.NewContext()\n  if err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n\n  if _, err := ctx.EvalFile(\"a.js\", nil); err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n\n  // method 1: bind JS function with a golang var\n  if err := ctx.BindFunc(\"add\", \u0026add); err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n  res := add(1, 2)\n\n  // method 2: call JS function using Call\n  res, err := ctx.CallFunc(\"add\", 1, 2)\n  if err != nil {\n     fmt.Printf(\"%v\\n\", err)\n     return\n  }\n\n  fmt.Println(\"result is:\", res)\n}\n```\n\n#### 3. Javascript calls Go function\n\nJavascript calling Go function is also easy. In the Go code, make a Golang function\nas Javascript global function by calling `EvalFile` by registering. There's the example:\n\n```go\npackage main\n\nimport \"github.com/rosbit/go-quickjs\"\n\n// function to be called by Javascript\nfunc adder(a1 float64, a2 float64) float64 {\n    return a1 + a2\n}\n\nfunc main() {\n  ctx, err := quickjs.NewContext()\n  if err != nil {\n      fmt.Printf(\"%v\\n\", err)\n      return\n  }\n\n  if _, err := ctx.EvalFile(\"b.js\", map[string]interface{}{\n      \"adder\": adder,\n  })  // b.js containing code calling \"adder\"\n}\n```\n\nIn Javascript code, one can call the registered function directly. There's the example `b.js`.\n\n```javascript\nr = adder(1, 100)   // the function \"adder\" is implemented in Go\nconsole.log(r)\n```\n\n### Status\n\nThe package is not fully tested, so be careful.\n\n### Contribution\n\nPull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes.\n__Convention:__ fork the repository and make changes on your fork in a feature branch.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-quickjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fgo-quickjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-quickjs/lists"}