| 1 | // vtest build: present_python? // the example only makes sense to be compiled, when python is installed |
| 2 | module test |
| 3 | |
| 4 | // Note: compile this with `v -d no_backtrace -shared test.v` |
| 5 | import math |
| 6 | |
| 7 | @[export: 'square'] |
| 8 | fn square(i int) int { |
| 9 | return i * i |
| 10 | } |
| 11 | |
| 12 | @[export: 'sqrt_of_sum_of_squares'] |
| 13 | fn 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'] |
| 19 | fn work(s string) string { |
| 20 | return 'v ${s} v' |
| 21 | } |
| 22 | |