• 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 15:19:28 +0200

Hi. Thanks for joining the discussion.


> Can you pass a script object as a parameter to a handler in AppleScript?

I guess so yeah, a script object is also just a type class. If not, I guess you could
always go the extra way of declaring a property in the containing script object
and set that to the script you wanna pass. In the sub-level script object's handler
you can then reference the property by saying "parent's property".

There's also the trick of declaring a top-level property as

property toplevelScript : me
on handler()
    -- magic
end handler

and then saying

toplevelScript's handler()

to reference a specific handler from deeply nested sub-level scripts.

Of course that's not exactly the answer to your question, but that's all the ways of
getting a script object inside a handler deep down the hierarchy of script object contexts.
All that I can think of anyway :)

André

--- Original Nachricht ---
Absender: Mark J. Reed
Datum: 23.10.2008 14:59 Uhr
The usual solution for faking closures/function pointers in an OOPL is
to use objects with a predetermined method name - the caller can
always declare a new class to get the functionality desired.  Can you
pass a script object as a parameter to a handler in AppleScript?



On 10/23/08, André Berg wrote:
  
--- 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

  • Follow-Ups:
    • Re: How to simulate C's function pointer in AppleScript?
      • From: "Mark J. Reed" <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>)

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