diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-12 22:49:41 +0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-12 22:49:41 +0400 |
commit | c4636a578cee61a8a3b570146e168f7dffec9998 (patch) | |
tree | 1c9cd0f96ebb748e9cdbb8ea50ab7a11cba2faa9 /tools | |
parent | 901d5fd0d2475f8f912f9a73d14805d6898c8e02 (diff) |
Dynamically load native scripts
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/js2c.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/js2c.py b/tools/js2c.py index 64e5c2b625e..db4885553bb 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -211,13 +211,30 @@ namespace node { %(source_lines)s\ +struct _native { + const char* name; + const char* source; +}; + +static const struct _native natives[] = { + +%(native_lines)s\ + + { NULL, NULL } /* sentinel */ + +}; + } #endif """ +NATIVE_DECLARATION = """\ + { "%(id)s", %(id)s_native }, +""" + SOURCE_DECLARATION = """\ - static const char native_%(id)s[] = { %(data)s }; + const char %(id)s_native[] = { %(data)s }; """ @@ -252,6 +269,9 @@ def JS2C(source, target): # Build source code lines source_lines = [ ] source_lines_empty = [] + + native_lines = [] + for s in modules: delay = str(s).endswith('-delay.js') lines = ReadFile(str(s)) @@ -269,6 +289,7 @@ def JS2C(source, target): ids.append((id, len(lines))) source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': 0 }) + native_lines.append(NATIVE_DECLARATION % { 'id': id }) # Build delay support functions get_index_cases = [ ] @@ -312,6 +333,7 @@ def JS2C(source, target): 'builtin_count': len(ids) + len(delay_ids), 'delay_count': len(delay_ids), 'source_lines': "\n".join(source_lines), + 'native_lines': "\n".join(native_lines), 'get_index_cases': "".join(get_index_cases), 'get_script_source_cases': "".join(get_script_source_cases), 'get_script_name_cases': "".join(get_script_name_cases) |