Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

Article Preview


Buy Now

Print:
PDF:

Feature

Using RBScript

Creating plugins for your application

Issue: 2.6 (July/August 2004)
Author: Thomas Reed
Author Bio: Thomas Reed has been programming as a hobbyist for more than 20 years, and fell in love with the Mac in 1984.
Article Description: No description available.
Article Length (in bytes): 8,109
Starting Page Number: 30
RBD Number: 2614
Resource File(s):

Download Icon 2614.sit Updated: Wednesday, September 15, 2004 at 4:37 PM

Related Link(s): None
Known Limitations: None

Excerpt of article text...

Ask many REALbasic developers how to create a plugin architecture for your application and they're likely to tell you to write it in another language. Fortunately, this unpleasant advice couldn't be further from the truth. Not only is creating your own plugin architecture possible in REALbasic, it is not even all that difficult. RBScript is the answer.

RBScript provides a simple scripting language with which the user can easily create plugins. Because RBScripts are compiled before running, rather than being interpreted while running, they are as fast as native REALbasic code. The RBScript syntax is powerful enough to allow creation of classes, modules, and interfaces that can be used within the script.

With all of these things in its favor, why don't more people recommend RBScript for plugins? In part, I believe this is because some developers simply haven't explored RBScript. However, RBScripts do have one seemingly significant limitation: all RBScripts run in a "black box". They have access to only the most basic data types -- Integer, Single, Double, String, Boolean, and Color. They also recognize the Variant and Object (but not Object subclass) types, though variables of these types cannot be passed between the script and the application. An RBScript cannot in any way interact directly with any other kind of variable. This means they cannot interact with the outside world except in a very limited manner.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


List of Errata

Code Listings 2 and 3 from this article were accidentally omitted from this issue. This code has been added to archive and is also reprinted here:

Listing 2: Storing persistent data
Sub PersistentValue(key as string, assigns i as integer)
  pDict.Value(key) = i
End Sub

Sub PersistentValue(key as string, assigns s as string)
  pDict.Value(key) = s
End Sub

Sub PersistentValue(key as string, assigns b as boolean)
  pDict.Value(key) = b
End Sub

Function PersistentValueInteger(key as string) as integer
  return pDict.Value(key).IntegerValue
End Function

Function PersistentValueString(key as string) as string
  return pDict.Value(key).StringValue
End Function

Function PersistentValueBoolean(key as string) as boolean
  return pDict.Value(key).BooleanValue
End Function
Listing 3: Example Line tool script
const kMouseDown = 1
const kMouseDrag = 2
const kMouseUp = 3

dim startX, startY as integer

select case EventType
  
  case kMouseDown
    DrawPoint(CurX, CurY)
    PersistentValue("startX") = CurX
    PersistentValue("startY") = CurY
  
  case kMouseUp
    startX = PersistentValueInteger("startX")
    startY = PersistentValueInteger("startY")
    DrawLine(startX, startY, CurX, CurY)
  
end select


 


|

 


Weblog Commenting and Trackback by HaloScan.com