writing native ObjC extension to ruby ??

Y

Yvon Thoraval

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)
 
P

Paul Battley

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
 
L

Logan Capaldo

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( )
}
 
U

Une bévue

Logan Capaldo said:
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)

???
 
L

Logan Capaldo

Logan Capaldo said:
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 =3D 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=3DOSX::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=3DMyAlias.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 =20
ObjC)

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

Une bévue

Logan Capaldo said:
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 ))
 
L

Logan Capaldo

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 ))

Are you using mkmf? It'll make your life much easier and produce the =20
right compile switches.
 
U

Une bévue

Logan Capaldo said:
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)
 
J

Jon Egil Strand

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
 
M

M. Edward (Ed) Borasky

Jon said:
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
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

Enjoy!!
 
R

Robert Klemme

M. Edward (Ed) Borasky said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top