• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to simulate C's function pointer in AppleScript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to simulate C's function pointer in AppleScript?


  • Subject: Re: How to simulate C's function pointer in AppleScript?
  • From: André Berg <email@hidden>
  • Date: Thu, 23 Oct 2008 20:35:43 +0200

This is actually quite elegant. Thanks for taking the time to explain it.

It's all working well now. I am using the non-encapsulated approach with
a script object containing an on run() handler that wraps the code one needs
to time.

The user can set various settings before calling Timer's timeit(), but he doesn't
have to, because those settings are all implemented as properties and have
default values. Which makes timing code very easy and comfortable now.


I dropped the ability to pass a string containing AppleScript syntax completely.
I am not sure of the implementation details, but I can only state that I have observed
that the same code passed in a script object's on run() handler performs almost 1.5 orders
of magnitude better than the exact same code passed as an escaped AppleScript syntax
string. Other advantages of using a script object include:


- you can avoid having to go around carefully matching escape-levels.

- you see instantly if some of your code has errors because of the syntax coloring in the
compilation process.


While running a lot of tests I came to appreciate those little things :)


André

P.S. Yeah, you can pass script objects directly in a handler.

--- Original Nachricht ---
Absender: Mark J. Reed
Datum: 23.10.2008 16:19 Uhr
What I was thinking of was this:

script scriptToTime
    on run()
               display dialog "beep"
    end run
end script

script Timer
      on timeit(procedure)
           run script procedure
      end timeit
end script

Timer's timeit(scriptToTime)

If you want to initialize the procedure once and then time it many
times, you can do this:

script Timer
    property procedure: missing value

    on setProcedure(newProcedure)
          set my procedure to newProcedure
    end setProcedure

   on timeit()
        run script procedure
   end timeit
end script

Or if you're not concerned about encapsulation you can just

set Timer's procedure to whatever

before calling timeit.





_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >How to simulate C's function pointer in AppleScript? (From: André Berg <email@hidden>)
 >Re: How to simulate C's function pointer in AppleScript? (From: Philip Aker <email@hidden>)
 >Re: How to simulate C's function pointer in AppleScript? (From: André Berg <email@hidden>)
 >Re: How to simulate C's function pointer in AppleScript? (From: "Mark J. Reed" <email@hidden>)
 >Re: How to simulate C's function pointer in AppleScript? (From: André Berg <email@hidden>)
 >Re: How to simulate C's function pointer in AppleScript? (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: How to simulate C's function pointer in AppleScript?
  • Next by Date: Close Unselected Tabs in Safari...
  • Previous by thread: Re: How to simulate C's function pointer in AppleScript?
  • Next by thread: Re: How to simulate C's function pointer in AppleScript?
  • Index(es):
    • Date
    • Thread