Skip to content

feenkcom/PharoLink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PharoLink

PharoLink provides a mechanism for Pharo to communicate with remote Pharo processes.

Getting Started

Installation

PharoLink is already installed if you are using Gtoolkit.

Requirements:

PharoLink has been tested with Pharo 8 & 9.

To install PharoLink evaluate:

EpMonitor disableDuring: [ 
Metacello new
	repository: 'github://feenkcom/PharoLink:main/src';
	baseline: 'PharoLink';
	load ]

First statements

The playground examples pictured below assume you are running Gtoolkit. If you are running a vanilla Pharo image, the programmatic examples can be used.

Open a playground in Gtoolkit and start the PharoLinkApplication:

Start PharoLink

We can now evaluate our first expression in the remote server:

First Object

After typing the code in to the playground it is evaluated by pressing the play & inspect button:

Play & Inspect button

From here we can navigate through the attributes of the object in the same way as when inspecting pharo objects.

If the value of the attribute is a non-primitive object, a proxy will be returned, if it is a primitive, it will be returned directly:

Inspect Primitive

As well as inspecting the raw values of the remote object, any views which can be represented declaratively, or which have been explicitly specified by the remote object will also be displayed, e.g. the String, List and Columned List views shown below:

Declarative Views

When evaluating statements in a proxy object's playground, self is bound to the proxy object:

self bound

The remote server can then be stopped with:

PharoLinkApplication stop.

Programatic Use

So far we have been using a global instance of PharoLink, however it is also possible to have multiple servers running concurrently through the use of private instances.

PharoLink allows Pharo code to be supplied in two ways:

  1. Strings of code, and
  2. AST objects generated using RBParser

First, using strings:

"Start PharoLink"
pharolink := PharoLinkApplication withDefaultSettings.
pharolink start.

"Create an instance of the test inspectable and retrieve the string"
object := pharolink newCommandFactory
	<< 'GtDeclarativeTestInspectable new';
	sendAndWait.

date := object newCommandFactory
	<< 'self collectionOfObjects second';
	sendAndWait.

"Stop the server"
pharolink stop

Hello, World!

Second, using Smalltalk generated with RBParser:

"Start PharoLink"
pharolink := PharoLinkApplication withDefaultSettings.
pharolink start.

"Generate the expression and evaluate"
node := RBParser parseExpression: 
	'| inspectable hw |
	inspectable := GtDeclarativeTestInspectable new.
	hw := inspectable collectionOfObjects second.
	hw'.

date := pharolink newCommandFactory
	<< node;
	sendAndWait.

"Stop the server"
pharolink stop

Hello, World! with RBParser

Garbage Collection

Proxy objects register them selves for finalisation. When they are garbage collected in Pharo they are automatically removed from the registry in the node.js server.

Callbacks

Callbacks in to Pharo from the remote server are supported through observables.

See PharoLinkSendCommandTest for examples of setting up and using callbacks.

Automated Tests

See the 'PharoLink-Tests` package.

ToDo

PythonBridge supports communicating with the server using either HTTP or MsgPack. While the code has been left in the package, MsgPack is not yet supported.

Futures

TBS.

Acknowledgements and Thanks

Thanks to the team at ObjectProfile for making PythonBridge, on which PharoLink is based.