{"id":13366344,"url":"https://github.com/Shopify/Go-lua","last_synced_at":"2025-03-12T18:30:59.458Z","repository":{"id":12672291,"uuid":"15344288","full_name":"Shopify/go-lua","owner":"Shopify","description":"A Lua VM in Go","archived":false,"fork":false,"pushed_at":"2024-05-27T20:09:33.000Z","size":947,"stargazers_count":3104,"open_issues_count":49,"forks_count":189,"subscribers_count":547,"default_branch":"main","last_synced_at":"2024-10-22T08:15:02.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Shopify.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-20T17:29:43.000Z","updated_at":"2024-10-22T07:41:36.000Z","dependencies_parsed_at":"2024-06-20T14:45:38.277Z","dependency_job_id":null,"html_url":"https://github.com/Shopify/go-lua","commit_stats":{"total_commits":193,"total_committers":27,"mean_commits":7.148148148148148,"dds":"0.36269430051813467","last_synced_commit":"91867de107cf529cbfb9210580ce7673451546f4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fgo-lua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fgo-lua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fgo-lua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fgo-lua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shopify","download_url":"https://codeload.github.com/Shopify/go-lua/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309819,"owners_count":16795816,"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-07-30T00:01:23.465Z","updated_at":"2024-10-24T11:30:16.164Z","avatar_url":"https://github.com/Shopify.png","language":"Go","readme":"[![Build Status](https://circleci.com/gh/Shopify/go-lua.png?circle-token=997f951c602c0c63a263eba92975428a49ee4c2e)](https://circleci.com/gh/Shopify/go-lua)\n[![GoDoc](https://godoc.org/github.com/Shopify/go-lua?status.png)](https://godoc.org/github.com/Shopify/go-lua)\n\nA Lua VM in pure Go\n===================\n\ngo-lua is a port of the Lua 5.2 VM to pure Go. It is compatible with binary files dumped by `luac`, from the [Lua reference implementation](http://www.lua.org/).\n\nThe motivation is to enable simple scripting of Go applications. For example, it is used to describe flows in [Shopify's](http://www.shopify.com/) load generation tool, Genghis.\n\nUsage\n-----\n\ngo-lua is intended to be used as a Go package. It does not include a command to run the interpreter. To start using the library, run:\n```sh\ngo get github.com/Shopify/go-lua\n```\n\nTo develop \u0026 test go-lua, you'll also need the [lua-tests](https://github.com/Shopify/lua-tests) submodule checked out:\n```sh\ngit submodule update --init\n```\n\nYou can then develop with the usual Go commands, e.g.:\n```sh\ngo build\ngo test -cover\n```\n\nA simple example that loads \u0026 runs a Lua script is:\n```go\npackage main\n\nimport \"github.com/Shopify/go-lua\"\n\nfunc main() {\n  l := lua.NewState()\n  lua.OpenLibraries(l)\n  if err := lua.DoFile(l, \"hello.lua\"); err != nil {\n    panic(err)\n  }\n}\n```\n\nStatus\n------\n\ngo-lua has been used in production in Shopify's load generation tool, Genghis, since May 2014, and is also part of Shopify's resiliency tooling.\n\nThe core VM and compiler has been ported and tested. The compiler is able to correctly process all Lua source files from the [Lua test suite](https://github.com/Shopify/lua-tests). The VM has been tested to correctly execute over a third of the Lua test cases.\n\nMost core Lua libraries are at least partially implemented. Prominent exceptions are regular expressions, coroutines and `string.dump`.\n\nWeak reference tables are not and will not be supported. go-lua uses the Go heap for Lua objects, and Go does not support weak references.\n\nBenchmarks\n----------\n\nBenchmark results shown here are taken from a Mid 2012 MacBook Pro Retina with a 2.6 GHz Core i7 CPU running OS X 10.10.2, go 1.4.2 and Lua 5.2.2.\n\nThe Fibonacci function can be written a few different ways to evaluate different performance characteristics of a language interpreter. The simplest way is as a recursive function:\n```lua\n  function fib(n)\n    if n == 0 then\n      return 0\n    elseif n == 1 then\n      return 1\n    end\n    return fib(n-1) + fib(n-2)\n  end\n```\n\nThis exercises the call stack implementation. When computing `fib(35)`, go-lua is about 6x slower than the C Lua interpreter. [Gopher-lua](https://github.com/yuin/gopher-lua) is about 20% faster than go-lua. Much of the performance difference between go-lua and gopher-lua comes from the inclusion of debug hooks in go-lua. The remainder is due to the call stack implementation - go-lua heap-allocates Lua stack frames with a separately allocated variant struct, as outlined above. Although it caches recently used stack frames, it is outperformed by the simpler statically allocated call stacks in gopher-lua.\n```\n  $ time lua fibr.lua\n  real  0m2.807s\n  user  0m2.795s\n  sys   0m0.006s\n  \n  $ time glua fibr.lua\n  real  0m14.528s\n  user  0m14.513s\n  sys   0m0.031s\n  \n  $ time go-lua fibr.lua\n  real  0m17.411s\n  user  0m17.514s\n  sys   0m1.287s\n```\n\nThe recursive Fibonacci function can be transformed into a tail-recursive variant:\n```lua\n  function fibt(n0, n1, c)\n    if c == 0 then\n      return n0\n    else if c == 1 then\n      return n1\n    end\n    return fibt(n1, n0+n1, c-1)\n  end\n  \n  function fib(n)\n    fibt(0, 1, n)\n  end\n```\n\nThe Lua interpreter detects and optimizes tail calls. This exhibits similar relative performance between the 3 interpreters, though gopher-lua edges ahead a little due to its simpler stack model and reduced bookkeeping.\n```\n  $ time lua fibt.lua\n  real  0m0.099s\n  user  0m0.096s\n  sys   0m0.002s\n\n  $ time glua fibt.lua\n  real  0m0.489s\n  user  0m0.484s\n  sys   0m0.005s\n\n  $ time go-lua fibt.lua\n  real  0m0.607s\n  user  0m0.610s\n  sys   0m0.068s\n```\n\nFinally, we can write an explicitly iterative implementation:\n```lua\n  function fib(n)\n    if n == 0 then\n      return 0\n    else if n == 1 then\n      return 1\n    end\n    local n0, n1 = 0, 1\n    for i = n, 2, -1 do\n      local tmp = n0 + n1\n      n0 = n1\n      n1 = tmp\n    end\n    return n1\n  end\n```\n\nThis exercises more of the bytecode interpreter’s inner loop. Here we see the performance impact of Go’s `switch` implementation. Both go-lua and gopher-lua are an order of magnitude slower than the C Lua interpreter.\n```\n  $ time lua fibi.lua\n  real  0m0.023s\n  user  0m0.020s\n  sys   0m0.003s\n\n  $ time glua fibi.lua\n  real  0m0.242s\n  user  0m0.235s\n  sys   0m0.005s\n\n  $ time go-lua fibi.lua\n  real  0m0.242s\n  user  0m0.240s\n  sys   0m0.028s\n```\n\nLicense\n-------\n\ngo-lua is licensed under the [MIT license](https://github.com/Shopify/go-lua/blob/master/LICENSE.md).\n","funding_links":[],"categories":["嵌入式脚本语言","嵌入式腳本語言"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2FGo-lua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShopify%2FGo-lua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2FGo-lua/lists"}