Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
haifenghuang committed May 15, 2018
1 parent 9ab0dc7 commit 8302b63
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2109,33 +2109,33 @@ register `go` language functions or types into monkey language.
Below is an example of `main.go`(extracted):

```swift
// Because in monkey we already have built in module `fmt`, here we use `gfmt` for package name.
eval.RegisterFunctions("gfmt", []interface{}{
fmt.Errorf,
fmt.Println, fmt.Print, fmt.Printf,
fmt.Fprint, fmt.Fprint, fmt.Fprintln, fmt.Fscan, fmt.Fscanf, fmt.Fscanln,
fmt.Scan, fmt.Scanf, fmt.Scanln,
fmt.Sscan, fmt.Sscanf, fmt.Sscanln,
fmt.Sprint, fmt.Sprintf, fmt.Sprintln,
})

eval.RegisterFunctions("io/ioutil", []interface{}{
ioutil.WriteFile, ioutil.ReadFile, ioutil.TempDir, ioutil.TempFile,
ioutil.ReadAll, ioutil.ReadDir, ioutil.NopCloser,
})

eval.Eval(program, scope)
// Because in monkey we already have built in module `fmt`, here we use `gfmt` for package name.
eval.RegisterFunctions("gfmt", []interface{}{
fmt.Errorf,
fmt.Println, fmt.Print, fmt.Printf,
fmt.Fprint, fmt.Fprint, fmt.Fprintln, fmt.Fscan, fmt.Fscanf, fmt.Fscanln,
fmt.Scan, fmt.Scanf, fmt.Scanln,
fmt.Sscan, fmt.Sscanf, fmt.Sscanln,
fmt.Sprint, fmt.Sprintf, fmt.Sprintln,
})

eval.RegisterFunctions("io/ioutil", []interface{}{
ioutil.WriteFile, ioutil.ReadFile, ioutil.TempDir, ioutil.TempFile,
ioutil.ReadAll, ioutil.ReadDir, ioutil.NopCloser,
})

eval.Eval(program, scope)
```
Now, in your monkey file, you could use it like below:

```swift
gfmt.Printf("Hello %s!\n", "go function");
gfmt.Printf("Hello %s!\n", "go function");

//Note Here: we use 'io_ioutil', not 'io/ioutil'.
let files, err = io_ioutil.ReadDir(".")
if err != nil {
gfmt.Println(err)
}
//Note Here: we use 'io_ioutil', not 'io/ioutil'.
let files, err = io_ioutil.ReadDir(".")
if err != nil {
gfmt.Println(err)
}
```

For more detailed examples, please see `goObj.my`.
Expand Down
44 changes: 22 additions & 22 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2080,33 +2080,33 @@ Monkey提供了引入`go`语言模块的功能(实验性)。
下面是`main.go`中的例子(节选):

```swift
// 因为Monkey语言中,已经提供了内置模块`fmt`, 因此这里我们使用`gfmt`作为名字。
eval.RegisterFunctions("gfmt", []interface{}{
fmt.Errorf,
fmt.Println, fmt.Print, fmt.Printf,
fmt.Fprint, fmt.Fprint, fmt.Fprintln, fmt.Fscan, fmt.Fscanf, fmt.Fscanln,
fmt.Scan, fmt.Scanf, fmt.Scanln,
fmt.Sscan, fmt.Sscanf, fmt.Sscanln,
fmt.Sprint, fmt.Sprintf, fmt.Sprintln,
})

eval.RegisterFunctions("io/ioutil", []interface{}{
ioutil.WriteFile, ioutil.ReadFile, ioutil.TempDir, ioutil.TempFile,
ioutil.ReadAll, ioutil.ReadDir, ioutil.NopCloser,
})

eval.Eval(program, scope)
// 因为Monkey语言中,已经提供了内置模块`fmt`, 因此这里我们使用`gfmt`作为名字。
eval.RegisterFunctions("gfmt", []interface{}{
fmt.Errorf,
fmt.Println, fmt.Print, fmt.Printf,
fmt.Fprint, fmt.Fprint, fmt.Fprintln, fmt.Fscan, fmt.Fscanf, fmt.Fscanln,
fmt.Scan, fmt.Scanf, fmt.Scanln,
fmt.Sscan, fmt.Sscanf, fmt.Sscanln,
fmt.Sprint, fmt.Sprintf, fmt.Sprintln,
})

eval.RegisterFunctions("io/ioutil", []interface{}{
ioutil.WriteFile, ioutil.ReadFile, ioutil.TempDir, ioutil.TempFile,
ioutil.ReadAll, ioutil.ReadDir, ioutil.NopCloser,
})

eval.Eval(program, scope)
```
接下来, 在你的Monkey文件中,像下面这样使用导入的方法:

```swift
gfmt.Printf("Hello %s!\n", "go function");
gfmt.Printf("Hello %s!\n", "go function");

//注意: 这里需要使用'io_ioutil', 而不是'io/ioutil'。
let files, err = io_ioutil.ReadDir(".")
if err != nil {
gfmt.Println(err)
}
//注意: 这里需要使用'io_ioutil', 而不是'io/ioutil'。
let files, err = io_ioutil.ReadDir(".")
if err != nil {
gfmt.Println(err)
}
```

更详细的例子请参照`goObj.my`
Expand Down

0 comments on commit 8302b63

Please sign in to comment.