examples: show how to call a simple v module from python (#13105)
parent
535317eba3
commit
5e85d4cb39
|
@ -176,6 +176,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
|
||||||
}
|
}
|
||||||
if testing.github_job != 'ubuntu-tcc' {
|
if testing.github_job != 'ubuntu-tcc' {
|
||||||
skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
|
skip_files << 'examples/c_interop_wkhtmltopdf.v' // needs installation of wkhtmltopdf from https://github.com/wkhtmltopdf/packaging/releases
|
||||||
|
skip_files << 'examples/call_v_from_python/test.v' // the example only makes sense to be compiled, when python is installed
|
||||||
// the ttf_test.v is not interactive, but needs X11 headers to be installed, which is done only on ubuntu-tcc for now
|
// the ttf_test.v is not interactive, but needs X11 headers to be installed, which is done only on ubuntu-tcc for now
|
||||||
skip_files << 'vlib/x/ttf/ttf_test.v'
|
skip_files << 'vlib/x/ttf/ttf_test.v'
|
||||||
skip_files << 'vlib/vweb/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h
|
skip_files << 'vlib/vweb/vweb_app_test.v' // imports the `sqlite` module, which in turn includes sqlite3.h
|
||||||
|
@ -456,7 +457,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c := os.read_file(f) or { panic(err) }
|
c := os.read_file(f) or { panic(err) }
|
||||||
maxc := if c.len > 300 { 300 } else { c.len }
|
maxc := if c.len > 500 { 500 } else { c.len }
|
||||||
start := c[0..maxc]
|
start := c[0..maxc]
|
||||||
if start.contains('module ') && !start.contains('module main') {
|
if start.contains('module ') && !start.contains('module main') {
|
||||||
skipped_f := f.replace(os.join_path_single(parent_dir, ''), '')
|
skipped_f := f.replace(os.join_path_single(parent_dir, ''), '')
|
||||||
|
|
|
@ -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``
|
|
@ -0,0 +1,4 @@
|
||||||
|
from ctypes import *
|
||||||
|
so_file="./test.so"
|
||||||
|
my_functions = CDLL(so_file)
|
||||||
|
print(my_functions.square(10))
|
|
@ -0,0 +1,6 @@
|
||||||
|
module test
|
||||||
|
|
||||||
|
[export: 'square']
|
||||||
|
fn square(i int) int {
|
||||||
|
return i * i
|
||||||
|
}
|
Loading…
Reference in New Issue