Why a C API?

My understanding is that SketchUp is written in C++. There also used to be a C++ API which has been deprecated.

What was the motivation behind ditching the C++ API and creating a C API instead?

It is so tedious and verbose to work with it… Even very simple tasks require many lines of code.
The SketchUp data structure seems to be highly object-oriented, hence C++ would seem to be a better fit. What am I missing?

it’e easier to assemble into javascript, i.e. the main ‘stated’ reason Trimble purchased the ‘engine’…

john

I thought the C++ implementation resulted in a DLL that needed a specific version of Microsoft’s Visual Studio. The few times I have looked at the Ruby language’s source code, it was in C, not C++. That would prevent the “.so” extension files from encountering the various name mangling of C++ function overloading that compilers might have.

I think the reason to ditch the old API was that it was highly coupled to SketchUp’s internal workings, without much thought of what should even be available in an API. I’ve gotten the impression you could do things with it that wasn’t supposed to be supported by the core and could cause crashes. I don’t have any examples of this though.

I think ThomThom commented on what made C better than C++ but I can’t remember.

I think Bruce has the right of it. I seem to remember @bugra commenting that the C API has better portability.

Look at the wrappings and bindings that have been done using the C API to allow use in C#, Cython/Python and even Ruby. Perhaps even other languages.

1 Like

Makes sense.
Thanks for your input, guys. I’m a tiny bit less frustrated now :smiley:

I forgot to mention that both Thomas and Tommy have done C++ wrappings, if that is what you prefer.
TT hasn’t yet published his. Tommy’s is here …

Yes we tried to use it a few months ago, and even contributed a couple of fixes. But at the time it wasn’t mature enough and we didn’t have time to improve it.

C++ binary compatibility is a pain. C is much more portable.

I made a C++ wrapper on top of Ruby. So instead of using VALUE variables and Ruby’s C API directly I use my C++ wrapper which introduce some type safety, easier code editing as the IDE knows what type I’m working on. Also let me inspect the values of Ruby strings and arrays etc when debugging.

I think this is the more mature C++ wrapper of the C API so far. Worth for the community to contribute.

1 Like