mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 01:46:15 +01:00
Add genpybind example
This commit is contained in:
parent
0c16ab4f65
commit
1fd2e4174c
9
playground/genpybind/example.cpp
Normal file
9
playground/genpybind/example.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "example.h"
|
||||
|
||||
constexpr int Example::not_exposed;
|
||||
|
||||
int Example::calculate(int some_argument) const { return _value + some_argument; }
|
||||
|
||||
int Example::getSomething() const { return _value; }
|
||||
|
||||
void Example::setSomething(int value) { _value = value; }
|
20
playground/genpybind/example.h
Normal file
20
playground/genpybind/example.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "genpybind.h"
|
||||
|
||||
class GENPYBIND(visible) Example {
|
||||
public:
|
||||
static constexpr int GENPYBIND(hidden) not_exposed = 10;
|
||||
|
||||
/// \brief Do a complicated calculation.
|
||||
int calculate(int some_argument = 5) const;
|
||||
|
||||
GENPYBIND(getter_for(something))
|
||||
int getSomething() const;
|
||||
|
||||
GENPYBIND(setter_for(something))
|
||||
void setSomething(int value);
|
||||
|
||||
private:
|
||||
int _value = 0;
|
||||
};
|
9
playground/genpybind/example_test.py
Normal file
9
playground/genpybind/example_test.py
Normal file
@ -0,0 +1,9 @@
|
||||
import pyexample as m
|
||||
|
||||
|
||||
def test_example():
|
||||
obj = m.Example()
|
||||
obj.something = 42
|
||||
assert obj.something == 42
|
||||
assert obj.calculate() == 47 # with default argument
|
||||
assert obj.calculate(2) == 44
|
37
playground/genpybind/wscript
Normal file
37
playground/genpybind/wscript
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
def options(opt):
|
||||
opt.load('python')
|
||||
opt.load('compiler_cxx')
|
||||
opt.load('genpybind')
|
||||
|
||||
|
||||
def configure(cfg):
|
||||
cfg.load('python')
|
||||
cfg.load('compiler_cxx')
|
||||
cfg.check_python_version((2, 7))
|
||||
cfg.check_python_headers()
|
||||
cfg.load('genpybind')
|
||||
|
||||
cfg.check(compiler='cxx',
|
||||
features='cxx pyext',
|
||||
uselib_store='PYBIND11GENPYBIND_EXAMPLE',
|
||||
mandatory=True,
|
||||
header_name='pybind11/pybind11.h')
|
||||
|
||||
|
||||
def build(bld):
|
||||
bld(target='example_inc',
|
||||
export_includes='.')
|
||||
|
||||
bld.shlib(target='example',
|
||||
source='example.cpp',
|
||||
features='use',
|
||||
use='example_inc')
|
||||
|
||||
bld(target='pyexample',
|
||||
source='example.h',
|
||||
genpybind_tags='genpybind_example',
|
||||
features='use genpybind cxx cxxshlib pyext',
|
||||
use=['PYBIND11GENPYBIND_EXAMPLE', 'example'])
|
Loading…
Reference in New Issue
Block a user