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 14:50:44 +0200
Title: Re: How to simulate C's function pointer in AppleScript?
--- Original Nachricht ---
Absender: Jay Louvion
Datum: 23.10.2008 13:03 Uhr
Have
you tried declaring it as global ?
Best,
j.
Thank you for replying. :) I failed to mention that I had tried that
already.
--- Original Nachricht ---
Absender: Philip Aker
Datum: 23.10.2008 13:22 Uhr
On Oct 23, 2008, at 3:58 AM, André Berg wrote:
The question now is how can I
correctly pass, from the top-level script, myHandlerToTime() in the
statement property of the Timer script so that it gets used as the
direct parameter to the run script command inside the Timer script?
on
doHandlerToTime()
display
dialog
"beep"
end
doHandlerToTime
script
Timer
property
procedure
:
missing value
on
timeit()
run
script
procedure
end
timeit
end
script
set
Timer's
procedure
to
doHandlerToTime
Timer's
timeit()
Passing parameters is a different story ;-)
Ok, seems like this was the missing piece. Thank you very much. :)
I didn't think of trying to pass the handler name as type and not in a
string.
So far so good...
But as we all know, it's never easy, now is it?
My handler of course has three parameters.
I think I will give the user the possibility to specify either an
AppleScript syntax string, or a script object that does the parameter
setup and calling of the handler to time itself, so that I can just
pass
it to the "run script" command:
-- either a script object
script scriptToTime
-- setup arguments for the function to time
on handlerToTime("spam", "eggs")
-- magic ...
end handlerToTime
end script
-- or an AS syntax string
set Timer's statement to
"tell app \"Finger\" to count fingers"
script Timer
property statement
: missing value
-- start timer
run script my
statement
-- end timer
end script
There might be a downside of a small overhead
that I cannot exactly calculate
this way, but the effect of being able to time handlers instead of only
statements
far outweighs that in my humble opinion and executing code inside one
AppleScript
component is always subject to rather large fluctuations in time
compared to other
languages.
Btw, might be related to this question, the "run script" command has an
optional
parameter called "in" that is used to specify the scripting component
that it should use as
execution context, but in my tests I couldn't get it to work. The
unicode text to specify
is the name of a script object, right?
Again thanks to you both for posting your replies :)
André
|
_______________________________________________
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