@@ -19,38 +19,25 @@ import (
19
19
rt "github.com/arnodel/golua/runtime"
20
20
"github.com/arnodel/golua/lib/packagelib"
21
21
"github.com/arnodel/golua/lib/iolib"
22
- "mvdan.cc/sh/v3/interp"
23
22
)
24
23
25
- type fs struct {
26
- runner * interp. Runner
27
- Loader packagelib. Loader
24
+ var Loader = packagelib. Loader {
25
+ Load : loaderFunc ,
26
+ Name : "fs" ,
28
27
}
29
28
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 ()) {
43
30
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 },
54
41
}
55
42
mod := rt .NewTable ()
56
43
util .SetExports (rtm , mod , exports )
@@ -65,7 +52,7 @@ func (f *fs) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
65
52
// This can be used to resolve short paths like `..` to `/home/user`.
66
53
// #param path string
67
54
// #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 ) {
69
56
path , err := c .StringArg (0 )
70
57
if err != nil {
71
58
return nil , err
@@ -85,7 +72,7 @@ func (f *fs) fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
85
72
// `.` will be returned.
86
73
// #param path string Path to get the base name of.
87
74
// #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 ) {
89
76
if err := c .Check1Arg (); err != nil {
90
77
return nil , err
91
78
}
@@ -100,7 +87,7 @@ func (f *fs) fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
100
87
// cd(dir)
101
88
// Changes Hilbish's directory to `dir`.
102
89
// #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 ) {
104
91
if err := c .Check1Arg (); err != nil {
105
92
return nil , err
106
93
}
@@ -123,7 +110,7 @@ func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
123
110
// `~/Documents/doc.txt` then this function will return `~/Documents`.
124
111
// #param path string Path to get the directory for.
125
112
// #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 ) {
127
114
if err := c .Check1Arg (); err != nil {
128
115
return nil , err
129
116
}
@@ -154,7 +141,7 @@ print(matches)
154
141
-- -> {'init.lua', 'code.lua'}
155
142
#example
156
143
*/
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 ) {
158
145
if err := c .Check1Arg (); err != nil {
159
146
return nil , err
160
147
}
@@ -188,7 +175,7 @@ print(fs.join(hilbish.userDir.config, 'hilbish'))
188
175
-- -> '/home/user/.config/hilbish' on Linux
189
176
#example
190
177
*/
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 ) {
192
179
strs := make ([]string , len (c .Etc ()))
193
180
for i , v := range c .Etc () {
194
181
if v .Type () != rt .StringType {
@@ -215,7 +202,7 @@ func (f *fs) fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
215
202
fs.mkdir('./foo/bar', true)
216
203
#example
217
204
*/
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 ) {
219
206
if err := c .CheckNArgs (2 ); err != nil {
220
207
return nil , err
221
208
}
@@ -246,7 +233,7 @@ func (f *fs) fmkdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
246
233
// The type returned is a Lua file, same as returned from `io` functions.
247
234
// #returns File
248
235
// #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 ) {
250
237
rf , wf , err := os .Pipe ()
251
238
if err != nil {
252
239
return nil , err
@@ -261,7 +248,7 @@ func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
261
248
// Returns a list of all files and directories in the provided path.
262
249
// #param dir string
263
250
// #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 ) {
265
252
if err := c .Check1Arg (); err != nil {
266
253
return nil , err
267
254
}
@@ -309,7 +296,7 @@ Would print the following:
309
296
]]--
310
297
#example
311
298
*/
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 ) {
313
300
if err := c .Check1Arg (); err != nil {
314
301
return nil , err
315
302
}
0 commit comments