{"id":20459747,"url":"https://github.com/rosbit/dukgo","last_synced_at":"2025-03-05T11:17:06.667Z","repository":{"id":177207220,"uuid":"660071416","full_name":"rosbit/dukgo","owner":"rosbit","description":"make duktape (2.7.0) be embeddable very easily in Golang. it is NOT a binding.","archived":false,"fork":false,"pushed_at":"2024-06-13T05:39:02.000Z","size":966,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T00:24:43.803Z","etag":null,"topics":["duktape","embeddable","golang","helper","javascript","js","modsearch"],"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":"2023-06-29T07:22:08.000Z","updated_at":"2025-01-11T23:27:16.000Z","dependencies_parsed_at":"2024-01-12T05:16:09.927Z","dependency_job_id":"e3022a13-06ee-4f80-a8db-8f47b1f53647","html_url":"https://github.com/rosbit/dukgo","commit_stats":null,"previous_names":["rosbit/go-duktape","rosbit/dukgo"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fdukgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fdukgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fdukgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fdukgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/dukgo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242014722,"owners_count":20057880,"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":["duktape","embeddable","golang","helper","javascript","js","modsearch"],"created_at":"2024-11-15T12:17:09.093Z","updated_at":"2025-03-05T11:17:06.624Z","avatar_url":"https://github.com/rosbit.png","language":"Go","readme":"# dukgo, makes duktape be embedded easily\n\n[Duktape](http://duktape.org/index.html) is a thin, embeddable javascript engine.\nIts [api](http://duktape.org/api.html) is very well documented. For most of developers\nwho are not familiar with C language, it is very tedious to call duk\\_push\\_xxx() and\nduk\\_pop() to make use of the power of Duktape. Though there are some binding\nimplementations of Duktape for languages other than C, most of them inherit the\nmethods of using API of Duktape.\n\n`dukgo` is a package wrapping Duktape and making it a **pragmatic embeddable** language.\nWith some helper functions provided by `dukgo`, calling Golang functions from Javascript, \nor calling Javascript functions from Golang are both very simple. So, with the help of `dukgo`, Duktape\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/dukgo`\n\nto install.\n\n### Usage\n\n#### 1. Evaluates expressions\n\n```go\npackage main\n\nimport (\n  djs \"github.com/rosbit/dukgo\"\n  \"fmt\"\n)\n\nfunc main() {\n  ctx, err := djs.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  djs \"github.com/rosbit/dukgo\"\n  \"fmt\"\n)\n\nvar add func(int, int)int\n\nfunc main() {\n  ctx, err := djs.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 CallFunc\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, calling `EvalFile` with a map as env will\nmake Golang functions as Javascript global functions. There's the example:\n\n```go\npackage main\n\nimport \"github.com/rosbit/dukgo\"\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 := djs.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\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%2Fdukgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fdukgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fdukgo/lists"}