Writing native ObjC extension to ruby?

i’d like to write a natine objc ext to ruby.

i’m in search of an example or a tuto.

(i’ve found how to write C ext)

On 07/08/06, Yvon T. [email protected] wrote:

i’d like to write a natine objc ext to ruby.

Have a look at RubyCocoa[1][2]. You probably don’t need to write an
extension, as you can use ObjC objects directly from within Ruby. (If
you still want to write ObjC, perhaps the source of RubyCocoa will
point you in the right direction.)

i’m in search of an example or a tuto.

There’s a detailed tutorial on RubyCocoa by Tim Burks[3] - I haven’t
looked at it in depth, but it seems good.

Paul.

  1. http://rubycocoa.sourceforge.net/
  2. http://www.rubycocoa.com/
  3. http://www.rubycocoa.com/mastering-cocoa-with-ruby

Le 7 août 06 à 13:38, Paul B. a écrit :

Have a look at RubyCocoa[1][2]. You probably don’t need to write an
extension, as you can use ObjC objects directly from within Ruby.

in my case i’m not sure i can use ObjC object directly because even
the ObjC class i’ve wrotten makes use of non ObjC method (Carbon and
the like).

(If
you still want to write ObjC, perhaps the source of RubyCocoa will
point you in the right direction.)

i’m in search of an example or a tuto.

There’s a detailed tutorial on RubyCocoa by Tim Burks[3] - I haven’t
looked at it in depth, but it seems good.

thanks a lot i didn’t your last ref ))

Yvon

On Aug 7, 2006, at 7:47 AM, Yvon T. wrote:

in my case i’m not sure i can use ObjC object directly because even
the ObjC class i’ve wrotten makes use of non ObjC method (Carbon
and the like).

That shouldn’t matter assuming its like

  • objCMethod
    {
    CallCarbonFunction( )
    }

Logan C. [email protected] wrote:

That shouldn’t matter assuming its like

  • objCMethod
    {
    CallCarbonFunction( )
    }

OK fine, however Tim Burks at the page
ttp://www.rubycocoa.com/ruby-extensions-with-rubycocoa/3

says :

We have to use RubyCocoa/Objective-C object allocation
and initialization. Instead of calling Jukebox.new
to create our jukebox objects, we have to perform
the standard Objective-C two step initialization.
First call alloc, then the init function,
in this case initWithUnit.

then i would have better to write my ext in C (rather than in ObjC)
because the try out i’ve done using ObjC wrapper of C for RubyCocoa
needs those steps :

require ‘osx/cocoa’
require ‘jukebox’
OSX::ns_import :Jukebox

j = OSX::Jukebox.alloc.initWithUnit(13)
j.seekDisc(3, :track, 16)
[…]
GC.start
disposing of jukebox with unit id 13

whereas with my ObjC class i’ve used only :

OSX.ns_import(‘MyAlias’) # the ObjC class
@ns_alias=OSX::MyAlias.alloc.initWithAliasPath(@ns_alias_path)

and i get everything i need about “MyAlias”

however definitely i would prefer doing that more shortly (as with C
ext) :

trick=MyAlias.new

as said by Tim Burks

then, now, i wonder if i could call carbon methods :
CFURLCreateWithFileSystemPath
CFURLGetFSRef …
FSResolveAliasFile
CFURLCreateFromFSRef
CFURLCopyFileSystemPath

as easily in C than in ObjC (i never a line of C, only 30 lines of ObjC)

???

On Aug 7, 2006, at 8:45 AM, Une bévue wrote:

