Skip to content

Commit b01e140

Browse files
committed
add goos.mkdir_all
1 parent 2972024 commit b01e140

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

goos/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ print(hostname)
2121
-- get_pagesize
2222
local page_size = goos.get_pagesize()
2323
if not(page_size > 0) then error("bad pagesize") end
24-
```
2524

25+
-- mkdir_all
26+
goos.mkdir_all("./test/test_dir/test_dir/all")
27+
local stat, err = goos.stat("./test/test_dir/test_dir/all")
28+
if err then error(err) end
29+
```

goos/api.go

+10
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ func Getpagesize(L *lua.LState) int {
4242
L.Push(lua.LNumber(os.Getpagesize()))
4343
return 1
4444
}
45+
46+
// MkdirAll lua goos.mkdir_all() return err
47+
func MkdirAll(L *lua.LState) int {
48+
err := os.MkdirAll(L.CheckString(1), 0755)
49+
if err != nil {
50+
L.Push(lua.LString(err.Error()))
51+
return 1
52+
}
53+
return 0
54+
}

goos/example_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,22 @@ print(page_size > 0)
6363
// Output:
6464
// true
6565
}
66+
67+
// goos.mkdir_all()
68+
func ExampleMkdirAll() {
69+
state := lua.NewState()
70+
Preload(state)
71+
inspect.Preload(state)
72+
source := `
73+
local goos = require("goos")
74+
local err = goos.mkdir_all("./test/test_dir_example/test_dir")
75+
if err then error(err) end
76+
local _, err = goos.stat("./test/test_dir_example/test_dir")
77+
print(err == nil)
78+
`
79+
if err := state.DoString(source); err != nil {
80+
log.Fatal(err.Error())
81+
}
82+
// Output:
83+
// true
84+
}

goos/loader.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ var api = map[string]lua.LGFunction{
2424
"stat": Stat,
2525
"hostname": Hostname,
2626
"get_pagesize": Getpagesize,
27+
"mkdir_all": MkdirAll,
2728
}

0 commit comments

Comments
 (0)