Add example with lua built-in function

This commit is contained in:
eleksir
2025-10-27 18:54:51 +03:00
parent b0c28ef87f
commit 88b48cdb4d
5 changed files with 113 additions and 23 deletions

View File

@@ -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)