2021-03-19 23:03:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-03-31 02:37:08 +00:00
|
|
|
"fmt"
|
2021-05-01 19:35:43 +00:00
|
|
|
"os"
|
|
|
|
|
2024-07-19 20:54:15 +00:00
|
|
|
//"hilbish/util"
|
2024-07-20 14:50:04 +00:00
|
|
|
"hilbish/golibs/bait"
|
2024-07-20 15:46:07 +00:00
|
|
|
"hilbish/golibs/commander"
|
2024-07-20 15:34:39 +00:00
|
|
|
"hilbish/golibs/fs"
|
2024-07-20 15:59:14 +00:00
|
|
|
"hilbish/golibs/terminal"
|
2021-03-31 02:37:08 +00:00
|
|
|
|
2024-07-19 20:54:15 +00:00
|
|
|
"hilbish/moonlight"
|
2021-03-19 23:03:11 +00:00
|
|
|
)
|
|
|
|
|
2022-01-27 21:01:27 +00:00
|
|
|
var minimalconf = `hilbish.prompt '& '`
|
2021-04-05 00:31:32 +00:00
|
|
|
|
2021-12-09 03:31:48 +00:00
|
|
|
func luaInit() {
|
2024-07-19 20:54:15 +00:00
|
|
|
l = moonlight.NewRuntime()
|
|
|
|
setupSinkType()
|
2021-03-31 02:37:08 +00:00
|
|
|
|
2024-07-19 20:54:15 +00:00
|
|
|
l.LoadLibrary(hilbishLoader, "hilbish")
|
2021-05-16 21:13:28 +00:00
|
|
|
// yes this is stupid, i know
|
2024-07-19 20:54:15 +00:00
|
|
|
l.DoString("hilbish = require 'hilbish'")
|
2021-05-16 19:53:21 +00:00
|
|
|
|
2021-10-17 20:10:57 +00:00
|
|
|
// Add fs and terminal module module to Lua
|
2024-07-20 13:31:57 +00:00
|
|
|
f := fs.New(runner)
|
2024-07-20 15:34:39 +00:00
|
|
|
l.LoadLibrary(f.Loader, "fs")
|
2024-07-20 15:59:14 +00:00
|
|
|
|
|
|
|
l.LoadLibrary(terminal.Loader, "terminal")
|
|
|
|
|
2024-07-20 15:46:07 +00:00
|
|
|
cmds = commander.New(l)
|
|
|
|
l.LoadLibrary(cmds.Loader, "commander")
|
|
|
|
|
2022-08-17 22:01:32 +00:00
|
|
|
hooks = bait.New(l)
|
|
|
|
hooks.SetRecoverer(func(event string, handler *bait.Listener, err interface{}) {
|
2022-10-11 21:41:13 +00:00
|
|
|
fmt.Println("Error in `error` hook handler:", err)
|
2022-08-17 22:01:32 +00:00
|
|
|
hooks.Off(event, handler)
|
|
|
|
})
|
2024-07-20 14:50:04 +00:00
|
|
|
l.LoadLibrary(hooks.Loader, "bait")
|
|
|
|
/*
|
2021-11-22 20:13:05 +00:00
|
|
|
// Add Ctrl-C handler
|
2022-08-17 22:01:32 +00:00
|
|
|
hooks.On("signal.sigint", func(...interface{}) {
|
2021-11-22 20:13:05 +00:00
|
|
|
if !interactive {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-07-11 00:34:00 +00:00
|
|
|
lr.rl.RawInputCallback = func(r []rune) {
|
2022-08-17 22:01:32 +00:00
|
|
|
hooks.Emit("hilbish.rawInput", string(r))
|
2022-07-11 00:34:00 +00:00
|
|
|
}
|
2024-07-19 20:54:15 +00:00
|
|
|
*/
|
2022-07-11 00:34:00 +00:00
|
|
|
|
2021-03-31 02:37:08 +00:00
|
|
|
// Add more paths that Lua can require from
|
2024-07-26 21:58:25 +00:00
|
|
|
_, err := l.DoString("print(type(hilbish)); package.path = package.path .. " + requirePaths)
|
2022-04-04 10:40:02 +00:00
|
|
|
if err != nil {
|
2024-07-20 14:53:49 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2022-05-01 00:31:37 +00:00
|
|
|
fmt.Fprintln(os.Stderr, "Could not add Hilbish require paths! Libraries will be missing. This shouldn't happen.")
|
2022-04-04 10:40:02 +00:00
|
|
|
}
|
2021-03-31 02:37:08 +00:00
|
|
|
|
2024-07-19 20:54:15 +00:00
|
|
|
err1 := l.DoFile("nature/init.lua")
|
2022-05-06 23:21:32 +00:00
|
|
|
if err1 != nil {
|
2024-07-19 20:54:15 +00:00
|
|
|
err2 := l.DoFile(preloadPath)
|
2022-05-06 23:21:32 +00:00
|
|
|
if err2 != nil {
|
2022-05-01 00:31:37 +00:00
|
|
|
fmt.Fprintln(os.Stderr, "Missing nature module, some functionality and builtins will be missing.")
|
2022-05-06 23:21:32 +00:00
|
|
|
fmt.Fprintln(os.Stderr, "local error:", err1)
|
|
|
|
fmt.Fprintln(os.Stderr, "global install error:", err2)
|
2021-03-31 02:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 18:17:14 +00:00
|
|
|
}
|
2022-04-04 10:40:02 +00:00
|
|
|
|
2021-12-06 21:21:31 +00:00
|
|
|
func runConfig(confpath string) {
|
2021-04-28 11:26:23 +00:00
|
|
|
if !interactive {
|
|
|
|
return
|
|
|
|
}
|
2024-07-19 20:54:15 +00:00
|
|
|
err := l.DoFile(confpath)
|
2021-03-31 02:37:08 +00:00
|
|
|
if err != nil {
|
2022-04-04 10:40:02 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err, "\nAn error has occured while loading your config! Falling back to minimal default config.")
|
2024-07-19 20:54:15 +00:00
|
|
|
l.DoString(minimalconf)
|
2021-03-31 02:37:08 +00:00
|
|
|
}
|
|
|
|
}
|