mirror of https://github.com/Hilbis/Hilbish
"feat: add lua libs for filesystem access and custom commands - written in go"
parent
4456d7593b
commit
f910c9dea4
|
@ -0,0 +1,38 @@
|
|||
package commander
|
||||
|
||||
import (
|
||||
"github.com/chuckpreslar/emission"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
type Commander struct{
|
||||
Events *emission.Emitter
|
||||
}
|
||||
|
||||
func New() Commander {
|
||||
return Commander{
|
||||
Events: emission.NewEmitter(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Commander) Loader(L *lua.LState) int {
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"register": c.register,
|
||||
}
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
L.SetField(mod, "__commands", L.NewTable())
|
||||
|
||||
L.Push(mod)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func (c *Commander) register(L *lua.LState) int {
|
||||
cmdName := L.ToString(1)
|
||||
cmd := L.ToFunction(2)
|
||||
|
||||
c.Events.Emit("commandRegister", cmdName, cmd)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"cd": cd,
|
||||
}
|
||||
|
||||
func cd(L *lua.LState) int {
|
||||
path := L.ToString(1)
|
||||
|
||||
os.Chdir(path)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue