On Thu, 2007-08-23 at 19:57 +0000, Mark Carter wrote:
> It's also why I'm trying to convince people to stop using C++ - C is
> just easier to interface with.
I find it way easier to wrap over C than C++, but with the cost of
implementing stuff in C just to benefit wrapping, it's like the tail
trying to wag the dog.
C++, if done right, offers enormous programming leverage:
- more readable code
- more maintainable code
- get more done in much less lines
- easy to extend
- eliminates a lot of menial and 'yak shaving' boilerplating
- create very satisfying and intuitive abstractions
But there's the wrapping problem - and admittedly C++ is a hell of a lot
harder to wrap than C.
There are two solutions:
1. Throw the header files at SWIG. By default, SWIG creates a plain-C
wrapper that in many cases Just Works (TM). It's not hard to dress
up this layer within the scripting language, eg neat classes
done as Pyrex extension classes for the Python wrapper. Or in FICL,
do thin primitives over the top of the plain-C wrapper, then
write some nice Forth words to get the desired abstraction.
or
2. Hand-code a C wrapper on top. Pass all object instances in/out as
opaque void pointers. Write attribute getter and setter funcs and
method dispatchers.
Example:
class Fred {
Fred();
~Fred();
int foo;
char *bar(float f);
}
wraps in C as:
extern "C" {
void *Fred_new() {
return (void *)(new Fred());
}
void Fred_del(void *pFred) {
((Fred *)pFred)->~Fred();
}
int Fred_get_foo(void *pFred) {
return ((Fred *)pFred)->foo;
}
void Fred_set_foo(void *pFred, int foo) {
((Fred *)pFred)->foo = foo;
}
char *Fred_bar(void *pFred, float f) {
return ((Fred *)pFred)->bar(f);
}
}
Cheers
David
_______________________________________________
Cinelerra mailing list
[email protected]
https://init.linpro.no/mailman/skolelinux.no/listinfo/cinelerra