refactor: use util funcs to run lua where possible

lua5.4
TorchedSammy 2022-03-28 18:58:56 -04:00
parent 26add67287
commit d2d423a4ef
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 8 additions and 12 deletions

20
lua.go
View File

@ -23,9 +23,7 @@ func luaInit() {
lib.LoadLibs(l, hilbishLoader) lib.LoadLibs(l, hilbishLoader)
// yes this is stupid, i know // yes this is stupid, i know
chunk, _ := l.CompileAndLoadLuaChunk("", []byte("hilbish = require 'hilbish'"), rt.TableValue(l.GlobalEnv())) util.DoString(l, "hilbish = require 'hilbish'")
_, err := rt.Call1(l.MainThread(), rt.FunctionValue(chunk))
fmt.Println("hsh load", err)
// Add fs and terminal module module to Lua // Add fs and terminal module module to Lua
/* l.PreloadModule("fs", fs.Loader) /* l.PreloadModule("fs", fs.Loader)
@ -53,20 +51,18 @@ func luaInit() {
}) })
// Add more paths that Lua can require from // Add more paths that Lua can require from
chunk, _ = l.CompileAndLoadLuaChunk("", []byte("package.path = package.path .. " + requirePaths), rt.TableValue(l.GlobalEnv())) err := util.DoString(l, "package.path = package.path .. " + requirePaths)
_, err = rt.Call1(l.MainThread(), rt.FunctionValue(chunk))
fmt.Println("package path", err)
data, err := os.ReadFile("prelude/init.lua")
if err != nil { if err != nil {
data, err = os.ReadFile(preloadPath) fmt.Fprintln(os.Stderr, "Could not add preload paths! Libraries will be missing. This shouldn't happen.")
}
err = util.DoFile(l, "prelude/init.lua")
if err != nil {
err = util.DoFile(l, preloadPath)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.") fmt.Fprintln(os.Stderr, "Missing preload file, builtins may be missing.")
} }
} }
chunk, _ = l.CompileAndLoadLuaChunk("", data, rt.TableValue(l.GlobalEnv()))
_, err = rt.Call1(l.MainThread(), rt.FunctionValue(chunk))
fmt.Println("prelude", err)
} }
func runConfig(confpath string) { func runConfig(confpath string) {