Add example with lua built-in function
This commit is contained in:
@@ -8,11 +8,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
file := "example_data/02-test.lua"
|
||||
// Init log subsystem.
|
||||
log.Init("info", os.Stderr)
|
||||
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
file := "example_data/02-test.lua"
|
||||
|
||||
// Load the Lua script file.
|
||||
log.Infof("Loading %s", file)
|
||||
@@ -22,11 +21,14 @@ func main() {
|
||||
luaCode, err := os.ReadFile(file)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Error reading Lua file %s: %s", file, err)
|
||||
|
||||
os.Exit(1)
|
||||
log.Fatalf("Error reading Lua file %s: %s", file, err)
|
||||
}
|
||||
|
||||
log.Info("Creating new Lua state")
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
log.Info("Evaluating Lua code")
|
||||
if err := L.DoString(string(luaCode)); err != nil {
|
||||
log.Errorf("Error evaluating Lua code: %s", err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user