Re: How to simulate C's function pointer in AppleScript?
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