Skip to content
Common Lisp and CXX interoperation
Branch: master
Clone or download
Latest commit 990c2f0 Apr 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests Work Apr 7, 2019
.gitignore Fix .gitignore Apr 22, 2019
README.markdown Update README.markdown Apr 25, 2019
cxx-test.asd
cxx.asd several fixes Apr 15, 2019
package.lisp add .gitignore Apr 6, 2019

README.markdown

CL-CXX - Common Lisp and CXX interoperation

This is a C++ library to be used with COMMON-LISP such as boost.python, PYBIND11, ...

Prerequisites

Installation

Clone into home/common-lisp directory. Then asdf:test-system "cxx"

Supported Types

  • Fundamental types
  • Pointers
  • Classes can add public members and functions
  • POD
  • functions, std::function and lambda

example

#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")

Usage

See test files

NOTE

Tested on SBCL 1.4.5.debian

TODO

  • test functions
  • classes
  • references
  • Smart pointers
  • Tuple
  • benchmark

Copyright

Copyright (c) 2018 Islam Omar (io1131@fayoum.edu.eg)

License

Licensed under the MIT License.

You can’t perform that action at this time.