Skip to content
cpp for your javascript. literally.
LiveScript Shell Makefile
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin
test
README.md
package.json

README.md

laudanumscript

cpp for your javascript. literally.

Praise for Laudanum:

"its liek when your gf confuses star trek with starwars.. thats what you're doing lol" --@blakmatrix

"this makes my eyes bleed" --@mmalecki

"Let me tell you something about dynamic languages. You don't need a preprocessor." --@marak

"I can almost see #include s being useful" --@jfhbrook

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: 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

Something went wrong with that request. Please try again.