{"id":22442480,"url":"https://github.com/nevercase/golua","last_synced_at":"2025-08-13T02:46:19.754Z","repository":{"id":57616522,"uuid":"384309815","full_name":"neverCase/golua","owner":"neverCase","description":"go call lua by capi","archived":false,"fork":false,"pushed_at":"2021-07-09T03:27:17.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T10:17:29.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/neverCase.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":"2021-07-09T03:24:45.000Z","updated_at":"2021-07-09T03:27:20.000Z","dependencies_parsed_at":"2022-08-27T08:22:04.380Z","dependency_job_id":null,"html_url":"https://github.com/neverCase/golua","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/neverCase/golua","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverCase%2Fgolua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverCase%2Fgolua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverCase%2Fgolua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverCase%2Fgolua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neverCase","download_url":"https://codeload.github.com/neverCase/golua/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverCase%2Fgolua/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270170339,"owners_count":24539355,"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","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12-06T02:19:17.041Z","updated_at":"2025-08-13T02:46:19.717Z","avatar_url":"https://github.com/neverCase.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Go Bindings for the lua C API\n=========================\n\n[![Build Status](https://travis-ci.org/aarzilli/golua.svg?branch=lua5.3)](https://travis-ci.org/aarzilli/golua)\n\nSimplest way to install:\n\n\t# go get -u github.com/aarzilli/golua/lua\n\nWill work as long as your compiler can find a shared object called lua5.1 on linux, or lua anywhere else.\nIf your linux system uses \"lua\" as the shared object name for lua (for example, Fedora Core does this) you can install using:\n\n\t# go get -u -tags llua github.com/aarzilli/golua/lua\n\n\nYou can then try to run the examples:\n\n\t$ cd /usr/local/go/src/pkg/github.com/aarzilli/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\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:\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.\n2. The call to lua.State.Error, present in previous versions of this library, has been removed as it is nonsensical\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* 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\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\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- [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%2Fnevercase%2Fgolua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnevercase%2Fgolua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnevercase%2Fgolua/lists"}