A Lua 5.3 VM in pure Go — no CGo, no dependencies.
This is a fork of Shopify/go-lua, upgraded from Lua 5.2 to Lua 5.3.
- Native 64-bit integers (
int64) alongside floats (float64) - Bitwise operators:
&,|,~,<<,>>and unary~ - Integer division:
// - Coroutines:
coroutine.create,resume,yield,wrap,status,running - UTF-8 library:
utf8.char,utf8.codes,utf8.codepoint,utf8.len,utf8.offset - String packing:
string.pack,string.unpack,string.packsize - Math extensions:
math.tointeger,math.type,math.ult,math.maxinteger,math.mininteger - Table move:
table.move(a1, f, e, t [,a2]) - Table metamethods:
table.insert,table.remove,table.sortrespect__index/__newindex - Hex float format:
string.formatsupports%a/%A
go get github.com/speedata/go-luaA minimal example:
package main
import "github.com/speedata/go-lua"
func main() {
l := lua.NewState()
lua.OpenLibraries(l)
if err := lua.DoFile(l, "hello.lua"); err != nil {
panic(err)
}
}l := lua.NewState()
lua.OpenLibraries(l)
lua.DoString(l, `
function greet(name)
return "Hello, " .. name .. "!"
end
`)
l.Global("greet")
l.PushString("World")
l.Call(1, 1)
result, _ := l.ToString(-1)
fmt.Println(result) // Hello, World!l := lua.NewState()
lua.OpenLibraries(l)
l.Register("add", func(l *lua.State) int {
a := lua.CheckNumber(l, 1)
b := lua.CheckNumber(l, 2)
l.PushNumber(a + b)
return 1
})
lua.DoString(l, `print(add(2, 3))`) // 5We run the official Lua 5.3 test suites. Currently 19 out of 24 pass:
| Test | Status | Notes |
|---|---|---|
| bitwise | Pass | |
| calls | Pass | |
| closure | Pass | |
| code | Pass | |
| constructs | Pass | |
| coroutine | Pass | |
| errors | Pass | |
| events | Pass | |
| files | Pass | |
| goto | Pass | |
| literals | Pass | |
| locals | Pass | |
| math | Pass | |
| pm (pattern matching) | Pass | |
| sort | Pass | |
| strings | Pass | |
| tpack (string.pack) | Pass | |
| utf8 | Pass | |
| vararg | Pass | |
| attrib | — | Needs debug.getinfo, weak refs |
| db | — | Needs debug.getlocal for coroutines |
| gc | — | Go's GC, not controllable like Lua's |
| big | — | Tables with >2^18 elements |
| main | — | Requires standalone Lua binary |
- No weak references —
__modeon metatables is not supported (Go's GC doesn't offer that hook) - No
string.dump— serializing functions to bytecode is not implemented - Partial
debuglibrary —debug.getlocalanddebug.upvalueidare not yet implemented - No C API — pure Go, so C Lua libraries won't work (that's kind of the point though)
git clone https://github.com/speedata/go-lua.git
go build ./...
go test ./...Some tests optionally use luac 5.3 for compiling Lua source to bytecode. If it's not in your PATH, those tests get skipped automatically.
MIT — see LICENSE.md.
Originally forked from Shopify/go-lua.