-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (36 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"embed"
"os"
"github.com/tongson/LadyLua"
"github.com/yuin/gopher-lua"
)
//go:embed main/*
var mainSrc embed.FS
//go:embed src/*
var luaSrc embed.FS
func main() {
L := lua.NewState()
defer L.Close()
// See for available modules -> https://github.com/tongson/LadyLua#modules
// Also:
// https://github.com/tongson/LadyLua/blob/main/docs/go-loader.adoc
// https://github.com/tongson/LadyLua/blob/main/docs/go-helper.adoc
// Load `http` and `json` modules
ll.PreloadGo(L, "http")
ll.PreloadGo(L, "json")
ll.LoadGlobalGo(L, "extend")
// Allow loading(require) Lua code from LadyLua; found in `LadyLua/internal/lua`
ll.Preload(L)
// Load Lua source from `src`; for `require("cvrf")`
// Usually modules specific to a project or program
// Depends on the go:embed directive, any directory or filename works
ll.PreloadModule(L, "cvrf", ll.ReadFile(luaSrc, "src/cvrf.lua"))
// Capture command line arguments
ll.FillArg(L, os.Args)
// Load Lua source from `main`; the entrypoint Lua code or so-called main()
// Depends on the go:embed directive, any directory or filename works
ll.Main(L, ll.ReadFile(mainSrc, "main/main.lua"))
// If all goes well; Lua code can call `os.exit` to override exit code
os.Exit(0)
}