-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to embed function like require #41
Comments
You probably want something like this:
I'm not sure if it's a bug that Run does not always run in the global context or not... |
And here is
|
I've created a package named motto to provide a Nodejs like module environment, hope it helpful. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For multiple script files, a require function will be nice, but I have tried and failed.
func require(fn otto.FunctionCall) otto.Value {
file := fn.Argument(0).String()
fmt.Printf("require file:%s\n", file)
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err)
panic(err)
}
}
engine := otto.New()
engine.Set("require", require)
The text was updated successfully, but these errors were encountered: