v icon indicating copy to clipboard operation
v copied to clipboard

eval: Host API

Open felipensp opened this issue 2 years ago • 3 comments

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

felipensp avatar Feb 27 '23 15:02 felipensp

This looks way too RPN-ish!

JalonSolov avatar Feb 27 '23 16:02 JalonSolov

Good work. It just needs some tests to prevent/detect regressions.

spytheman avatar Feb 28 '23 15:02 spytheman

Good work. It just needs some tests to prevent/detect regressions.

Done.

felipensp avatar Feb 28 '23 17:02 felipensp