2

in my c + + application i would like to expose the same API to different scripting languages. Is there a library that allows me to expose it once and that will expose to v8, luajit, cpython or mono?

2

SWIG to quote the web page:

The following scripting languages were supported in the final SWIG 1.1 release:

  • Tcl 8.0 and newer versions.
  • Python 1.5 and newer.
  • Perl 5.003 or newer.
  • Guile 1.3.4 and newer.

The following languages are also supported in swig-1.3.6 onwards.

  • Java JDK 1.1 and newer.
  • Ruby.
  • Mzscheme.
  • PHP support was added in swig-1.3.11.
  • Objective Caml (Ocaml) and Pike support was added in swig-1.3.14.
  • Support for C# and the Chicken scheme compiler was added in swig-1.3.18.
  • Support for Allegro CL and Modula-3 was added in swig-1.3.22.
  • Support for Lua, CLISP and Common Lisp with UFFI was added in swig-1.3.26.
  • Support for Common Lisp with CFFI was added in swig-1.3.28.
  • Support for R was added in swig-1.3.30.
  • Support for Octave was added in swig-1.3.35.
  • Support for the Go language was added in swig-2.0.1.
  • Support for D was added in swig-2.0.2.
  • Support for Javascript was added in swig-3.0.1.
  • There is also a SWIG Eiffel module - SWIGEiffel.

Which should hit most of your requirements.

SWIG is Free software, both Libre and FOSS, and distributed under the GPL license but specifically notes:

When SWIG is used as it is distributed by the SWIG developers, its output is not governed by SWIG's license (including the GPL). SWIG's output contains code from three sources:

  • code generated by SWIG, which is not governed by copyright;
  • code copied from the SWIG library which is permissively licensed to be redistributed without restriction;
  • code derived from the user's input, which may be governed by the license of the code supplied by the user.
2
  • SWIG is mostly for libraries. Can it be used to add scripting interface to a running program? In other words, can a c++ program expose its objects to a scripting language through SWIG? – Rado Feb 8 '15 at 1:32
  • When you think about it everything outside of main in a C/C++ program is a set of local library calls, with .o files just not necessarily stored in a .lib or .dll file, if your program is all in main then you should be fixing that rather than generating APIs. On the other hand a DLL and an EXE only differ in having a main and hopefully on the level of activity when things are not calling it. – Steve Barnes Feb 8 '15 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.