-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.go
52 lines (42 loc) · 1.3 KB
/
script.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package engine
// declare functionality for interpreted input scripts
import "github.com/mumax/3/script"
// holds the script state (variables etc)
var World = script.NewWorld()
// Add a function to the script world
func DeclFunc(name string, f interface{}, doc string) {
World.Func(name, f, doc)
}
// Add a constant to the script world
func DeclConst(name string, value float64, doc string) {
World.Const(name, value, doc)
}
// Add a read-only variable to the script world.
// It can be changed, but not by the user.
func DeclROnly(name string, value interface{}, doc string) {
World.ROnly(name, value, doc)
GUI.Add(name, value)
}
// Add a (pointer to) variable to the script world
func DeclVar(name string, value interface{}, doc string) {
World.Var(name, value, doc)
GUI.Add(name, value)
}
// Add an LValue to the script world.
// Assign to LValue invokes SetValue()
func DeclLValue(name string, value script.LValue, doc string) {
World.LValue(name, value, doc)
GUI.Add(name, value)
}
// evaluate code, exit on error (behavior for input files)
func EvalFile(code *script.BlockStmt) {
for i := range code.Children {
formatted := rmln(script.Format(code.Node[i]))
LogInput(formatted)
code.Children[i].Eval()
}
}
// evaluate code, report error (behaviour for GUI)
//func EvalGUI(code*script.BlockStmt){
//
//}