Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Embedding F-Script into Cocoa Applications
Subject:   thanks, example gave something to chew on
Date:   2002-08-11 04:46:37
From:   pmougin
Response to: thanks, example gave something to chew on

In order to configure the button (i.e. object1) we need to provides it with a target (i.e. an object), and the name of the message it must send to the target when clicked (this is the Cocoa target/action paradigm). The Cocoa API require for the "action" message to be a message with one and only one parameter. At run-time, when clicked, the button will send the message to its target, passing itself as the parameter (this allows the target to further interact with the button if needed).


In our case the target is an F-Script block. Our goal is to execute this block when the button is clicked. As you know, in order to execute a block, you send it a "value..." style message (the exact message depends on the number of parameters the block is expecting). Here, we configure the button with the "value:" message name, which is the one that takes one parameter (in the example, our block doesn't make use of this parameter).


Note that "#value:" represent the name of a message. What in Objective-C is called a message selector. So in fact it is (in F-Script) an object, but an object whose job is to represent the name of a message. It is a noun that describe a verb.


The target-action paradigm is described in the Apple Objective-C book, as well as some notions about outlets. I would also recommend you to get the Hillegass Cocoa book (see http://www.bignerdranch.com/Book/).


Phil

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • thanks, I believe # is F-scripts symbol and have distilled something
    2002-08-12 22:12:01  psheldon [View]

    My objC.pdf manual with index didn't mention a #.
    I got, p.57 of old objC.pdf manual with index, that a method selector can take a runtime assigned variable as an argument, so I understand why you value implementing F-Script to take something like a literal constant. I've seen constant strings and string variables that were assigned, so I think I got the idea what this #-construct is doing and how its place could be occupied with something more general.

    You wrote :
    "The target-action paradigm is described in the Apple Objective-C book, as well as some notions about outlets."
    I read this, but I need to struggle writing to get it in my heart.
    An outlet is an object declared in a controller associated with an IB object. The IB/controller object has methods that the controller can send it as messages, such as to write some text. Now, when I set up such an outlet and its use totally in F-Script and interface builder, I imagine I must exemplify me doing something to get that object to do its method. To get an idea, I give myself an example of pushing a button. That button would run a script by my coding as in your example and in that script the outlet would be assigned to and object by the control drag mechanism. Then I would see the text print.
    Am I right?
    If I am right, when I am not so tired, I will give myself an exercise doing this in a simple little example program. I shall then write myself a little column, big enough for my own adventure. I know I can talk myself into believing I understand, but only when I try to work out something will I get the ultimate confidence (after some frustration).
    I shall consider buying Cocoa book by Hillegass.
    Thank you again.


    • Re: thanks, I believe # is F-scripts symbol and have distilled something
      2002-08-14 10:54:48  pmougin [View]

      Basically, what you need is to make the F-Script block a target of the button. Normally, in IB, to make an object a target of a button, you juste control-drag FROM the button TO the object. Here is a somewhat not easy thing to graps with F-Script live mode: the commonly used technique described above is not what you will use to connect a button to a F-Script block! Actually this is a two step process:

      First, you let know the F-Script interpreter about the button by control-dragging FROM the F-Script interpreter object TO the button and assigning the button to one of the interpreter outlet (object1 for instance).

      Now, you can manipulate the button from within F-Script. This means that you can now type "object1 setTarget:[sys log:'hello'. sys beep]. object1 setAction:#value:]" in the F-Script live mode window. This will establish the block [sys log:’hello’. sys beep] as the target of the button.


      Phil