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):
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 dataSub 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 FunctionListing 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
|










