Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created December 31, 2010 17:58
Show Gist options
  • Save DanielG/761193 to your computer and use it in GitHub Desktop.
Save DanielG/761193 to your computer and use it in GitHub Desktop.
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