feat!: move username and version access to hilbish table

instead of having ugly `_user` and `_ver` variables,
`hilbish.user` and `hilbish.version` is used
pull/59/head
sammyette 2021-05-16 15:53:21 -04:00
parent 9415c5193e
commit e29ba6a0d5
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
3 changed files with 24 additions and 5 deletions

11
hilbish.go 100644
View File

@ -0,0 +1,11 @@
// Here is the core api for the hilbi shell itself
// Basically, stuff about the shell itself and other functions
// go here.
package main
type Hilbish struct {
Version string `luar:"version"` // Hilbish's version
User string `luar:"user"` // Name of the user
Hostname string `luar:"hostname"`
}

7
lua.go
View File

@ -12,6 +12,7 @@ import (
"hilbish/golibs/fs"
"github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
)
var minimalconf = `
@ -23,18 +24,16 @@ prompt(ansikit.format(
func LuaInit() {
l = lua.NewState()
l.OpenLibs()
l.SetGlobal("_ver", lua.LString(version))
l.SetGlobal("_user", lua.LString(curuser.Username))
l.SetGlobal("prompt", l.NewFunction(hshprompt))
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
l.SetGlobal("alias", l.NewFunction(hshalias))
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
l.SetGlobal("exec", l.NewFunction(hshexec))
l.SetGlobal("hilbish", luar.New(l, hilbish))
// Add fs module to Lua
l.PreloadModule("fs", fs.Loader)

11
main.go
View File

@ -18,9 +18,9 @@ import (
"golang.org/x/term"
)
var version = "v0.4.0"
var (
version = "v0.4.0"
l *lua.LState
prompt string // User's prompt, this will get set when lua side is initialized
@ -37,6 +37,7 @@ var (
interactive bool
login bool // Are we the login shell?
noexecute bool // Should we run Lua or only report syntax errors
hilbish *Hilbish // dont ask
)
func main() {
@ -108,6 +109,14 @@ func main() {
}
}
host, _ := os.Hostname()
hilbish = &Hilbish {
Version: version,
User: curuser.Username,
Hostname: host,
}
go HandleSignals()
LuaInit()
RunLogin()