|Pliant talk forum
Discussion: accessing C++ objects from Pliant
I have read Pliant->C tutorial. What about Pliant->C++ ?
|Message posted by maybe Boris on 2003/05/29 08:38:20
|I need a library to produce sounds from pliant, as I want to write
software that can generate midi files, and such. I found a library
written in C++ (classes and objects). How do I go about accessing
methods of C++ objects from pliant ?
|Message posted by hubert.tonneau on 2003/05/29 09:11:16
|You have two solutions.
1) Write a wrapper library in C++ that embeds all C++ calls in a C function.
2) Find how your C++ compiler generates mangled names so that you can call the
C++ functions directly from Pliant
Also the problem with C++ is trippe:
. mangled names tend to be compiler specific
. inline functions are not available outside C++
. C++ is not powerfull enough to expose it's internals to another language
In very fiew words, C is a language designed to cooperate with others (I mean
it's basically the common part of all languages), but both C++ and Pliant are
extensions that are designed to be the top level language of the application
(mainly due to the language limits on C++ side, and to the dynamic compiling
notion on Pliant side), so using two of these in a single application is not
Another way to speak is to say that C++ is a very closed language because when
you have some code written in C++, you have no way to extract informations
This is less of a problem with C where most informations (except prototypes and
types definition) are available in the DLLs, and it does not append at all with
Pliant because you can write very simple modules that will provide any required
information about the program.
It means that there are mainly only two ways to wisely write programs:
. write the program in Pliant and execute it within Pliant execution environment
where you benefit from it's dynamic compiling feature
. write a program in Pliant and use Pliant as a super powerfull preprocessor
that will turn it to what ever language you like
The main problem with the second point is that for the programs I write, the
first model is better because FullPliant is mostly self contained, so I have
not finished the environment required to work with the second model that closed
softwares and softwares that need to link many pieces of code from different
languages might prefer.
|Message posted by hubert.tonneau on 2003/05/29 09:47:36
|A third way would be to write a C++ parser for Pliant in order to let the
C++ library be compiled by Pliant, but it's not completely straight forward,
mainly because C++ is not clean syntax as Pliant is with the first word telling
you what comes next (a function, a new type), and then, the main problem is that
when doing so tools, you often fall on subtil bugs.
I mean most programs tend to use some side effects of the language rather
than be only plain simple code (see C++ portability problems among various
compilers, so imagine the extense when switching to a different underlying
compiling and execution model)
As an exemple, even the two only very simple and widely used libraries Pliant
links with (zlib and libjpeg) had to be patched and recompiled for the Win32
environment because of prototypes mistakes that don't show up in a single compiler
|Message posted by maybe Marcus on 2003/05/29 12:29:46
|I am not sure if it relates to Boris's issue, but Mujtaba, a student here
at Ryerson, has plans of implementing the bindings for the SDL sound capabilities
in Pliant. As far as I know, SDL is as close to the hardware as you can get.
He has already successfully created many bindings between Pliant and the SDL
graphical library (http://pligame.sourceforge.net)
|Message posted by reitman on 2003/06/01 22:09:37
|Thanks guys for your detailed responses. I will investigate this further...
|Message posted by mujtaba on 2003/06/09 20:25:12
|SDL provides low-level access to the dsp device, where you can
reproduce digitally sampled audio data. I think what you want instead is
an audio sequencer/player. There is a popular C library
called MikMod, I'm sure you have heard of it. It lets you play
MOD (and related) file formats. A MOD file contains a collection of
sampled sounds, and timed sequences to play these sounds to
produce a song.