mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples: enhance the call_v_from_python example, with a fn accepting 2 f64 params (#13480)
This commit is contained in:
parent
3ac4155f0c
commit
b8d656b308
@ -1,8 +1,11 @@
|
|||||||
from ctypes import *
|
from ctypes import *
|
||||||
import os
|
import math, os
|
||||||
|
|
||||||
so_file="./test.so"
|
so_file="./test.so"
|
||||||
if os.name=="nt":
|
if os.name=="nt":
|
||||||
so_file="./test.dll"
|
so_file="./test.dll"
|
||||||
my_functions = CDLL(so_file)
|
lib = CDLL(so_file)
|
||||||
print(my_functions.square(10))
|
assert lib.square(10) == 100, "Cannot validate V square()."
|
||||||
|
|
||||||
|
lib.sqrt_of_sum_of_squares.restype = c_double
|
||||||
|
assert lib.sqrt_of_sum_of_squares(c_double(1.1), c_double(2.2)) == math.sqrt(1.1*1.1 + 2.2*2.2), "Cannot validate V sqrt_of_sum_of_squares()."
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
module test
|
module test
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
[export: 'square']
|
[export: 'square']
|
||||||
fn square(i int) int {
|
fn square(i int) int {
|
||||||
return i * i
|
return i * i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[export: 'sqrt_of_sum_of_squares']
|
||||||
|
fn sqrt_of_sum_of_squares(x f64, y f64) f64 {
|
||||||
|
return math.sqrt(x * x + y * y)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user