refactor(minor): reduce the amount of module renaming

pull/42/head
sammy 2021-04-28 18:57:28 -04:00
parent a29eddb1bf
commit e0cf87d272
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
3 changed files with 15 additions and 15 deletions

16
lua.go
View File

@ -2,12 +2,12 @@ package main
import (
"fmt"
hooks "hilbish/golibs/bait"
cmds "hilbish/golibs/commander"
"hilbish/golibs/bait"
"hilbish/golibs/commander"
lfs "hilbish/golibs/fs"
"os"
lua "github.com/yuin/gopher-lua"
"github.com/yuin/gopher-lua"
)
var minimalconf = `
@ -32,9 +32,9 @@ func LuaInit(confpath string) {
// Add fs module to Lua
l.PreloadModule("fs", lfs.Loader)
commander := cmds.New()
cmds := commander.New()
// When a command from Lua is added, register it for use
commander.Events.On("commandRegister",
cmds.Events.On("commandRegister",
func(cmdName string, cmd *lua.LFunction) {
commands[cmdName] = true
l.SetField(
@ -44,10 +44,10 @@ func LuaInit(confpath string) {
cmd)
})
l.PreloadModule("commander", commander.Loader)
l.PreloadModule("commander", cmds.Loader)
bait = hooks.New()
l.PreloadModule("bait", bait.Loader)
hooks = bait.New()
l.PreloadModule("bait", hooks.Loader)
// Add more paths that Lua can require from
l.DoString(`package.path = package.path

View File

@ -8,7 +8,7 @@ import (
"os/user"
"strings"
hooks "hilbish/golibs/bait"
"hilbish/golibs/bait"
"github.com/akamensky/argparse"
"github.com/bobappleyard/readline"
@ -28,7 +28,7 @@ var (
commands = map[string]bool{}
aliases = map[string]string{}
bait hooks.Bait
hooks bait.Bait
homedir string
running bool
interactive bool

View File

@ -23,7 +23,7 @@ func RunInput(input string) {
// If it succeeds, add to history and prompt again
HandleHistory(input)
bait.Em.Emit("command.exit", 0)
hooks.Em.Emit("command.exit", 0)
return
}
@ -71,22 +71,22 @@ func RunInput(input string) {
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
continue
} else if code, ok := interp.IsExitStatus(err); ok {
bait.Em.Emit("command.exit", code)
hooks.Em.Emit("command.exit", code)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
bait.Em.Emit("command.exit", 1)
hooks.Em.Emit("command.exit", 1)
}
break
}
} else {
if code, ok := interp.IsExitStatus(err); ok {
bait.Em.Emit("command.exit", code)
hooks.Em.Emit("command.exit", code)
} else {
fmt.Fprintln(os.Stderr, err)
}
}
} else {
bait.Em.Emit("command.exit", 0)
hooks.Em.Emit("command.exit", 0)
}
HandleHistory(cmdString)
}