This package has been deprecated

Author message:

This was a joke package that I still think is funny but it never went anywhere.

laudanumscript

0.0.0 • Public • Published

laudanumscript

cpp for your javascript. literally.

install:

npm install laudanumscript

example:

The test is an example. It includes two DSL-ish macros, compiles, and asserts that the macros did what was expected of them.

Here are the two "header files":

bound.lsh

This macro gives you a block called BOUND which binds THIS to scope in a way (at least superficially) similar to "fat arrow":

#ifndef __bound__
#define __bound__

self = this;

#define THIS (typeof self !== "undefined" && self !== null ? self : this)

#define BOUND(...) function (__VA_ARGS__) { var self = this;
#define ENDBOUND };

#endif

clos.lsh

This macro creates some syntactic syrup for creating immediately-invoked function expressions:

#ifndef __clos__
#define __clos__

#define CLOS (function () {
#define ENDCLOS })()

#endif

index.ls

Here's the main file:

#include "include/bound.lsh"
#include "include/clos.lsh"

var assert = require('assert');

var test = BOUND(a, b, c)
  assert(THIS.fxn == 'test', "THIS.fxn == 'test'");
  assert(a == 1 && b == 2 && c == 3, "correct args passed into BOUND");
  CLOS
    assert(globallyScoped(this), "this is globally scoped as expected");
    assert(self.fxn == 'test', "self.fxn = 'test'");
    assert(THIS.fxn == 'test', "THIS.fxn == 'test'");
  ENDCLOS

  console.log('Congratulations! All tests passed!');
ENDBOUND

// Easy test
function globallyScoped(obj) {
  return !!(obj.GLOBAL && obj.process);
}

test.call({
  "fxn": "test"
}, 1,2,3);

Makefile

laudanum is makefile-friendly:

all: clean index.js

index.js:
    ../bin/laudanum index.ls

clean:
    rm index.js

test:
    node index.js

Run it!

$ make
../bin/laudanum index.ls
josh@onix:/tmp/jscpp/test$ node index.js
Congratulations! All tests passed!

Or, alternately, compile AND run in one fell swoop:

$ ../bin/laudanum --run index.ls
Congratulations! All tests passed!

run the tests:

make test

license:

MIT/X11

Readme

Keywords

none

Package Sidebar

Install

npm i laudanumscript

Weekly Downloads

1

Version

0.0.0

License

none

Last publish

Collaborators

  • jfhbrook