#24 Modules in Other Languages


There is interest in importing functions from other languages so they are usable in Asymptote scripts.


For C++, this could be done by exposing some of the functionality of runtime.pl, but producing a shared library and some sort of asy "header" file. Implementing this shouldn't be too hard, but making it user friendly might be.


  • newt0311

    newt0311 - 2007-09-04

    Logged In: YES
    Originator: NO

    One pressing question: How will internal structures (i.e. pairs, arrays, other asymptote functions) be exposed to the outside code?

  • Andy Hammerlindl

    Logged In: YES
    Originator: YES

    Asymptote structures will probably be exposed basically as they are in runtime.in (which I strongly suggest you take a peek at if you haven't yet).

    For instance, pair is a C++ class defined in pair.h:

    pair z;
    real x=z.getx();
    real y=z.gety();

    Arrays are defined in array.h. Elements have to be cast to and from the item class when reading/writing the array. item is sort of like PyObject:

    item i=4.0;
    real four=get<real>(i);

    size_t size=5;
    array *a=new array(size);
    for (size_t i=0; i<size; ++i)

    real sum=0.0;
    for (size_t i=0; i<size; ++i)
    sum+=read<real>(a,i) // or: get<real>((*a)[i])

    Functions are a set of polymorphic classes derived from the abstract base class callable in callable.h. They are called by pushing arguments on the stack in left-to-right order, calling, and then popping the result:

    callable *f= <something> ;
    real result=pop<real>(Stack);

    Because of the extensive use of classes in the code, it would probably be prohibitively difficult to work with these structure using pure C. This would not prevent people from wrapping existing C libraries for use with Asymptote.

    Also, these classes have been designed just for internal use, so-to-speak. They may need some cleaning up before exposing them via this API, but that is not neccessarily a bad thing. One thing is for sure, though. When using early versions of this interface, you are going to get your hands dirty.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks