[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

writing native ObjC extension to ruby ??

Yvon Thoraval

8/7/2006 10:57:00 AM

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)

10 Answers

Paul Battley

8/7/2006 11:38:00 AM

0

On 07/08/06, Yvon Thoraval <yvonthoraval@free.fr> 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.source...
2. http://www.ruby...
3. http://www.ruby...mastering-cocoa-with-ruby

Logan Capaldo

8/7/2006 12:14:00 PM

0


On Aug 7, 2006, at 7:47 AM, Yvon Thoraval 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( )
}




pere.noel

8/7/2006 12:42:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> 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)

???

--
une bévue

Logan Capaldo

8/7/2006 1:13:00 PM

0


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

> Logan Capaldo <logancapaldo@gmail.com> 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)
>
> ???
>
Sure you can, Carbon is a C api (and a relatively sane one at that,
it's almost OO in many ways).


> --
> une bévue
>


pere.noel

8/7/2006 3:57:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> 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_rub...

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

--
une bévue

Logan Capaldo

8/7/2006 4:23:00 PM

0


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

> Logan Capaldo <logancapaldo@gmail.com> 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_rub...
>
> 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
right compile switches.

> --
> une bévue
>


pere.noel

8/7/2006 6:39:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> 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...
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_rub....

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)
--
une bévue

Jon Egil Strand

8/7/2006 8:55:00 PM

0

M. Edward (Ed) Borasky

8/8/2006 4:41:00 AM

0

Jon Egil Strand wrote:
> 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/projec...

Enjoy!!

Robert Klemme

8/8/2006 8:12:00 AM

0

M. Edward (Ed) Borasky wrote:
> Jon Egil Strand wrote:
>> 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/projec...

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