mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
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.
47 lines
1.0 KiB
C++
47 lines
1.0 KiB
C++
|
|
#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
|