KPN/python/kpn_python.cpp
2026-05-12 21:23:33 +02:00

40 lines
1.6 KiB
C++

#define KPN_BUILD_PYTHON
#include <kpn/python/auto_bind.hpp>
#include <iostream>
namespace nb = nanobind;
using namespace kpn;
using namespace kpn::python;
// ── Demo node functions (hello-pipeline) ──────────────────────────────────────
static int produce() { return 42; }
static int double_it(int x) { return x * 2; }
static void print_it(int x) { std::cout << "result: " << x << '\n'; }
// ── Registry ──────────────────────────────────────────────────────────────────
// Variant type is auto-deduced as std::variant<int> from the port types above.
using DemoNodes = NodeRegistry<
Entry<produce, "produce">,
Entry<double_it, "double_it">,
Entry<print_it, "print_it">
>;
// ── Module ────────────────────────────────────────────────────────────────────
NB_MODULE(kpn_python, m) {
m.doc() = "KPN++ Python bindings — Kahn Process Network library";
// Registers: Network, INode, ProduceNode, DoubleItNode, PrintItNode,
// make_produce(), make_double_it(), make_print_it()
bind_network<DemoNodes>(m);
// Also expose raw functions for direct testing (no network needed):
// kpn.produce() → 42
// kpn.double_it(5) → 10
// kpn.print_it(84) → prints "result: 84", returns None
bind_debug<DemoNodes>(m);
}