GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mvenditto/v-python: Python/C API wrapper for developing modules / embedding Python in V. Experimental.

BranchesTags
Open more actions menu

Latest commit

 

History

77 Commits
77 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
helpers
helpers
 
 
samples
samples
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
Vagrantfile
Vagrantfile
 
 
_helpers.v
_helpers.v
 
 
arg.v
arg.v
 
 
arg_test.v
arg_test.v
 
 
bool.v
bool.v
 
 
bool_test.v
bool_test.v
 
 
dict.v
dict.v
 
 
dict_test.v
dict_test.v
 
 
errors.v
errors.v
 
 
errors_test.v
errors_test.v
 
 
errors_windows.c.v
errors_windows.c.v
 
 
exceptions.v
exceptions.v
 
 
exceptions_test.v
exceptions_test.v
 
 
float.v
float.v
 
 
float_test.v
float_test.v
 
 
integer.v
integer.v
 
 
integer_test.v
integer_test.v
 
 
list.v
list.v
 
 
list_test.v
list_test.v
 
 
object.v
object.v
 
 
object_test.v
object_test.v
 
 
py.v
py.v
 
 
test_all.sh
test_all.sh
 
 
test_all_limited.sh
test_all_limited.sh
 
 
tuple.v
tuple.v
 
 
tuple_test.v
tuple_test.v
 
 
v.mod
v.mod
 
 

Repository files navigation

Python/C api in v for modules development and embedding

ci badge badge2

Example structure of a Python module written in vlang (WIP)

module hello

import py
import v.util.version

[heap; py_module: 'hello']
struct HelloModuleContext { 
}

[export: 'PyInit_hello'; unsafe]
pub fn py_init_module() &C.PyObject {
	return py.init_module<HelloModuleContext>(&HelloModuleContext{})
}

[py_method; unsafe]
pub fn (mod HelloModuleContext) greetings(self &C.PyObject, ignore &C.PyObject) &C.PyObject { 
	println('This module was build with: ${version.full_v_version(true)}')
	return py.py_none()
}

/*
until it will be possible to either:
  - pass around method pointers
  - use generic anonymous function
the module struct must explicitly implement the py.Dispatcher interface.
*/
pub fn (mod HelloModuleContext) dispatch(m_name string, self &C.PyObject, args &C.PyObject) &C.PyObject{
	$for method in HelloModuleContext.methods {
		$if method.args[0].typ is C.PyObject 
		 && method.args[1].typ is C.PyObject {
			if method.name == m_name {
				return mod.$method(self, args).str
			}
		}
	}
	return py.py_none()
}
>>> import hello
>>> hello.boring()
This module was built with: V 0.2.4 105d7fc
>>>

WIP

About

Python/C API wrapper for developing modules / embedding Python in V. Experimental.

Topics

cpython-apicpython-extensionspythonpython-extensionpython-modulevlangvlang-libraryvlang-module

Resources

Readme
Activity

Stars

8 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.