Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tcl

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcl - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

57

lib/tcl.js

@@ -19,2 +19,3 @@

this._version = null;
this.$inject();

@@ -92,2 +93,48 @@ };

/**
* Alias for {@link Tcl#cmdSync}
*
* @method
* @see Tcl#cmdSync
*/
Tcl.prototype.$ = Tcl.prototype.cmdSync;
/**
* Inject Tcl commands (returned by `info commands`) as javascript functions
* into the object.
*/
Tcl.prototype.$inject = function () {
var self = this;
var cmds = self.$( 'info commands' ).toArray();
var inject = function ( cmd ) {
return function () {
var args = '';
for ( var i = 0; i < arguments.length; i++ ) {
args += ' ' + arguments[i];
}
return self.$( cmd + args );
};
};
cmds.forEach( function ( cmd ) {
self.$[ cmd ] = inject( cmd );
} );
};
/**
* load a Tcl module and refresh internal Tcl command references
*/
Tcl.prototype.load = function ( module ) {
var result = this.$( 'load {' + module + '}' );
this.$inject();
return result;
};
/**
* Add a Tcl command to the asynchronous processing queue. Each command

@@ -121,2 +168,12 @@ * added will be executed using a single worker thread outside of the

/**
* Source a Tcl script and refresh internal Tcl command references
*/
Tcl.prototype.source = function ( file ) {
var result = this.$( 'source {' + file + '}' );
this.$inject();
return result;
};
/**
* Returns the Tcl Interpreter version

@@ -123,0 +180,0 @@ *

5

package.json
{
"name": "tcl",
"version": "2.2.0",
"version": "2.3.0",
"description": "Node.js Tcl binding",

@@ -36,4 +36,5 @@ "main": "index.js",

"jshint": "^2.8.0",
"mocha": "^2.3.3"
"mocha": "^2.3.3",
"sinon": "^1.17.2"
}
}

145

README.md

@@ -13,8 +13,19 @@ node-tcl

## Dependencies
- Tcl development files (e.g. ```sudo apt-get install tcl-dev``` or ```sudo yum install tcl-devel```)
The build process will look for ```tclConfig.sh``` to identify Tcl include directory
and linker flags. If you are using a Tcl version older than 8.5 or want to link to a specific
Tcl installation use the ```TCLCONFIG``` environment variable to override the default behaviour
(e.g. ```export TCLCONFIG=/path/to/tclConfig.sh```).
### Optional Dependencies
- Tcl thread support (To enable async commands outside the main event loop)
- C++ compiler with support for c++11 features (To enable async command queues outside the main event loop)
## Installation
**Prerequisites :** You will need to have ```tcl-dev``` packages installed on
your system (e.g. ```sudo apt-get install tcl-dev```) for the Node.js native addon
to link to along with a c++11 compatible compiler (e.g. ```g++ v4.8```).
```sh

@@ -27,23 +38,86 @@ $ npm install --save tcl

You can execute any Tcl command supported by the Tcl shell (```tchsh```) and you
can even load native Tcl modeles (```load module.so```), source scripts
(```source filename.tcl```) and source Tcl libraries (```package require name```).
```js
var tcl = require( 'tcl' );
```
**Note :** Asynchronous commands (```cmd``` and ```eval```) are executed usng a
dedicated worker thread using a new Tcl Interpreter instance and comes with the
overhead of creating and destroying a Tcl Interpreter for each call. But these
executions are parallel and useful for batched tasks.
```js
var Tcl = require( 'tcl' ).Tcl;
var tcl = new Tcl();
```
### $( cmd ), cmdSync( cmd ), evalSync( cmd )
``` js
var tcl = require( 'tcl' );
Execute a Tcl command synchronously and returns a [Result](http://nukedzn.github.io/node-tcl/docs/Result.html).
// synchronous commands
console.log( tcl.version() );
console.log( tcl.cmdSync( 'info tclversion' ) );
console.log( tcl.evalSync( 'info tclversion' ) );
#### Parameters
| Name | Type | Description |
|------|--------|--------------------|
| cmd | String | Command to execute |
// asynchronous commands (parallelly executed in decated threads)
#### Example
```js
tcl.$( 'info version' );
```
### $.(tcl-command)( ... )
Execute a Tcl command using injected helper methods and returns a [Result](http://nukedzn.github.io/node-tcl/docs/Result.html).
#### Example
```js
tcl.$.info( 'tclversion' );
tcl.$.set( 'x', 10 );
tcl.$.expr( 22, '/', '7.0' );
```
### load( module )
Load a Tcl module and refresh injected helper methods.
#### Example
```js
tcl.load( 'libfoo.so' );
tcl.$.foo();
```
### source( file )
Source a Tcl script file and refresh injected helper methods.
#### Example
```js
tcl.source( '/path/to/multiply.tcl' );
tcl.$.multiply( 2, 3 );
```
### cmd( cmd, callback ), eval( cmd, callback )
Execute a Tcl command asynchronously using a new worker thread (A new Tcl interpreter
instance will be created for each call).
#### Parameters
| Name | Type | Description |
|----------|--------|--------------------|
| cmd | String | Command to execute |
| callback | [Callback](http://nukedzn.github.io/node-tcl/docs/Tcl.html#~cmdCallback) | Callback method to handle the response |
#### Example
```js
tcl.cmd( 'info tclversion', function ( err, result ) {
if ( err ) {
return console.log( err );
}
console.log( result.data() );

@@ -53,21 +127,38 @@ } );

tcl.eval( 'info commands', function ( err, result ) {
if ( err ) {
return console.log( err );
}
console.log( result.toArray() );
} );
```
// queued asynchronous commands (executed in a shared thread)
tcl.queue( 'set x 0' );
tcl.queue( 'incr $x', function ( err, result ) {
console.log( result );
} );
```
### queue( cmd, callback )
Execute a Tcl command asynchronously using a shared worker thread. A new Tcl interpreter
instance will be created for the worker thread but will be shared between calls.
#### Parameters
| Name | Type | Description |
|----------|--------|--------------------|
| cmd | String | Command to execute |
| callback | [Callback](http://nukedzn.github.io/node-tcl/docs/Tcl.html#~cmdCallback) | Callback method to handle the response |
#### Example
``` js
var Tcl = require( 'tcl' ).Tcl;
var tcl = new Tcl();
tcl.queue( 'set x 1' );
tcl.queue( 'incr x', function ( err, result ) {
if ( err ) {
return console.log( err );
}
console.log( tcl.version() );
console.log( result.data() ); // 2
} );
```
## API Documentation

@@ -74,0 +165,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc