{"id":13366339,"url":"https://github.com/olebedev/Go-duktape","last_synced_at":"2025-03-12T18:31:01.129Z","repository":{"id":25518167,"uuid":"28949956","full_name":"olebedev/go-duktape","owner":"olebedev","description":"[abandoned] Duktape JavaScript engine bindings for Go","archived":true,"fork":false,"pushed_at":"2021-10-14T11:38:32.000Z","size":3287,"stargazers_count":777,"open_issues_count":8,"forks_count":96,"subscribers_count":25,"default_branch":"v3","last_synced_at":"2024-07-31T01:24:47.648Z","etag":null,"topics":["binding","duktape","golang","javascript-engine"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"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/olebedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-08T05:09:05.000Z","updated_at":"2024-07-29T17:18:10.000Z","dependencies_parsed_at":"2022-09-14T08:50:12.087Z","dependency_job_id":null,"html_url":"https://github.com/olebedev/go-duktape","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/olebedev%2Fgo-duktape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fgo-duktape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fgo-duktape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fgo-duktape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olebedev","download_url":"https://codeload.github.com/olebedev/go-duktape/tar.gz/refs/heads/v3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309820,"owners_count":16795817,"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":["binding","duktape","golang","javascript-engine"],"created_at":"2024-07-30T00:01:23.386Z","updated_at":"2024-10-24T11:30:16.158Z","avatar_url":"https://github.com/olebedev.png","language":"Go","funding_links":[],"categories":["嵌入式脚本语言","嵌入式腳本語言"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"# Duktape bindings for Go(Golang)\n\n[![wercker status](https://app.wercker.com/status/3a5bb2e639a4b4efaf4c8bf7cab7442d/s \"wercker status\")](https://app.wercker.com/project/bykey/3a5bb2e639a4b4efaf4c8bf7cab7442d)\n[![Travis status](https://travis-ci.org/olebedev/go-duktape.svg?branch=v3)](https://travis-ci.org/olebedev/go-duktape)\n[![Appveyor status](https://ci.appveyor.com/api/projects/status/github/olebedev/go-duktape?branch=v3\u0026svg=true)](https://ci.appveyor.com/project/olebedev/go-duktape/branch/v3)\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/olebedev/go-duktape?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n[Duktape](http://duktape.org/index.html) is a thin, embeddable javascript engine.\nMost of the [api](http://duktape.org/api.html) is implemented.\nThe exceptions are listed [here](https://github.com/olebedev/go-duktape/blob/master/api.go#L1566).\n\n### Usage\n\nThe package is fully go-getable, no need to install any external C libraries.  \nSo, just type `go get gopkg.in/olebedev/go-duktape.v3` to install.\n\n\n```go\npackage main\n\nimport \"fmt\"\nimport \"gopkg.in/olebedev/go-duktape.v3\"\n\nfunc main() {\n  ctx := duktape.New()\n  ctx.PevalString(`2 + 3`)\n  result := ctx.GetNumber(-1)\n  ctx.Pop()\n  fmt.Println(\"result is:\", result)\n  // To prevent memory leaks, don't forget to clean up after\n  // yourself when you're done using a context.\n  ctx.DestroyHeap()\n}\n```\n\n### Go specific notes\n\nBindings between Go and Javascript contexts are not fully functional.\nHowever, binding a Go function to the Javascript context is available:\n```go\npackage main\n\nimport \"fmt\"\nimport \"gopkg.in/olebedev/go-duktape.v3\"\n\nfunc main() {\n  ctx := duktape.New()\n  ctx.PushGlobalGoFunction(\"log\", func(c *duktape.Context) int {\n    fmt.Println(c.SafeToString(-1))\n    return 0\n  })\n  ctx.PevalString(`log('Go lang Go!')`)\n}\n```\nthen run it.\n```bash\n$ go run *.go\nGo lang Go!\n$\n```\n\n### Timers\n\nThere is a method to inject timers to the global scope:\n```go\npackage main\n\nimport \"fmt\"\nimport \"gopkg.in/olebedev/go-duktape.v3\"\n\nfunc main() {\n  ctx := duktape.New()\n\n  // Let's inject `setTimeout`, `setInterval`, `clearTimeout`,\n  // `clearInterval` into global scope.\n  ctx.PushTimers()\n\n  ch := make(chan string)\n  ctx.PushGlobalGoFunction(\"second\", func(_ *Context) int {\n    ch \u003c- \"second step\"\n    return 0\n  })\n  ctx.PevalString(`\n    setTimeout(second, 0);\n    print('first step');\n  `)\n  fmt.Println(\u003c-ch)\n}\n```\nthen run it\n```bash\n$ go run *.go\nfirst step\nsecond step\n$\n```\n\nAlso you can `FlushTimers()`.\n\n### Command line tool\n\nInstall `go get gopkg.in/olebedev/go-duktape.v3/...`.  \nExecute file.js: `$GOPATH/bin/go-duk file.js`.\n\n### Benchmarks\n| prog        | time  |\n| ------------|-------|\n|[otto](https://github.com/robertkrimen/otto)|200.13s|\n|[anko](https://github.com/mattn/anko)|231.19s|\n|[agora](https://github.com/PuerkitoBio/agora/)|149.33s|\n|[GopherLua](https://github.com/yuin/gopher-lua/)|8.39s|\n|**go-duktape**|**9.80s**|\n\nMore details are [here](https://github.com/olebedev/go-duktape/wiki/Benchmarks).\n\n### Status\n\nThe package is not fully tested, so be careful.\n\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2FGo-duktape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folebedev%2FGo-duktape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2FGo-duktape/lists"}