v / examples / call_v_from_python / test.v
21 lines · 17 sloc · 513 bytes · a80bc2331450fc28c900097f8afafe173f161d27
Raw
1// vtest build: present_python? // the example only makes sense to be compiled, when python is installed
2module test
3
4// Note: compile this with `v -d no_backtrace -shared test.v`
5import math
6
7@[export: 'square']
8fn square(i int) int {
9 return i * i
10}
11
12@[export: 'sqrt_of_sum_of_squares']
13fn sqrt_of_sum_of_squares(x f64, y f64) f64 {
14 return math.sqrt(x * x + y * y)
15}
16
17// you do not have to use the same name in the export attribute
18@[export: 'process_v_string']
19fn work(s string) string {
20 return 'v ${s} v'
21}
22