This is a C++ library to be used with COMMON-LISP cl-cxx such as boost.python, PYBIND11, ...
Forked from julia language libcxxwrap
- function prototype must be
CLCXX_PACKAGE <name>(clcxx::Package &pack)
. - basic example
#include <clcxx/clcxx.hpp>
int Int(int x) { return x + 100; }
CLCXX_PACKAGE Test(clcxx::Package &pack) {
pack.defun("hi", F_PTR(&Hi));}
compiled into a shared lib.
- add class with default initializer
pack.defclass<A, true>("A");
- add class without default initializer
pack.defclass<A, false>("A");
- basic class example:
#include <clcxx/clcxx.hpp>
class A {
public:
A(int A, int yy) : y(yy), x(A) {}
std::string Greet() { return "Hello, World"; }
float operator()(void) { return 0.0; }
int y;
int x;
template <typename T>
long int add(T) {
return 1;
}
long int one() const { return 1; }
};
pack.defclass<A, false>("A")
.defmethod("class-greet", F_PTR(&A::Greet))
.defmethod("class-operator", F_PTR(&A::operator()))
.defmethod("class-lambda", F_PTR([](A x) { return x.x; }))
.constructor<int, int>()
.member("y", &A::y)
.defmethod("add", F_PTR(&A::add<int>))
.defmethod("one", F_PTR(&A::one));
- add overloaded function by creating new lambda
.defmethod("m.resize", F_PTR([](Eigen::MatrixXd& m, Eigen::Index i, Eigen::Index j) { return m.resize(i, j); }))
C++
functions/lambda/member_function are converted into an overload functionDoApply
and it's pointer is safed and passed to lispcffi
.C++
fundamental/array/pod_struct
are converted as they are (copied) to lispcffi
types.C++
&
are converted to raw pointervoid *
with no allocation.C++
*
are passed asvoid *
withstatic_cast
.C++
non-PODclass
are passed asvoid *
after allocation withstd::pmr::memory_resource
.C++
std::strings
are converted toconst char *
after allocation withstd::pmr::memory_resource
.C++
std::complex
are copied to lisp.
- C++ function, lambda and c functions auto type conversion.
- Classes
- resolve const type template
- reference types
- support tuples,vectors,...
mkdir build
cd build
cmake ..
make
make install