Created
December 31, 2010 17:58
-
-
Save DanielG/761193 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
var fs = require('fs'); | |
var util = require('util'); | |
var Step = require('step'); | |
var Script = process.binding('evals').Script; | |
var loadModule = function loadModule(modulePath, callback){ | |
Step( | |
function fetchScript(){ | |
fs.readFile(modulePath, this); | |
} | |
, function eval(err, script){ | |
if(err) throw err; | |
var module = { | |
exports: {} | |
}; | |
var sandbox = { | |
module: module | |
exports: module.exports | |
require: require | |
}; | |
try { | |
var ret = Script.runInNewContext(script, sandbox, modulePath); | |
callback(sandbox); | |
} catch (e){ | |
callback(e); | |
} | |
} | |
); | |
} | |
exports.loadModule = loadModule; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment