refactor: use lua.Check<Type> where possible (resolves #40)

pull/46/head
sammy 2021-05-01 13:42:15 -04:00
parent d2a44c70c0
commit e580112e1b
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
3 changed files with 10 additions and 10 deletions

View File

@ -29,8 +29,8 @@ func (c *Commander) Loader(L *lua.LState) int {
}
func (c *Commander) register(L *lua.LState) int {
cmdName := L.ToString(1)
cmd := L.ToFunction(2)
cmdName := L.CheckString(1)
cmd := L.CheckFunction(2)
c.Events.Emit("commandRegister", cmdName, cmd)

View File

@ -27,7 +27,7 @@ var exports = map[string]lua.LGFunction{
}
func cd(L *lua.LState) int {
path := L.ToString(1)
path := L.CheckString(1)
err := os.Chdir(strings.TrimSpace(path))
if err != nil {
@ -41,7 +41,7 @@ func cd(L *lua.LState) int {
}
func mkdir(L *lua.LState) int {
dirname := L.ToString(1)
dirname := L.CheckString(1)
// TODO: handle error here
os.Mkdir(strings.TrimSpace(dirname), 0744)
@ -50,7 +50,7 @@ func mkdir(L *lua.LState) int {
}
func stat(L *lua.LState) int {
path := L.ToString(1)
path := L.CheckString(1)
// TODO: handle error here
pathinfo, _ := os.Stat(path)

10
lua.go
View File

@ -81,20 +81,20 @@ func LuaInit(confpath string) {
}
func hshprompt(L *lua.LState) int {
prompt = L.ToString(1)
prompt = L.CheckString(1)
return 0
}
func hshmlprompt(L *lua.LState) int {
multilinePrompt = L.ToString(1)
multilinePrompt = L.CheckString(1)
return 0
}
func hshalias(L *lua.LState) int {
alias := L.ToString(1)
source := L.ToString(2)
alias := L.CheckString(1)
source := L.CheckString(2)
aliases[alias] = source
@ -102,7 +102,7 @@ func hshalias(L *lua.LState) int {
}
func hshappendPath(L *lua.LState) int {
path := L.ToString(1)
path := L.CheckString(1)
os.Setenv("PATH", os.Getenv("PATH") + ":" + path)