Comments (6)
I think there are other ways to solve this issue. For example, first run in the script with all the functions, then can run a script with just the wanted function. Could also look into using modules.
from anko.
I'm not sure I understand. I can run a whole script, but how would I then run the wanted function only?
Modules look basically like classes to me. Unless I can interact with them from outside Anko, I'm not sure that modules would help me.
from anko.
Split the script into two part. First run in the part with all the functions. Then run a script with just the function you want to call.
from anko.
Are the variables shared between the two parts?
Basically I have a function (or in this case script) that gets called in regular intervals and with each execution of the script, all variables are reset. My thought was that if I just call a function and not the whole script, I can have variables outside of that function that don't reset between calls.
from anko.
Any script can be run in any env, the env is where the script runs. Can keep running scripts as long as you want in the same env.
package main
import (
"fmt"
"log"
"github.com/mattn/anko/env"
"github.com/mattn/anko/vm"
)
func main() {
e := env.NewEnv()
err := e.Define("println", fmt.Println)
if err != nil {
log.Fatalf("Define error: %v\n", err)
}
script := `
a = 1
`
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
script = `
a = a + 1
println(a)
`
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
}
Output:
2
3
4
from anko.
Okay, that solves this issue. Thanks!
from anko.
Related Issues (20)
- Master branch doesn't follow releases HOT 14
- dangerous packages import HOT 10
- goroutine crash silently HOT 14
- Cannot use vm in multiple goroutines HOT 3
- Method overriding in custom structs HOT 11
- unknown field 'Structs' in struct literal of type ast.TypeStruct HOT 9
- Anon calls doesn't report the expr position HOT 4
- Could I throw an error in script for anko to catch and return it to caller HOT 7
- Crashed by invalid input
- question: extending slices and getting data out HOT 1
- Can a function be created
- when "new" and "make" structure, field will not be zero value.
- Playground (http://play-anko.appspot.com/) returns 500 HOT 5
- undefined symbol 'Atoi' HOT 1
- Methods definition
- How can I get the result HOT 5
- How to check if a channel is closed? HOT 1
- Data race when running scripts concurrently HOT 3
- Mathematical expression computation bug HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anko.