forked from katallaxie/v8go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95fe190
commit 0c733ec
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
v8 "github.com/zeiss/v8go" | ||
) | ||
|
||
func main() { | ||
ctx := v8.NewContext() // creates a new V8 context with a new Isolate aka VM | ||
ctx.RunScript("const add = (a, b) => a + b", "math.js") // executes a script on the global context | ||
ctx.RunScript("const result = add(3, 4)", "main.js") // any functions previously added to the context can be called | ||
val, _ := ctx.RunScript("result", "value.js") // return a value in JavaScript back to Go | ||
fmt.Printf("addition result: %s", val) | ||
} |