Skip to content

Commit 571fcc3

Browse files
committed
fix: remove sh runner dep from fs
1 parent 0b0821f commit 571fcc3

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed

golibs/fs/fs.go

+24-37
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,25 @@ import (
1919
rt "github.com/arnodel/golua/runtime"
2020
"github.com/arnodel/golua/lib/packagelib"
2121
"github.com/arnodel/golua/lib/iolib"
22-
"mvdan.cc/sh/v3/interp"
2322
)
2423

25-
type fs struct{
26-
runner *interp.Runner
27-
Loader packagelib.Loader
24+
var Loader = packagelib.Loader{
25+
Load: loaderFunc,
26+
Name: "fs",
2827
}
2928

30-
func New(runner *interp.Runner) *fs {
31-
f := &fs{
32-
runner: runner,
33-
}
34-
f.Loader = packagelib.Loader{
35-
Load: f.loaderFunc,
36-
Name: "fs",
37-
}
38-
39-
return f
40-
}
41-
42-
func (f *fs) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
29+
func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
4330
exports := map[string]util.LuaExport{
44-
"cd": util.LuaExport{f.fcd, 1, false},
45-
"mkdir": util.LuaExport{f.fmkdir, 2, false},
46-
"stat": util.LuaExport{f.fstat, 1, false},
47-
"readdir": util.LuaExport{f.freaddir, 1, false},
48-
"abs": util.LuaExport{f.fabs, 1, false},
49-
"basename": util.LuaExport{f.fbasename, 1, false},
50-
"dir": util.LuaExport{f.fdir, 1, false},
51-
"glob": util.LuaExport{f.fglob, 1, false},
52-
"join": util.LuaExport{f.fjoin, 0, true},
53-
"pipe": util.LuaExport{f.fpipe, 0, false},
31+
"cd": util.LuaExport{fcd, 1, false},
32+
"mkdir": util.LuaExport{fmkdir, 2, false},
33+
"stat": util.LuaExport{fstat, 1, false},
34+
"readdir": util.LuaExport{freaddir, 1, false},
35+
"abs": util.LuaExport{fabs, 1, false},
36+
"basename": util.LuaExport{fbasename, 1, false},
37+
"dir": util.LuaExport{fdir, 1, false},
38+
"glob": util.LuaExport{fglob, 1, false},
39+
"join": util.LuaExport{fjoin, 0, true},
40+
"pipe": util.LuaExport{fpipe, 0, false},
5441
}
5542
mod := rt.NewTable()
5643
util.SetExports(rtm, mod, exports)
@@ -65,7 +52,7 @@ func (f *fs) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
6552
// This can be used to resolve short paths like `..` to `/home/user`.
6653
// #param path string
6754
// #returns string
68-
func (f *fs) fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
55+
func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
6956
path, err := c.StringArg(0)
7057
if err != nil {
7158
return nil, err
@@ -85,7 +72,7 @@ func (f *fs) fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
8572
// `.` will be returned.
8673
// #param path string Path to get the base name of.
8774
// #returns string
88-
func (f *fs) fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
75+
func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
8976
if err := c.Check1Arg(); err != nil {
9077
return nil, err
9178
}
@@ -100,7 +87,7 @@ func (f *fs) fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
10087
// cd(dir)
10188
// Changes Hilbish's directory to `dir`.
10289
// #param dir string Path to change directory to.
103-
func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
90+
func fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
10491
if err := c.Check1Arg(); err != nil {
10592
return nil, err
10693
}
@@ -123,7 +110,7 @@ func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
123110
// `~/Documents/doc.txt` then this function will return `~/Documents`.
124111
// #param path string Path to get the directory for.
125112
// #returns string
126-
func (f *fs) fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
113+
func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
127114
if err := c.Check1Arg(); err != nil {
128115
return nil, err
129116
}
@@ -154,7 +141,7 @@ print(matches)
154141
-- -> {'init.lua', 'code.lua'}
155142
#example
156143
*/
157-
func (f *fs) fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
144+
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
158145
if err := c.Check1Arg(); err != nil {
159146
return nil, err
160147
}
@@ -188,7 +175,7 @@ print(fs.join(hilbish.userDir.config, 'hilbish'))
188175
-- -> '/home/user/.config/hilbish' on Linux
189176
#example
190177
*/
191-
func (f *fs) fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
178+
func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
192179
strs := make([]string, len(c.Etc()))
193180
for i, v := range c.Etc() {
194181
if v.Type() != rt.StringType {
@@ -215,7 +202,7 @@ func (f *fs) fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
215202
fs.mkdir('./foo/bar', true)
216203
#example
217204
*/
218-
func (f *fs) fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
205+
func fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
219206
if err := c.CheckNArgs(2); err != nil {
220207
return nil, err
221208
}
@@ -246,7 +233,7 @@ func (f *fs) fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
246233
// The type returned is a Lua file, same as returned from `io` functions.
247234
// #returns File
248235
// #returns File
249-
func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
236+
func fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
250237
rf, wf, err := os.Pipe()
251238
if err != nil {
252239
return nil, err
@@ -261,7 +248,7 @@ func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
261248
// Returns a list of all files and directories in the provided path.
262249
// #param dir string
263250
// #returns table
264-
func (f *fs) freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
251+
func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
265252
if err := c.Check1Arg(); err != nil {
266253
return nil, err
267254
}
@@ -309,7 +296,7 @@ Would print the following:
309296
]]--
310297
#example
311298
*/
312-
func (f *fs) fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
299+
func fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
313300
if err := c.Check1Arg(); err != nil {
314301
return nil, err
315302
}

lua.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ func luaInit() {
3030
util.DoString(l, "hilbish = require 'hilbish'")
3131

3232
// Add fs and terminal module module to Lua
33-
f := fs.New(runner)
34-
lib.LoadLibs(l, f.Loader)
33+
lib.LoadLibs(l, fs.Loader)
3534
lib.LoadLibs(l, terminal.Loader)
3635

3736
cmds = commander.New(l)

0 commit comments

Comments
 (0)