examples: show how to call a simple v module from python (#13105)

This commit is contained in:
Saptak Bhoumik 2022-01-09 23:23:36 +05:30 committed by GitHub
parent 535317eba3
commit 5e85d4cb39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,5 @@
A simple example to show how to call a function written in v from python
Step 1: Compile the v code to a shared library using ``v -shared -prod test.v``
Step 2: Run the python file using ``python3 test.py``

View file

@ -0,0 +1,4 @@
from ctypes import *
so_file="./test.so"
my_functions = CDLL(so_file)
print(my_functions.square(10))

View file

@ -0,0 +1,6 @@
module test
[export: 'square']
fn square(i int) int {
return i * i
}