This is a C++ library to be used with COMMON-LISP such as boost.python, PYBIND11, ...
- CLCXX is installed
Clone into home/common-lisp directory. Then asdf:test-system "cxx"
- Fundamental types
- Pointers
- Classes can add public members and functions
- POD
- functions, std::function and lambda
#include <string>
#include "clcxx/clcxx.hpp"
std::string greet() { return "Hello, World"; }
int Int(int x) { return x + 100; }
float Float(float y) { return y + 100.34; }
auto gr(std::complex<float> x) { return x; }
std::string hi(char* s) { return std::string("hi, " + std::string(s)); }
void ref_int(int& x) { x += 30; }
void ref_class(xx& x) { x.y = 1000000; }
class xx {
public:
xx(int xx, int yy) : y(yy), x(xx) {}
std::string greet() { return "Hello, World"; }
int y;
int x;
};
CLCXX_PACKAGE TEST(clcxx::Package& pack) {
pack.defun("hi", &hi);
pack.defun("test-int", &Int);
pack.defun("greet", &greet);
pack.defun("test-float", &Float);
pack.defun("test-complex", &gr);
pack.defun("ref-int", &ref_int);
pack.defun("ref-class", &ref_class);
pack.defclass<xx, false>("xx")
.member("y", &xx::y)
.defmethod("foo", &xx::greet)
.constructor<int, int>();
}
compiled as shared lib. libtest
in lisp
(defpackage cxx/test
(:use :cl
))
(in-package :cxx/test)
(pushnew (merge-pathnames #p"ros/lisp-demo/lib/" (user-homedir-pathname))
cffi:*foreign-library-directories*
:test #'equal)
(cffi:define-foreign-library my-lib
(t (:default "libtest")))
(cffi:use-foreign-library my-lib)
(cxx:init)
(cxx:add-package "TEST" "TEST")
(test:greet)
(test:hi "Cxx")
See test files
Tested on SBCL 1.4.5.debian
- test functions
- classes
- references
- Smart pointers
- Tuple
- benchmark
Copyright (c) 2018 Islam Omar (io1131@fayoum.edu.eg)
Licensed under the MIT License.