Difference between revisions of "Scripting of frameworks"

From GNUstepWiki
Jump to navigation Jump to search
 
m
Line 102: Line 102:
 
     );
 
     );
 
  }
 
  }
 +
 +
[[Category:Scripting]]

Revision as of 09:27, 18 February 2005

This article describes how to advertise and use scripting capabilities of a frameworks or a bundle.

Introduction

Any bundle, including an application or a framework can provide information about scripting. Bundles can advertise:

  • classes
  • named objects

Frameworks and other bundles do not have to be linked with StepTalk, therefore they do not have to have StepTalk dependency. You just include a file named ScriptingInfo.plist in the framework's or bundle's Resources directory.

Usage

To include a framework in a script, simply do following:

Environment includeFramework:'MyFrameworkName'.

Frameworks

You can use GNUstep Frameworks from StepTalk scripts. Frameworks are stored in standard paths */Library/Frameworks. To get a list of all available frameworks:

 NSBundle allFrameworkNames.

To load a framework with its public classes:

 Environment includeFramework:'MyFramework'

StepTalk Bundles (or Modules)

StepTalk bundles are stored in */Library/StepTalk/Modules and can be loaded this way:

Environment loadModule:'moduleName'.

For example, to load the AppKit module:

Environment loadModule:'AppKit'

To get list of all available StepTalk bundle names use:

names := NSBundle stepTalkBundleNames

Generic Bundles

To use scripting capabilities from any bundle, you have to find the bundle and include its capabilities in a scripting environment.

bundle := NSBundle bundleWithPath:'/path/to/my/bundle'.
Environment includeBundle:bundle.

This will register all public classes and named objects provided by the bundle.

To include scripting capabilities of all loaded bundles, do:

(NSBundle allBundles) do: [ :bundle | Environment includeBundle:bundle ]

To include scripting capabilities of all loaded frameworks, do:

(NSBundle allFrameworks) do: [ :bundle | Environment includeBundle:bundle ]

Note: Ignore the logs.

Advertisment

List public classes in bundle's info dictionary (Info.plist)

Classes = ( /* Array of public classes */ );

Named Objects

Bundles can provide objects like global variables or constants. To make objects available, create a script info class and provide it's name in bundle's info dictionary. Return a dictionary of named objects in specific class method.

Interface:

@interface MyBundleScriptingInfo:NSObject
+ (NSDictionary *)namedObjectsForScripting;
@end

Implementation:

@implementation !MyBundleScriptingInfo
+ (NSDictionary *)namedObjectsForScripting
{
    NSMutableDictionary *dictionary;

    /* ... fill the dictionary with objects ...*/

    return [[NSDictionary dictionaryWithDictionary:dictionary]; /* Return an immutable copy */
}
@end

Public classes

Then provide the class name in the file MyBundleInfo.plist:

ScriptingInfoClass = MyBundleScriptingInfo;

Example info dictionary:

{
    ScriptingInfoClass = ObjectiveCModule;
    Classes = (
        ObjectiveCRuntime
    );
}