ttp://www.rubycocoa.com/ruby-extensions-with-rubycocoa/3
then i would have better to write my ext in C (rather than in ObjC)
GC.start
however definitely i would prefer doing that more shortly (as with C
CFURLCreateFromFSRef
CFURLCopyFileSystemPath

as easily in C than in ObjC (i never a line of C, only 30 lines of
ObjC)

???

Sure you can, Carbon is a C api (and a relatively sane one at that,
it’s almost OO in many ways).

Logan C. [email protected] wrote:

Sure you can, Carbon is a C api (and a relatively sane one at that,
it’s almost OO in many ways).

ok, thanxs, i did a first test following “Extending Ruby”
http://www.rubycentral.com/book/ext_ruby.html

it seems gcc want to use /usr/bin/ld

gcc didn’t found even ruby.h and also from the Test.c example given in
the pickaxe i do have nearly one syntax error per line for ruby.h,
missing.h and the like…

my gcc command was simply :
gcc -o Test.bundle -bundle -framework Foundation Test.c

in my working folder i do have :
missing.h
config.h
defines.h
intern.h
ruby.h
Test.c

then i think, at least, some option to gcc is missing ))

Le 7 août 06 à 18:23, Logan C. a écrit :

Are you using mkmf? It’ll make your life much easier and produce
the right compile switches.

yes thanxs, i’m reading “How to create a Ruby extension in C in under
5 minutes” <http://www.rubyinside.com/how-to-create-a-ruby-extension-
in-c-in-under-5-minutes-100.html> right now ))

Greetings

Does there in the db-world exist any de-facto standard dataset for
db-performance testing?

I know there esists some “standard” problems both in image-analysis
(some
picture of a woman, can’t remember her name just now), and machine
learning (us zip-code hand writing). Are there any similar sets for
databases?

Ideally, it should be large, contain multiple datatypes, some structure
but still be easy enough to present in a talk.

Reason:

I’m planning on doing some db-performance testing.

Goals:
a) Learn more about Ruby’s db tools
b) Learn more about postgres & sqlserver (my main options at work)
c) Learn profiling and tuning

All the best

On Aug 7, 2006, at 12:00 PM, Une bévue wrote:

gcc didn’t found even ruby.h and also from the Test.c example given in
intern.h
ruby.h
Test.c

then i think, at least, some option to gcc is missing ))

Are you using mkmf? It’ll make your life much easier and produce the
right compile switches.

Logan C. [email protected] wrote:

Are you using mkmf? It’ll make your life much easier and produce the
right compile switches.

not before, but right now, i’m following the page “How to create a Ruby
extension in C in under 5 minutes”
<http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-
5-minutes-100.html>

i’ve allready done the “MyTest” example and want to adapt this strategy
to the jukebox given in “Extending Ruby” of “The Pragmatic Programmer’s
Guide” http://www.rubycentral.com/book/ext_ruby.html.

here i’ve done the “cdjukebox.bundle” using mkmf however when wanting to
test by ruby i get :
dyld: NSLinkModule() error
dyld: Symbol not found: _CDPlayerSeek
Referenced from: ./Jukebox/cdjukebox.bundle
Expected in: flat namespace

the *.h and *.c are cut’n paste from pickaxe and my ruby test being :

require ‘Jukebox/cdjukebox’
p = CDPlayer.new(1)
puts “Unit is #{p.unit}”
p.seek(3, 16) {|x| puts “#{x}% done” }
puts “Avg. time was #{p.seekTime} seconds”

also as it’s done in pickaxe…

i wonder also how to translate my ObjC class into a C one, i’ve heard
they are tools for that ? (i’ve found the reverse C → ObjC)

Jon Egil S. wrote:

Ideally, it should be large, contain multiple datatypes, some structure

All the best

There is indeed a “standard” database test suite. I believe the base
implementations are in C with PostgreSQL as the database, but of course
you can vary the language and the database for purposes of comparison.
The suite can be found at

Enjoy!!

M. Edward (Ed) Borasky wrote:

All the best

There is indeed a “standard” database test suite. I believe the base
implementations are in C with PostgreSQL as the database, but of course
you can vary the language and the database for purposes of comparison.
The suite can be found at

http://sourceforge.net/projects/osdldbt

Hm, didn’t know that. Thanks for that link!

However, I’m not sure about the usefulness of such a thing. First, to
get meaningful results the dataset typically needs to be huge - but
there is huge and huge (for some apps it’s GB for others TB). Second,
each application’s DB schema and usage pattern differ, so while it
probably makes sense to have a SAP DB test suite I’m not sure what I’d
expect from a generalized test set. Did you use this already and can
share some experience?

Kind regards

robert