v
v copied to clipboard
eval: Host API
Host API
create() Eval
Returns an Eval instance
Eval.add_file(filepath string)
Adds a user file to be processed with the .run() code
Eval.push_val(val Object)
Pushes a value onto the host stack
Eval.run(expression string) []Object
Execute the code and returns the possible values
Interpreter side
host_pop() voidptr
Pops a value from the host stack
Example
t.v
fn test() {
println('test() called')
}
import v.eval
mut e := eval.create()
e.push_val(i64(2))
e.push_val(f64(2.2))
e.push_val('calc')
e.add_file('./t.v')
e.run('test() println("\${host_pop()}: \${i64(host_pop())+i64(host_pop())}")')!
test() called
calc: 4
This looks way too RPN-ish!
Good work. It just needs some tests to prevent/detect regressions.
Good work. It just needs some tests to prevent/detect regressions.
Done.