Created
September 5, 2013 12:01
-
-
Save kaosat-dev/6449222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#see https://github.com/joyent/node/blob/master/src/node.js#L367 | |
#and http://stackoverflow.com/questions/9475792/how-does-require-in-node-js-work | |
#and https://github.com/joyent/node/blob/906a175a0b40fc56dfafbe0929e4fbbb4df68ff2/src/node.js#L699 | |
globals = {} | |
class Module | |
constructor:-> | |
@exports = {} | |
@content = "" | |
compile:()-> | |
#f = new Function( wrapper ) | |
#toto = f(globals, module, assembly) | |
#f = new Function(["module","assembly"], wrapper ) | |
#toto = f.apply(null, [module,assembly]) | |
wrap:(script)-> | |
wrapped = """ | |
return (function ( exports, include, module, , __filename, __dirname) | |
{ | |
console.log("exports",exports, "module",module); | |
//#{script} | |
}); | |
""" | |
return wrapped | |
class Assembly | |
constructor:-> | |
@contents = [] | |
add:(item)=> | |
@contents.push( item ) | |
module = new Module() | |
assembly = new Assembly() | |
script = """ | |
//assembly.add( "toto") | |
module.exports = 24 | |
""" | |
wrapper = """ | |
return (function ( exports, include, module, , __filename, __dirname) | |
{ | |
console.log("assembly",assembly, "module",module); | |
//#{script} | |
//console.log(assembly); | |
}); | |
""" | |
#console.log toto | |
#toto(module, assembly) | |
#console.log wrapper | |
#console.log module | |
#console.log assembly | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]" /> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment