ruby-c-extension-examples icon indicating copy to clipboard operation
ruby-c-extension-examples copied to clipboard

Add some examples with substance.

Open DanRathbun opened this issue 5 years ago • 7 comments
trafficstars

The Hello World is a silly and meaningless example.

Add some examples with substance. Something that at least looks up some SketchUp model properties and displays them.

DanRathbun avatar Oct 01 '20 23:10 DanRathbun

Got a Ruby equivalent for what you are looking for?

The Hello World is a silly and meaningless example.

The main purpose of this example has been to provide the headers and lib along with project setup to compile a Ruby C extension that runs within SketchUp. For that it has served well.

I can see that there are opportunities to do more with the examples. (However, just because it isn't 100% what you expect doesn't mean it isn't useful for others. And there any many ways to suggests improvements in more positive constructive language.)

Also, Pull Requests are welcome 😉!

thomthom avatar Oct 05 '20 10:10 thomthom

Observation: Your adding of an inner loop is the kind of thing that makes a good example ...

https://forums.sketchup.com/t/how-to-create-a-hole-using-the-inner-loop/74239/3

... but is probably more suited to the Live-C example repo: https://github.com/SketchUp/sketchup-live-c-api applying to a external file.

DanRathbun avatar Aug 24 '21 20:08 DanRathbun

Are you looking for examples on how to use Ruby's C API? How to make method calls to Ruby from C?

thomthom avatar Aug 25 '21 08:08 thomthom

Not specifically. This topic is about "examples with substance" ... So any examples showing basics of using the C API in standalone or "live" mode are "good".

But specific to your question, I've often posted links to the companion book for "Writing Ruby Extensions in C". It is informative although quite old now. (It was written when Ruby 1.9 was current.) It can be overwhelming if a coder is just looking for the simply how to call SketchUp's Ruby API methods from a C extension. So I would have to answer yes, that a simple example could be beneficial. (I think you have already posted such an example either in the forums, or in some of the tracker issue threads.)

DanRathbun avatar Aug 25 '21 19:08 DanRathbun

The main purpose of this example repo is setting up the project, along with providing the headers and libs. My experience with Ruby C extensions was that writing the code was the easy part, but getting a project setup to compile and link was the hard part.

My go-to reference for the Ruby C API is this one: https://silverhammermba.github.io/emberb/c/

thomthom avatar Aug 26 '21 08:08 thomthom

Okay this is nice ... BUT ... your taking this discussion off-topic.

Again, this is about examples of using the SketchUp C API. Showing tasks that are NOT obvious to new users of the C API and probably know little of how SketchUp works. (Ie, they need to write an importer for a 3rd party application, etc.)

For example, ... the question you answered today about copying text objects from model to model. There is no explanation that an exception will occur if a text object's font is not set.

There are other tasks also using the SU C API where the order that things are done must be correct.

DanRathbun avatar Aug 26 '21 20:08 DanRathbun

I'd say such examples fit better in pure C API examples. They are not tied to Ruby C extension or live C API. (I fully agree that we need better C API examples.)

thomthom avatar Aug 27 '21 10:08 thomthom