Re: [MacRuby-devel] Understanding Pointer objects
You can set pointers using:
Pointer.new_with_type and using one of the following types:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
Note, that not none of the types are supported.
Here is some more information:
http://jonathan.waddilove.net/macruby_pointers.html
To dereference a pointer, simply get its value:
pointer = Pointer.new_with_type("f")
pointer.assign(3.2)
pointer's value = pointer[0]
I'll soon update my book draft with a section on pointers.
- Matt
On Sat, Oct 23, 2010 at 10:04 PM, Mark Rada wrote:
> Hi,
>
> I've been trying to play with using the Accessibility API to do some
> automated testing.
>
> >From what I have researched, I have to use some C functions that often
> need a reference passed to the them.
>
> I am at a loss when trying to deal with Pointer objects. I've tried playing
> with them and googling it, but I just cannot figure out how to turn a
> pointer into a more useful type or to get what I want out of them.
>
> For example, I can start like this:
>
>framework 'Cocoa'
>
>unless AXAPIEnabled() # only works if I include the parenthesis
>puts 'Please enable Access for Assistive Devices first'
>exit 2
>end
>
>mail =
> NSRunningApplication.runningApplicationsWithBundleIdentifier('com.apple.Mail').first
>mail_object = AXUIElementCreateApplication mail.processIdentifier
>
>names = Pointer.new :object
>
>AXUIElementCopyAttributeNames mail_object, names
>
>
> But then how do I get the values out of the names pointer? For reference, I
> found the functions in AXUIElement.h.
>
>
> Thanks,
>Mark
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Frameworks Help
Hey Shaun, On Sun, Oct 24, 2010 at 1:14 AM, Shaun August wrote: > Hi Again, > > I have spent some time with Nick's tutorial and I am looking into wrapping > the framework I have been provided with and I have a few more questions. > > The framework I am working with is already compiled and not in an xcode > file. I am guessing all I need to do is write the Objective-C wrapper? > Yeah, all you have to worry about, is writing the wrapper, as it is what I did with my code writing for my wrapper. > The other issue I am having is the framework only contains one header file > which links out to a series of files contained in a system extension. > The header file, is all you need to import, as it should define all public API Access you need, including structs, to interface with the binary library. > Am I able to write my wrapper in an Objective-C class from within my > macruby application or do I need to create a bundle and import that into my > project. > You will need to write Pure Objective-C code for the API Access, but the code can be included with your macruby application, in the project itself. What will happen, is when you compile the main Objective C File, Main.m, it'll compile all the other Objective C files into the binary executable, that will eventually run your rb_main.rb file. It'll give all the access of your Objective C libraries that you wrote, right within your application. hth, Mario > Thanks, > > Shaun > > > > > On 2010-10-19, at 10:12 PM, Mario Steele wrote: > > Hello Shaun, > > On Wed, Oct 20, 2010 at 12:00 AM, Shaun August wrote: > >> Hi Robert, >> >> Thanks! That make sense. All those cocoa classes have capitals and they >> work fine. I seem to be able to call from the framework but I am running >> into an undefined method 'extern'. I have also read somewhere that extern >> doesn't work with MacRuby. Is that correct? The framework I am dealing with >> is calling C functions and I am having trouble accessing them. >> > > extern is a macro for the ld library, to export an API Address in the > Dynamic library, that can be access dynamically at run time. With > Objective-C, or more so specifically with MacRuby, you need to write a sort > of thin wrapper around C Functions in Objective C, in order to access said > Functions. So if the framework that you are working with, doesn't expose > Objective C API Functions, you'll need to write a thin wrapper in order to > access them. See the tutorial done by Nick Ludlam about wrapping the TagLib > C Library, in Objective C. You can find it here: > http://www.macruby.org/documentation/reading-an-mp3-with-macruby.html It's > best to read through the entire article, as it gives you information about > wrapping C Functions in Objective C, which is quite useful, when writing > your own wrapper. > > hth, > > Mario > > >> Thanks, >> >> Shaun >> >> >> On 2010-10-19, at 8:26 PM, Robert Rice wrote: >> >> > Hi Shaun: >> > >> > Lower case method names is only a convention. MacRuby will work fine >> using upper case, i.e., constant, method names. >> > I know because I only recently changed my project to conform to the >> convention. >> > >> > Bob Rice >> > >> > >> > On Oct 19, 2010, at 7:17 PM, Shaun August wrote: >> > >> >> Hi There, >> >> >> >> I am attempting to work with a framework provided by a USB device >> manufacturer and all of their method names start with capitols and I am >> wondering about the easiest way to access these methods through macruby. I >> remember reading somewhere about fixing the constants in Obj-C but I cannot >> locate the information. >> >> >> >> Does anyone have any suggestions as to how to remedy this? Should I >> rename every command in the framework? >> >> >> >> Thanks, >> >> >> >> Shaun >> >> >> >> ___ >> >> MacRuby-devel mailing list >> >> [email protected] >> >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> >> > >> > ___ >> > MacRuby-devel mailing list >> > [email protected] >> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> > > > > -- > Mario Steele > Lieutenant Commander 3 > XO - Geo 99 > XO - STO IFT Fleet > http://www.trekfederation.com > http://geo99.ruby-im.net > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > -- Mario Steele Lieutenant Commander 3 XO - Geo 99 XO - STO IFT Fleet http://www.trekfederation.com http://geo99.ruby-im.net __
Re: [MacRuby-devel] Is CoreText Fully Support
thanks ,I tried the new BirdgeSupport, it works :-) 2010/10/18 Matt Aimonetti > Hopefully the new BridgeSupport will help you solve this issue. > > - Matt > > > On Thu, Oct 7, 2010 at 7:28 PM, dianhui nie wrote: > >> Ok. I'll do this later when i was home : ) >> >> On Oct 8, 2010, at 10:17 AM, Laurent Sansonetti wrote: >> >> Hi, >> >> Could you reduce the problems to simple .rb scripts and attach them to a >> new ticket? >> >> We are working on a new version of BridgeSupport which will add missing >> metadata (I believe it will fix your CoreText problems), but we will need to >> verify. >> >> In the interim, you can wrap CoreText APIs in Objective-C classes, them >> call them from MacRuby directly. >> >> Laurent >> >> On Oct 7, 2010, at 7:41 AM, 聂殿辉 wrote: >> >> Hi >> I'm doing some work with CoreText with macruby ,and i had some question >> >> 1. CTline and some other `struct` does not have a ruby class ,the >> ctline.class is __NSCFType >> , not like the CGRect struct,in macruby ,the class is CGRecct ,so i can >> reopen the class ,and add some help methods. >> 2. the CTRunGetStringRange should return a CFRange but it return a class >> named Boxed >> >> can i wrap the CoreText in macruby ? and some suggestions ?? >> >> thanks >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Confusing with The memory a macruby app used
Hi: I want to write an app with macruby , and want to make sure there's not memory problem. I create an Macruby-Application with Xcode ,and lanuch it ,using the Activity Monitor , it using about 44M memory ,and create an ObjectivC-Application ,it only use 8M memory ,is it normal? thanks ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Confusing with The memory a macruby app used
Yes it is - Matt Sent from my iPhone On Oct 24, 2010, at 6:26, 聂殿辉 wrote: > Hi: > I want to write an app with macruby , and want to make sure there's not > memory problem. I create an Macruby-Application with Xcode ,and lanuch it > ,using the Activity Monitor , it using about 44M memory ,and create an > ObjectivC-Application ,it only use 8M memory ,is it normal? thanks > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Understanding Pointer objects
On 2010-10-24, at 05:06 , Matt Aimonetti wrote:
Is there any difference if I do these instead:
> pointer = Pointer.new_with_type("f")
p = Pointer.new(:float) #<= new instead of new_with_type
> pointer.assign(3.2)
p[0] = 3.2 #<= #[]= instead of #assign
I have used both successfully in the past. Just wondering if I was just lucky
or if they're fine.
Also, what's with the #[] thing anyway? What would I get using p[1], p[2]? Is
this a way to deal with C arrays or otherwise do basic pointer arithmetics?
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Understanding Pointer objects
Hey,
Thanks for the response. It has helped, but I am still confused a bit by you
stating that none of the types are supported but that I can still dereference a
pointer.
I have now been able to dereference some pointers, but not pointers to
pointers. Is that what you meant?
In these cases I guess I will have to create an objective-c wrapper. I found an
entry on the MacRuby site about creating bundles which I think is a good
solution.
Thanks for the pointers,
Mark
Sent from my iDevice
On 2010-10-24, at 3:06, Matt Aimonetti wrote:
> You can set pointers using:
>
> Pointer.new_with_type and using one of the following types:
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
> Note, that not none of the types are supported.
>
> Here is some more information:
> http://jonathan.waddilove.net/macruby_pointers.html
>
> To dereference a pointer, simply get its value:
>
> pointer = Pointer.new_with_type("f")
> pointer.assign(3.2)
> pointer's value = pointer[0]
>
> I'll soon update my book draft with a section on pointers.
>
> - Matt
>
>
> On Sat, Oct 23, 2010 at 10:04 PM, Mark Rada wrote:
> Hi,
>
> I've been trying to play with using the Accessibility API to do some
> automated testing.
>
> >From what I have researched, I have to use some C functions that often need
> >a reference passed to the them.
>
> I am at a loss when trying to deal with Pointer objects. I've tried playing
> with them and googling it, but I just cannot figure out how to turn a pointer
> into a more useful type or to get what I want out of them.
>
> For example, I can start like this:
>
>framework 'Cocoa'
>
>unless AXAPIEnabled() # only works if I include the parenthesis
>puts 'Please enable Access for Assistive Devices first'
>exit 2
>end
>
>mail =
> NSRunningApplication.runningApplicationsWithBundleIdentifier('com.apple.Mail').first
>mail_object = AXUIElementCreateApplication mail.processIdentifier
>
>names = Pointer.new :object
>
>AXUIElementCopyAttributeNames mail_object, names
>
>
> But then how do I get the values out of the names pointer? For reference, I
> found the functions in AXUIElement.h.
>
>
> Thanks,
>Mark
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Confusing with The memory a macruby app used
Hi, The memory used by a new MacRuby app depends on your environment, but it's indeed bigger than a default Objective-C app. If you start enabling garbage collection in the Objective-C app and create some objects, the rsize should then be the same as a normal MacRuby app (since the runtime itself creates some objects when starting). Using AOT compilation will decrease some memory usage. If you think the default rsize of a MacRuby process is too high please file a ticket and we will investigate. Otherwise, make sure the rsize of your app remains constant while using it, if you notice it's growing then please let us know, since it might be a leak. Laurent On Oct 24, 2010, at 6:26 AM, 聂殿辉 wrote: > Hi: > I want to write an app with macruby , and want to make sure there's not > memory problem. I create an Macruby-Application with Xcode ,and lanuch it > ,using the Activity Monitor , it using about 44M memory ,and create an > ObjectivC-Application ,it only use 8M memory ,is it normal? thanks > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Understanding Pointer objects
Hi Caio,
On Oct 24, 2010, at 11:09 AM, Caio Chassot wrote:
> On 2010-10-24, at 05:06 , Matt Aimonetti wrote:
>
> Is there any difference if I do these instead:
>
>> pointer = Pointer.new_with_type("f")
>
> p = Pointer.new(:float) #<= new instead of new_with_type
>
>> pointer.assign(3.2)
>
> p[0] = 3.2 #<= #[]= instead of #assign
>
>
> I have used both successfully in the past. Just wondering if I was just lucky
> or if they're fine.
They are the same :)
> Also, what's with the #[] thing anyway? What would I get using p[1], p[2]? Is
> this a way to deal with C arrays or otherwise do basic pointer arithmetics?
A Pointer object allows you to allocate memory of a given type for a given
number of elements. You can create an array of floats for example. Then, #[]
and #[]= make sense to get/set elements of this array.
Pointer objects are also returned by MacRuby when calling a native API that
returns a pointer to something. For example, float *. The API documentation
might state that it's one float, or an array of floats. In this case, MacRuby
doesn't really know much about the pointer itself (like its bounds), which is
why using #[] and #[]= must be done in a very careful way.
Laurent___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Understanding Pointer objects
Hi Mark,
Matt already replied but I thought I would give more info.
On Oct 23, 2010, at 10:04 PM, Mark Rada wrote:
> Hi,
>
> I've been trying to play with using the Accessibility API to do some
> automated testing.
>
>> From what I have researched, I have to use some C functions that often need
>> a reference passed to the them.
>
> I am at a loss when trying to deal with Pointer objects. I've tried playing
> with them and googling it, but I just cannot figure out how to turn a pointer
> into a more useful type or to get what I want out of them.
>
> For example, I can start like this:
>
> framework 'Cocoa'
>
> unless AXAPIEnabled() # only works if I include the parenthesis
> puts 'Please enable Access for Assistive Devices first'
> exit 2
> end
That's expected, in Ruby methods starting with a capital letter must be called
with explicit parentheses, otherwise they are interpreted as constants.
> mail =
> NSRunningApplication.runningApplicationsWithBundleIdentifier('com.apple.Mail').first
> mail_object = AXUIElementCreateApplication mail.processIdentifier
>
> names = Pointer.new :object
>
> AXUIElementCopyAttributeNames mail_object, names
>
>
> But then how do I get the values out of the names pointer? For reference, I
> found the functions in AXUIElement.h.
It looks like AXUIElementCopyAttributeNames returns a CFArray by reference. So
your pointer object is properly created, to retrieve the array after the call
you just use
array = names[0]
Then, it should behave like a normal Ruby array.
Laurent___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Understanding Pointer objects
On 2010-10-24, at 9:34 PM, Laurent Sansonetti wrote:
> Hi Mark,
>
> Matt already replied but I thought I would give more info.
>
> On Oct 23, 2010, at 10:04 PM, Mark Rada wrote:
>
>> Hi,
>>
>> I've been trying to play with using the Accessibility API to do some
>> automated testing.
>>
>>> From what I have researched, I have to use some C functions that often need
>>> a reference passed to the them.
>>
>> I am at a loss when trying to deal with Pointer objects. I've tried playing
>> with them and googling it, but I just cannot figure out how to turn a
>> pointer into a more useful type or to get what I want out of them.
>>
>> For example, I can start like this:
>>
>> framework 'Cocoa'
>>
>> unless AXAPIEnabled() # only works if I include the parenthesis
>> puts 'Please enable Access for Assistive Devices first'
>> exit 2
>> end
>
> That's expected, in Ruby methods starting with a capital letter must be
> called with explicit parentheses, otherwise they are interpreted as constants.
Ah, that makes more sense now.
>
>> mail =
>> NSRunningApplication.runningApplicationsWithBundleIdentifier('com.apple.Mail').first
>> mail_object = AXUIElementCreateApplication mail.processIdentifier
>>
>> names = Pointer.new :object
>>
>> AXUIElementCopyAttributeNames mail_object, names
>>
>>
>> But then how do I get the values out of the names pointer? For reference, I
>> found the functions in AXUIElement.h.
>
>
> It looks like AXUIElementCopyAttributeNames returns a CFArray by reference.
> So your pointer object is properly created, to retrieve the array after the
> call you just use
>
> array = names[0]
>
> Then, it should behave like a normal Ruby array.
Ah, that does work, and seems to have worked for a number of other things I am
trying to do.
The only problem now is when I have something like
value = Pointer.new '^v' # pointer to pointer to void
AXUIElementCopyAttributeValue mail_object, 'AXHidden', value
In this case I am using it right now, it will be returning a boolean, but when
I try to dereference it like
puts value[0][0] # => 120
it gives me a Fixnum, and then I can keep trying things like
puts value[0][1] # => 104
puts value[0][1] # => 0
And I seem to get nowhere.
Is there a way to cast the data back into the type I want it to be? Or am I
doing something dumb?
Thanks,
Mark
>
> Laurent
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
