{"id":13366360,"url":"https://github.com/aarzilli/Golua","last_synced_at":"2025-03-12T18:30:58.645Z","repository":{"id":1223035,"uuid":"1144572","full_name":"aarzilli/golua","owner":"aarzilli","description":"Go bindings for Lua C API - in progress","archived":false,"fork":true,"pushed_at":"2024-08-09T12:42:54.000Z","size":294,"stargazers_count":636,"open_issues_count":8,"forks_count":162,"subscribers_count":36,"default_branch":"master","last_synced_at":"2024-08-09T14:12:41.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"afitz/golua","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aarzilli.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}},"created_at":"2010-12-06T21:39:53.000Z","updated_at":"2024-08-09T12:42:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/aarzilli/golua","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/aarzilli%2Fgolua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aarzilli%2Fgolua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aarzilli%2Fgolua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aarzilli%2Fgolua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aarzilli","download_url":"https://codeload.github.com/aarzilli/golua/tar.gz/refs/heads/master","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":[],"created_at":"2024-07-30T00:01:23.686Z","updated_at":"2025-03-12T18:30:58.639Z","avatar_url":"https://github.com/aarzilli.png","language":"C","funding_links":[],"categories":["嵌入式脚本语言","嵌入式腳本語言"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"Go Bindings for the lua C API\n=========================\n\n![Build Status](https://github.com/aarzilli/golua/actions/workflows/build.yml/badge.svg)\n\nSimplest way to install:\n\n\t# go get github.com/aarzilli/golua/lua\n\nYou can then try to run the examples:\n\n\t$ cd golua/_example/\n\t$ go run basic.go\n\t$ go run alloc.go\n\t$ go run panic.go\n\t$ go run userdata.go\n\nThis library is configured using build tags. By default it will look for a library (or \"shared object\") called:\n\n* lua5.1 on Linux and macOS\n* lua on Windows\n* lua-5.1 on FreeBSD\n\nIf this doesn't work `-tags luadash5.1` can be used to force `lua-5.1`, and `-tags llua` can be used to force `lua`.\n\nIf you want to statically link to liblua.a you can do that with `-tags luaa`. Luajit can also be used by\nspecifying `-tags luajit`.\n\nThe library uses lua5.1 by default but also supports lua5.2 by specifying `-tags lua52`, lua5.3 by\nspecifying `-tags lua53`, and lua5.4 by specifying `-tags lua54`. If the library installed on your system has a dash, for example it is called `liblua-5.4` use the `lluadash` tag: `go build -tags lua54,lluadash ...`.\n\nQUICK START\n---------------------\n\nCreate a new Virtual Machine with:\n\n```go\nL := lua.NewState()\nL.OpenLibs()\ndefer L.Close()\n```\n\nLua's Virtual Machine is stack based, you can call lua functions like this:\n\n```go\n// push \"print\" function on the stack\nL.GetGlobal(\"print\")\n// push the string \"Hello World!\" on the stack\nL.PushString(\"Hello World!\")\n// call print with one argument, expecting no results\nL.Call(1, 0)\n```\n\nOf course this isn't very useful, more useful is executing lua code from a file or from a string:\n\n```go\n// executes a string of lua code\nerr := L.DoString(\"...\")\n// executes a file\nerr = L.DoFile(filename)\n```\n\nYou will also probably want to publish go functions to the virtual machine, you can do it by:\n\n```go\nfunc adder(L *lua.State) int {\n\ta := L.ToInteger(1)\n\tb := L.ToInteger(2)\n\tL.PushInteger(a + b)\n\treturn 1 // number of return values\n}\n\nfunc main() {\n\tL := lua.NewState()\n\tdefer L.Close()\n\tL.OpenLibs()\n\n\tL.Register(\"adder\", adder)\n\tL.DoString(\"print(adder(2, 2))\")\n}\n```\n\nON ERROR HANDLING\n---------------------\n\nLua's exceptions are incompatible with Go, golua works around this incompatibility by setting up protected execution environments in `lua.State.DoString`, `lua.State.DoFile`  and lua.State.Call and turning every exception into a Go panic.\n\nThis means that:\n\n1. In general you can't do any exception handling from Lua, `pcall` and `xpcall` are renamed to `unsafe_pcall` and `unsafe_xpcall`. They are only safe to be called from Lua code that never calls back to Go. Use at your own risk.\n\n2. The call to lua.State.Error, present in previous versions of this library, has been removed as it is nonsensical\n\n3. Method calls on a newly created `lua.State` happen in an unprotected environment, if Lua throws an exception as a result your program will be terminated. If this is undesirable perform your initialization like this:\n\n```go\nfunc LuaStateInit(L *lua.State) int {\n\t… initialization goes here…\n\treturn 0\n}\n\n…\nL.PushGoFunction(LuaStateInit)\nerr := L.Call(0, 0)\n…\n```\n\nON THREADS AND COROUTINES\n---------------------\n\n'lua.State' is not thread safe, but the library itself is. Lua's coroutines exist but (to my knowledge) have never been tested and are likely to encounter the same problems that errors have, use at your own peril.\n\nODDS AND ENDS\n---------------------\n\n* If you want to build against lua5.2, lua5.3, or lua5.4 use the build tags lua52, lua53, or lua54 respectively.\n* Compiling from source yields only a static link library (liblua.a), you can either produce the dynamic link library on your own or use the `luaa` build tag.\n\nLUAJIT\n---------------------\n\nTo link with [luajit-2.0.x](http://luajit.org/luajit.html), you can use CGO_CFLAGS and CGO_LDFLAGS environment variables\n\n```\n$ CGO_CFLAGS=`pkg-config luajit --cflags`\n$ CGO_LDFLAGS=`pkg-config luajit --libs-only-L`\n$ go get -f -u -tags luajit github.com/aarzilli/golua/lua\n```\n\nCONTRIBUTORS\n---------------------\n\n* Adam Fitzgerald (original author)\n* Alessandro Arzilli\n* Steve Donovan\n* Harley Laue\n* James Nurmi\n* Ruitao\n* Xushiwei\n* Isaint\n* hsinhoyeh\n* Viktor Palmkvist\n* HongZhen Peng\n* Admin36\n* Pierre Neidhardt (@Ambrevar)\n* HuangWei (@huangwei1024)\n* Adam Saponara\n* [Tim van Osch](https://github.com/TimVosch)\n\nSEE ALSO\n---------------------\n\n- [Luar](https://github.com/stevedonovan/luar/) is a reflection layer on top of golua API providing a simplified way to publish go functions to a Lua VM.\n- [lunatico](https://github.com/fiatjaf/lunatico) is a reflection layer that allows you to push and read Go values to a Lua VM without understanding the Lua stack.\n- [Golua unicode](https://github.com/Ambrevar/golua) is an extension library that adds unicode support to golua and replaces lua regular expressions with re2.\n\nLicensing\n-------------\nGoLua is released under the MIT license.\nPlease see the LICENSE file for more information.\n\nLua is Copyright (c) Lua.org, PUC-Rio.  All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faarzilli%2FGolua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faarzilli%2FGolua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faarzilli%2FGolua/lists"}