Skip to content

Commit

Permalink
Add function mkdirAll
Browse files Browse the repository at this point in the history
  • Loading branch information
mliezun committed Sep 6, 2021
1 parent f5b7aca commit 1fe26cf
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions internal/grotskyGlobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,27 @@ func defineIo(e *env, p IPrinter) {
return grotskyBool(true), nil
}

var mkdirAll nativeFn
mkdirAll.callFn = func(arguments []interface{}) (interface{}, error) {
// exec.mx.Unlock()
// defer exec.mx.Lock()
if len(arguments) != 2 {
return nil, errInvalidNumberArguments
}
path, ok := arguments[0].(grotskyString)
if !ok {
return nil, errExpectedString
}
perm, ok := arguments[0].(grotskyNumber)
if !ok {
return nil, errExpectedNumber
}
if err := os.MkdirAll(string(path), fs.FileMode(perm)); err != nil {
return nil, err
}
return nil, nil
}

var listDir nativeFn
listDir.callFn = func(arguments []interface{}) (interface{}, error) {
// exec.mx.Unlock()
Expand Down Expand Up @@ -274,10 +295,12 @@ func defineIo(e *env, p IPrinter) {

e.define("io", &nativeObj{
methods: map[string]*nativeFn{
"println": &println,
"readFile": &readFile,
"writeFile": &writeFile,
"listDir": &listDir,
"println": &println,
"readFile": &readFile,
"writeFile": &writeFile,
"listDir": &listDir,
"fileExists": &fileExists,
"mkdirAll": &mkdirAll,
},
})
}
Expand Down

0 comments on commit 1fe26cf

Please sign in to comment.