The embedding example from the README does not compile. When I try to embed that code snippet in a program like this:
package main
import (
"fmt"
"os"
rt "github.com/arnodel/golua/runtime"
)
func main() {
// First we obtain a new Lua runtime which outputs to stdout
r := rt.New(os.Stdout)
// This is the chunk we want to run. It returns an adding function.
source := []byte(`return function(x, y) return x + y end`)
// Compile the chunk. Note that compiling doesn't require a runtime.
chunk, _ := rt.CompileAndLoadLuaChunk("test", source, r.GlobalEnv())
// Run the chunk in the runtime's main thread. Its output is the Lua adding
// function.
f, _ := rt.Call1(r.MainThread(), chunk)
// Now, run the Lua function in the main thread.
sum, _ := rt.Call1(r.MainThread(), f, rt.Int(40), rt.Int(2))
// --> 42
fmt.Println(sum)
}
package main
import (
"fmt"
"os"
rt "github.com/arnodel/golua/runtime"
)
func main() {
// First we obtain a new Lua runtime which outputs to stdout
r := rt.New(os.Stdout)
// This is the chunk we want to run. It returns an adding function.
source := []byte(`return function(x, y) return x + y end`)
// Compile the chunk. Note that compiling requires a runtime.
chunk, _ := r.CompileAndLoadLuaChunk(
"test", source, rt.TableValue(r.GlobalEnv()))
// Run the chunk in the runtime's main thread. Its output is the Lua adding
// function.
f, _ := rt.Call1(r.MainThread(), rt.FunctionValue(chunk))
// Now, run the Lua function in the main thread.
sum, _ := rt.Call1(r.MainThread(), f, rt.IntValue(40), rt.IntValue(2))
// --> 42
fmt.Println(sum.AsInt())
}
correctly prints 42.
Therefore I'd like to suggest to update the README accordingly.
The embedding example from the README does not compile. When I try to embed that code snippet in a program like this:
I get compiler errors:
With the "obvious" fixes it works again:
correctly prints
42
.Therefore I'd like to suggest to update the README accordingly.