Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
0165915
setting an execution limit to lua code in terms of number of instruct…
aarzilli Mar 20, 2011
c0e50ea
updated to compile on last go release (r60, 20110908)
Sep 8, 2011
4ae2638
better way to make this compile with release (thanks to vase / v.tols…
Sep 30, 2011
c8b077a
Vasily (v.tolstov@selfip.ru) patch to Makefile
Sep 30, 2011
47aebd0
changes to make the previous patch work on my system:
Sep 30, 2011
cc9f008
Clean up some memory leaks in initialization.
Jul 6, 2011
7dda61b
Compiles with go1 (barely tested)
aarzilli Mar 31, 2012
bc4e72f
readme update
aarzilli Mar 31, 2012
e62ba98
Import path fixes for examples and more explanations in README
aarzilli Mar 31, 2012
4a2a375
Merging https://github.com/aarzilli/golua/pull/1 from ruitao (thanks)
aarzilli Jun 24, 2012
e44d144
changed examples to make them easier to run locally
aarzilli Jun 26, 2012
097c56b
pushing go interfaces to lua like we do with functions, changed name …
aarzilli Jun 28, 2012
e210009
clua_isgointerface
aarzilli Jun 28, 2012
b3a1fd1
PushGoStruct -- with reflection to access and set plain data fields
aarzilli Jul 18, 2012
4b79a92
go fmt run (and consistent formatting in c-golua.c)
aarzilli Jul 18, 2012
e36b6d3
removed some garbage, collected TODO items, made lauxlib functions in…
aarzilli Jul 18, 2012
40b8d1a
documentation
aarzilli Jul 20, 2012
2e01ce2
some testing
aarzilli Oct 17, 2012
ad8ad2e
returning nil in ToGoStruct/ToGoFunction
aarzilli Oct 17, 2012
11e5a39
Fixed example/basic.go
aarzilli Oct 27, 2012
dd5cb7a
lua.State.Error never worked or was broken by some go update at some …
aarzilli Oct 27, 2012
bf83d11
bugfixes: more longjump madness plus a bug in the garbage collection …
aarzilli Oct 27, 2012
4c44a0e
damn you go!!!!
aarzilli Oct 27, 2012
829ce7a
new todo item
aarzilli Oct 27, 2012
69c75da
quick start guide
aarzilli Oct 30, 2012
487c090
Update README.md
xushiwei Nov 22, 2012
4a78253
clua_pushcallback has been added to allow definining metamethods with…
losinggeneration Dec 11, 2012
a3f4feb
Changed PushCallback into SetMetaMethod
aarzilli Dec 15, 2012
bd064a4
restored lua.State.Error function to existence with a hack
aarzilli Dec 21, 2012
1ef48b4
added Lua 5.1 headers (cherry picked Steve Donovan commit)
aarzilli Dec 22, 2012
9b14eb2
(cherry picked from Steve Donovan fork) configuring cgo directly isnt…
aarzilli Dec 22, 2012
a8bb240
updated README.md
aarzilli Jan 1, 2013
d8e5c9e
Fixes issue #4 (or at least I hope it does)
aarzilli Mar 31, 2013
cb41947
collect all consts under a single const statement
aarzilli Mar 31, 2013
67ae247
Added list of contributors to README.md
aarzilli Mar 31, 2013
54de819
Saving lua return code inside LuaError
aarzilli Apr 1, 2013
e232130
saving lua stack trace
aarzilli Apr 1, 2013
aaa092a
Clarification about using the llua build tag on linux
aarzilli May 4, 2013
d81fa4e
Exposing method to create LuaError objects (fixes Issue 7)
aarzilli Jun 17, 2013
6836c92
replaced example allocator in example/alloc.go with one that isn't br…
aarzilli Aug 6, 2013
82d28bf
changed PushString and ToString to work correctly when their argument…
aarzilli Aug 23, 2013
aaa0b86
better formatting for contributors list + new contributor
aarzilli Aug 23, 2013
01ee1fe
fix README.md
hirochachacha Aug 30, 2013
fd4c547
Merge pull request #16 from hirochachacha/fix_doc
aarzilli Aug 30, 2013
fc1ef17
pointer to lua 5.2 support
aarzilli Sep 18, 2013
bee077b
Merge branch 'master' of github.com:aarzilli/golua
aarzilli Sep 18, 2013
d2aab31
target to link with liblua.a
aarzilli Dec 20, 2013
fb28da3
Added note for liblua.a in README
aarzilli Dec 20, 2013
1c34426
fix issue #22
aarzilli Jan 17, 2014
5c5d9af
Fix #26
elegios Aug 20, 2014
92c46e1
Merge pull request #27 from elegios/master
aarzilli Aug 20, 2014
baea951
Added contributor for Fix #27
aarzilli Aug 20, 2014
3bbbc0c
Fix build ldflags for freebsd
hongzhen Dec 1, 2014
7c8b036
Merge pull request #30 from hongzhen/master
aarzilli Dec 9, 2014
8db26f9
Added hongzhen to contributors
aarzilli Dec 9, 2014
3f64d28
link with luajit
flier Jun 17, 2015
f6ffa4b
Merge pull request #33 from flier/luajit
aarzilli Jun 17, 2015
e56d4f2
Add lua.PushGoClosure() method
rdlaitila Jul 29, 2015
fa75383
update build flags for osx
Sep 29, 2015
b89ed89
Merge pull request #1 from gcziprusz/gcziprusz-osxbuildflag-update
Sep 29, 2015
e80696f
Merge pull request #38 from gcziprusz/master
aarzilli Sep 30, 2015
b30b2c6
luaL_argcheck: Raise an error when condition is _not_ true
Ambrevar Nov 30, 2015
fb8ef86
Insured that code that uses the old version of ArgCheck does not compile
aarzilli Dec 1, 2015
1074bd5
Go 1.6 beta 1 compatibility
aarzilli Dec 24, 2015
c155673
go fmt
aarzilli Dec 24, 2015
aa40b80
Make golua build on Fedora/CentOS
aarzilli Jan 22, 2016
d4351ab
Use map to track gostate rather than slice
shanemhansen Apr 6, 2016
3933e72
Added ToBytes and PushBytes methods. Updated magic struct reflection…
acd Aug 4, 2016
13f31dc
Add link to "golua unicode"
aarzilli Aug 7, 2016
cf37152
support mingw64 on windows
huangwei1024 Mar 13, 2017
398439a
update README to mention lua5.3 branch.
aarzilli Mar 26, 2017
8eb37ae
update to work with go1.9
aarzilli May 22, 2017
8a6e7a0
Add travis check
aarzilli May 22, 2017
812b106
force to link luajit with tag
flier Aug 16, 2017
24dee68
fix new state crash
flier Aug 16, 2017
24fe5b5
Changed golua unicode link.
aarzilli Sep 4, 2017
459c093
Ensure that registry resize is large enough
aarzilli Mar 2, 2018
e82ac2f
add lua_dump and lua_load support
Jul 13, 2019
d4a4304
test dump and load
aarzilli Jul 14, 2019
8cb2917
add lunatico
fiatjaf Jan 19, 2020
421e0de
add GetState func
edolphin-ydf Feb 14, 2020
703cd57
Fix vendoring of package using go mod vendor
Jul 22, 2020
80ff49e
Add option to link to liblua-5.1.so
aarzilli Aug 3, 2020
705f54a
Add go.mod, fix eamples import paths, gofmt examples
aarzilli Aug 3, 2020
4563e62
fix references to example directory
aarzilli Aug 3, 2020
7f78a3b
merge branches lua5.2 and lua5.3 into master
aarzilli Aug 25, 2020
c7e4636
Add support for Lua 5.4
adsr Oct 24, 2020
2701145
save pointer to allocation function before passing it to cgo (#85)
superrxan Nov 6, 2020
3c8365d
Remove stale import from dummy.go
superrxan Nov 10, 2020
b3ec3b5
Fix typo in README.md
ptxmac Dec 25, 2020
9cdcedc
Improve linking on windows
ptxmac Dec 25, 2020
caa5d72
Rename errno because it's a reserved global variable
ptxmac Dec 25, 2020
717e993
Add LUA_OK constant (#92)
ptxmac Dec 27, 2020
f22fa65
Update travis distribution
aarzilli May 7, 2021
11106aa
Custom Debug Hook in Go via "State.SetHook" (#99)
Simerax May 7, 2021
e24027f
Add a generic lluadash tag
aarzilli Aug 9, 2024
dc21732
add github actions to build & test
aarzilli Sep 26, 2024
1841fa0
Add helper function to easily create lua libraries (#116)
MrNavaStar Oct 31, 2024
99a25f0
Add ability to create lua states with context (#118)
MrNavaStar Nov 10, 2024
8c04b0e
style: Run gofumpt over all source
TimVosch Dec 26, 2024
7609e5d
feat: Add PushGoClosureWithUpvalues
TimVosch Dec 26, 2024
c0240bb
docs: create doc generator
TimVosch Dec 26, 2024
25c9791
docs: add documentation to methods
TimVosch Dec 26, 2024
b6690b5
docs: Add -clean option to remove added docs
TimVosch Dec 26, 2024
e3db1ba
docs: fix comment formatting
TimVosch Dec 27, 2024
cd31ab2
docs: add TimVosch to contributors
TimVosch Dec 27, 2024
248753f
Fix C.lua_tointeger returning C.integer in some compilers (#122)
marko1777 Feb 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: aarzilli
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build and Test
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install Lua
run: sudo apt-get install lua5.4 liblua5.4-dev
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '>=1.20.0'
- name: Build
run: go build -tags lua54 -v ./...
- name: Test
run: go test -tags lua54 -v ./...
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

32 changes: 0 additions & 32 deletions README

This file was deleted.

162 changes: 162 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Go Bindings for the lua C API
=========================

![Build Status](https://github.com/aarzilli/golua/actions/workflows/build.yml/badge.svg)

Simplest way to install:

# go get github.com/aarzilli/golua/lua

You can then try to run the examples:

$ cd golua/_example/
$ go run basic.go
$ go run alloc.go
$ go run panic.go
$ go run userdata.go

This library is configured using build tags. By default it will look for a library (or "shared object") called:

* lua5.1 on Linux and macOS
* lua on Windows
* lua-5.1 on FreeBSD

If this doesn't work `-tags luadash5.1` can be used to force `lua-5.1`, and `-tags llua` can be used to force `lua`.

If you want to statically link to liblua.a you can do that with `-tags luaa`. Luajit can also be used by
specifying `-tags luajit`.

The library uses lua5.1 by default but also supports lua5.2 by specifying `-tags lua52`, lua5.3 by
specifying `-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 ...`.

QUICK START
---------------------

Create a new Virtual Machine with:

```go
L := lua.NewState()
L.OpenLibs()
defer L.Close()
```

Lua's Virtual Machine is stack based, you can call lua functions like this:

```go
// push "print" function on the stack
L.GetGlobal("print")
// push the string "Hello World!" on the stack
L.PushString("Hello World!")
// call print with one argument, expecting no results
L.Call(1, 0)
```

Of course this isn't very useful, more useful is executing lua code from a file or from a string:

```go
// executes a string of lua code
err := L.DoString("...")
// executes a file
err = L.DoFile(filename)
```

You will also probably want to publish go functions to the virtual machine, you can do it by:

```go
func adder(L *lua.State) int {
a := L.ToInteger(1)
b := L.ToInteger(2)
L.PushInteger(a + b)
return 1 // number of return values
}

func main() {
L := lua.NewState()
defer L.Close()
L.OpenLibs()

L.Register("adder", adder)
L.DoString("print(adder(2, 2))")
}
```

ON ERROR HANDLING
---------------------

Lua'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.

This means that:

1. 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.

2. The call to lua.State.Error, present in previous versions of this library, has been removed as it is nonsensical

3. 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:

```go
func LuaStateInit(L *lua.State) int {
… initialization goes here…
return 0
}

L.PushGoFunction(LuaStateInit)
err := L.Call(0, 0)
```

ON THREADS AND COROUTINES
---------------------

'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.

ODDS AND ENDS
---------------------

* If you want to build against lua5.2, lua5.3, or lua5.4 use the build tags lua52, lua53, or lua54 respectively.
* 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.

LUAJIT
---------------------

To link with [luajit-2.0.x](http://luajit.org/luajit.html), you can use CGO_CFLAGS and CGO_LDFLAGS environment variables

```
$ CGO_CFLAGS=`pkg-config luajit --cflags`
$ CGO_LDFLAGS=`pkg-config luajit --libs-only-L`
$ go get -f -u -tags luajit github.com/aarzilli/golua/lua
```

CONTRIBUTORS
---------------------

* Adam Fitzgerald (original author)
* Alessandro Arzilli
* Steve Donovan
* Harley Laue
* James Nurmi
* Ruitao
* Xushiwei
* Isaint
* hsinhoyeh
* Viktor Palmkvist
* HongZhen Peng
* Admin36
* Pierre Neidhardt (@Ambrevar)
* HuangWei (@huangwei1024)
* Adam Saponara
* [Tim van Osch](https://github.com/TimVosch)

SEE ALSO
---------------------

- [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.
- [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.
- [Golua unicode](https://github.com/Ambrevar/golua) is an extension library that adds unicode support to golua and replaces lua regular expressions with re2.

Licensing
-------------
GoLua is released under the MIT license.
Please see the LICENSE file for more information.

Lua is Copyright (c) Lua.org, PUC-Rio. All rights reserved.
6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- find all calls to lua api that can result in lua_error calls and rework them (for example checkarg stuff)
- lua.go: Dump implementing lua_dump
- lua.go: Load implementing lua_load
- AtPanic slightly broken when nil is passed, if we think passing nil has value to extract the current atpanic function we should also make sure it doesn't break everything
- threads implementation is probably fucked completely should look into it
- lauxlib.go:CheckOption is not implemented
1 change: 1 addition & 0 deletions _docgenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cache/
4 changes: 4 additions & 0 deletions _docgenerator/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// lua_upvalueindex
func (L *State) UpvalueIndex(n int) int {
return int(C.clua_upvalueindex(C.int32_t(n)))
}
10 changes: 10 additions & 0 deletions _docgenerator/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module docgen

go 1.23.4

require github.com/PuerkitoBio/goquery v1.10.0

require (
github.com/andybalholm/cascadia v1.3.2 // indirect
golang.org/x/net v0.29.0 // indirect
)
40 changes: 40 additions & 0 deletions _docgenerator/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4=
github.com/PuerkitoBio/goquery v1.10.0/go.mod h1:TjZZl68Q3eGHNBA8CWaxAN7rOU1EbDz3CWuolcO5Yu4=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Loading