mirror of https://github.com/Hilbis/Hilbish
feat: add hilbish module functions used by prelude
parent
a7722fa331
commit
7909aeb4b3
47
api.go
47
api.go
|
@ -22,24 +22,32 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var exports = map[string]util.LuaExport{
|
var exports = map[string]util.LuaExport{
|
||||||
/*"alias": hlalias,
|
/*
|
||||||
|
"alias": hlalias,
|
||||||
"appendPath": hlappendPath,
|
"appendPath": hlappendPath,
|
||||||
"complete": hlcomplete,
|
"complete": hlcomplete,
|
||||||
"cwd": hlcwd,
|
*/
|
||||||
|
"cwd": util.LuaExport{hlcwd, 0, false},
|
||||||
|
/*
|
||||||
"exec": hlexec,
|
"exec": hlexec,
|
||||||
"runnerMode": hlrunnerMode,
|
"runnerMode": hlrunnerMode,
|
||||||
"goro": hlgoro,
|
"goro": hlgoro,
|
||||||
"highlighter": hlhighlighter,
|
"highlighter": hlhighlighter,
|
||||||
"hinter": hlhinter,
|
"hinter": hlhinter,
|
||||||
"multiprompt": hlmlprompt,
|
"multiprompt": hlmlprompt,
|
||||||
"prependPath": hlprependPath,*/
|
"prependPath": hlprependPath,
|
||||||
|
*/
|
||||||
"prompt": util.LuaExport{hlprompt, 1, false},
|
"prompt": util.LuaExport{hlprompt, 1, false},
|
||||||
/*"inputMode": hlinputMode,
|
/*
|
||||||
|
"inputMode": hlinputMode,
|
||||||
"interval": hlinterval,
|
"interval": hlinterval,
|
||||||
"read": hlread,
|
*/
|
||||||
|
"read": util.LuaExport{hlprompt, 1, false},
|
||||||
|
/*
|
||||||
"run": hlrun,
|
"run": hlrun,
|
||||||
"timeout": hltimeout,
|
"timeout": hltimeout,
|
||||||
"which": hlwhich,*/
|
"which": hlwhich,
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
var greeting string
|
var greeting string
|
||||||
|
@ -69,8 +77,8 @@ Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
||||||
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
||||||
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
||||||
util.SetField(L, mod, "home", lua.LString(curuser.HomeDir), "Home directory of the user")
|
|
||||||
*/
|
*/
|
||||||
|
util.SetField(rtm, mod, "home", rt.StringValue(curuser.HomeDir), "Home directory of the user")
|
||||||
util.SetField(rtm, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files")
|
util.SetField(rtm, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files")
|
||||||
/*
|
/*
|
||||||
util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
||||||
|
@ -218,37 +226,40 @@ func hlrun(L *lua.LState) int {
|
||||||
L.Push(lua.LNumber(exitcode))
|
L.Push(lua.LNumber(exitcode))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// cwd()
|
// cwd()
|
||||||
// Returns the current directory of the shell
|
// Returns the current directory of the shell
|
||||||
func hlcwd(L *lua.LState) int {
|
func hlcwd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
L.Push(lua.LString(cwd))
|
return c.PushingNext1(t.Runtime, rt.StringValue(cwd)), nil
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read(prompt) -> input?
|
// read(prompt) -> input?
|
||||||
// Read input from the user, using Hilbish's line editor/input reader.
|
// Read input from the user, using Hilbish's line editor/input reader.
|
||||||
// This is a separate instance from the one Hilbish actually uses.
|
// This is a separate instance from the one Hilbish actually uses.
|
||||||
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
// --- @param prompt string
|
// --- @param prompt string
|
||||||
func hlread(L *lua.LState) int {
|
func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
luaprompt := L.CheckString(1)
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
luaprompt, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
lualr := newLineReader("", true)
|
lualr := newLineReader("", true)
|
||||||
lualr.SetPrompt(luaprompt)
|
lualr.SetPrompt(luaprompt)
|
||||||
|
|
||||||
input, err := lualr.Read()
|
input, err := lualr.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
L.Push(lua.LNil)
|
return c.Next(), nil
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
L.Push(lua.LString(input))
|
return c.PushingNext1(t.Runtime, rt.StringValue(input)), nil
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
prompt(str)
|
prompt(str)
|
||||||
|
|
Loading…
Reference in New Issue