mirror of https://github.com/lukechilds/node.git
Browse Source
Set the stage for making the builtin modules more dynamic. Note: this only converts crypto and net, I will add more extensions in a later commit. * node.h: Add utility macro for converting macro values to strings. * node.h: Include the actual module name inside the module structure, not just the file it was built from. * node.h: New Macro, NODE_MODULE_DECL, for declaring an external reference to a module structure. * node_extensions.cc: New File, implements get_builtin_module, which iterates over the module structures that are compiled into node. * node.cc(node::Binding): Use the new module lookup function to find modules. * node_{net,crypto}.c: Add NODE_MODULEs to generate the module structure.v0.7.4-release
Paul Querna
15 years ago
committed by
Ryan Dahl
7 changed files with 83 additions and 27 deletions
@ -0,0 +1,46 @@ |
|||
|
|||
#include "node.h" |
|||
#include "node_version.h" |
|||
#include <string.h> |
|||
|
|||
#undef NODE_EXT_LIST_START |
|||
#undef NODE_EXT_LIST_ITEM |
|||
#undef NODE_EXT_LIST_END |
|||
|
|||
#define NODE_EXT_LIST_START |
|||
#define NODE_EXT_LIST_ITEM NODE_MODULE_DECL |
|||
#define NODE_EXT_LIST_END |
|||
|
|||
#include "node_extensions.h" |
|||
|
|||
#undef NODE_EXT_LIST_START |
|||
#undef NODE_EXT_LIST_ITEM |
|||
#undef NODE_EXT_LIST_END |
|||
|
|||
#define NODE_EXT_STRING(x) &x ## _module, |
|||
#define NODE_EXT_LIST_START node::node_module_struct *node_module_list[] = { |
|||
#define NODE_EXT_LIST_ITEM NODE_EXT_STRING |
|||
#define NODE_EXT_LIST_END NULL}; |
|||
|
|||
#include "node_extensions.h" |
|||
|
|||
namespace node { |
|||
|
|||
node_module_struct* get_builtin_module(const char *name) |
|||
{ |
|||
char buf[128]; |
|||
node_module_struct *cur = NULL; |
|||
snprintf(buf, sizeof(buf), "node_%s", name); |
|||
/* TODO: you could look these up in a hash, but there are only
|
|||
* a few, and once loaded they are cached. */ |
|||
for (int i = 0; node_module_list[i] != NULL; i++) { |
|||
cur = node_module_list[i]; |
|||
if (strcmp(cur->modname, buf) == 0) { |
|||
return cur; |
|||
} |
|||
} |
|||
|
|||
return NULL; |
|||
} |
|||
|
|||
}; // namespace node
|
@ -0,0 +1,8 @@ |
|||
|
|||
NODE_EXT_LIST_START |
|||
NODE_EXT_LIST_ITEM(node_net) |
|||
#ifdef HAVE_OPENSSL |
|||
NODE_EXT_LIST_ITEM(node_crypto) |
|||
#endif |
|||
NODE_EXT_LIST_END |
|||
|
Loading…
Reference in new issue