Compare commits

...

6 Commits

Author SHA1 Message Date
sammy 3c4351a8fe fix: remove print 2021-04-09 23:14:10 -04:00
sammy 3cb8e64dc0 feat: add more require paths and change ordering 2021-04-09 23:13:28 -04:00
sammy 1868715b8a chore: merge from master 2021-04-09 20:00:53 -04:00
sammy b38585e86d chore: update .gitignore 2021-04-09 18:22:28 -04:00
sammy 3523bfa28b feat: add more paths to package.path 2021-04-09 18:22:05 -04:00
TorchedSammy 2c711de9dc feat: add mkdir and stat functions to fs module 2021-04-09 18:10:18 -04:00
3 changed files with 28 additions and 1 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
hilbish hilbish
.vim .vim
petals/

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
) )
func Loader(L *lua.LState) int { func Loader(L *lua.LState) int {
@ -22,6 +23,8 @@ func LuaErr(L *lua.LState, code int) {
var exports = map[string]lua.LGFunction{ var exports = map[string]lua.LGFunction{
"cd": cd, "cd": cd,
"mkdir": mkdir,
"stat": stat,
} }
func cd(L *lua.LState) int { func cd(L *lua.LState) int {
@ -38,3 +41,21 @@ func cd(L *lua.LState) int {
return 0 return 0
} }
func mkdir(L *lua.LState) int {
dirname := L.ToString(1)
// TODO: handle error here
os.Mkdir(strings.TrimSpace(dirname), 0744)
return 0
}
func stat(L *lua.LState) int {
path := L.ToString(1)
// TODO: handle error here
pathinfo, _ := os.Stat(path)
L.Push(luar.New(L, pathinfo))
return 1
}

7
lua.go
View File

@ -49,7 +49,12 @@ func LuaInit(confpath string) {
l.PreloadModule("bait", bait.Loader) l.PreloadModule("bait", bait.Loader)
// Add more paths that Lua can require from // Add more paths that Lua can require from
l.DoString("package.path = package.path .. ';./libs/?/init.lua;/usr/share/hilbish/libs/?/init.lua'") l.DoString(`package.path = package.path
.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
.. ';/usr/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua'
`)
err := l.DoFile("/usr/share/hilbish/preload.lua") err := l.DoFile("/usr/share/hilbish/preload.lua")
if err != nil { if err != nil {