mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-21 02:33:24 +00:00
Compressed integrated JavaScript
This commit is contained in:
@@ -115,6 +115,7 @@ char *Duktape_Duplicate_GetStringEx(duk_context *ctx, duk_idx_t i, duk_size_t *l
|
|||||||
#define duk_table_hasKey(ctx, i, key) duk_has_prop_string(ctx, i, key)
|
#define duk_table_hasKey(ctx, i, key) duk_has_prop_string(ctx, i, key)
|
||||||
#define duk_table_delKey(ctx, i, key) duk_del_prop_string(ctx, i, key)
|
#define duk_table_delKey(ctx, i, key) duk_del_prop_string(ctx, i, key)
|
||||||
|
|
||||||
|
#define duk_buffer_concat(ctx) duk_push_global_object(ctx);duk_get_prop_string(ctx,-1,"Buffer");duk_remove(ctx,-2);duk_get_prop_string(ctx, -1, "concat");duk_swap_top(ctx, -2);duk_dup(ctx, -3);duk_call_method(ctx,1);duk_remove(ctx, -2);
|
||||||
#define duk_buffer_slice(ctx, i, start, len) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "slice");duk_swap_top(ctx, -2);duk_push_int(ctx, start);duk_push_int(ctx, len);duk_pcall_method(ctx, 2);duk_remove(ctx, -2);
|
#define duk_buffer_slice(ctx, i, start, len) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "slice");duk_swap_top(ctx, -2);duk_push_int(ctx, start);duk_push_int(ctx, len);duk_pcall_method(ctx, 2);duk_remove(ctx, -2);
|
||||||
#define duk_string_concat(ctx, i) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "concat");duk_swap_top(ctx, -2);duk_dup(ctx, -3);duk_pcall_method(ctx, 1);duk_remove(ctx, -2);
|
#define duk_string_concat(ctx, i) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "concat");duk_swap_top(ctx, -2);duk_dup(ctx, -3);duk_pcall_method(ctx, 1);duk_remove(ctx, -2);
|
||||||
#define duk_string_split(ctx, i, delim) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "split");duk_swap_top(ctx, -2);duk_push_string(ctx, delim);duk_call_method(ctx, 1);
|
#define duk_string_split(ctx, i, delim) duk_dup(ctx, i);duk_get_prop_string(ctx, -1, "split");duk_swap_top(ctx, -2);duk_push_string(ctx, delim);duk_call_method(ctx, 1);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -29,6 +29,42 @@ var CF_UNICODETEXT = 13;
|
|||||||
|
|
||||||
var xclipTable = {};
|
var xclipTable = {};
|
||||||
|
|
||||||
|
function nativeAddCompressedModule(name)
|
||||||
|
{
|
||||||
|
var value = getJSModule(name);
|
||||||
|
var zip = require('compressed-stream').createCompressor();
|
||||||
|
zip.buffer = null;
|
||||||
|
zip.on('data', function (c)
|
||||||
|
{
|
||||||
|
if(this.buffer == null)
|
||||||
|
{
|
||||||
|
this.buffer = Buffer.concat([c]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.buffer = Buffer.concat([this.buffer, c]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
zip.end(value);
|
||||||
|
var vstring = zip.buffer.toString('base64');
|
||||||
|
var ret = "duk_peval_string_noresult(ctx, \"addCompressedModule('" + name + "', Buffer.from('" + vstring + "', 'base64'));\");";
|
||||||
|
if (ret.length > 16300)
|
||||||
|
{
|
||||||
|
// MS Visual Studio has a maxsize limitation
|
||||||
|
var tmp = vstring;
|
||||||
|
ret = 'char *_' + name.split('-').join('') + ' = ILibMemory_Allocate(' + (tmp.length + value.length + 2) + ', 0, NULL, NULL);\n';
|
||||||
|
var i = 0;
|
||||||
|
while (i < tmp.length)
|
||||||
|
{
|
||||||
|
var chunk = tmp.substring(i, i + 16000);
|
||||||
|
ret += ('memcpy_s(_' + name.split('-').join('') + ' + ' + i + ', ' + (tmp.length - i) + ', "' + chunk + '", ' + chunk.length + ');\n');
|
||||||
|
i += chunk.length;
|
||||||
|
}
|
||||||
|
ret += ('ILibDuktape_AddCompressedModule(ctx, "' + name + '", _' + name.split('-').join('') + ');\n');
|
||||||
|
ret += ('free(_' + name.split('-').join('') + ');\n');
|
||||||
|
}
|
||||||
|
module.exports(ret);
|
||||||
|
}
|
||||||
function nativeAddModule(name)
|
function nativeAddModule(name)
|
||||||
{
|
{
|
||||||
var value = getJSModule(name);
|
var value = getJSModule(name);
|
||||||
@@ -596,5 +632,6 @@ switch(process.platform)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
module.exports.nativeAddModule = nativeAddModule;
|
module.exports.nativeAddModule = nativeAddModule;
|
||||||
|
module.exports.nativeAddCompressedModule = nativeAddCompressedModule;
|
||||||
module.exports.dispatchWrite = dispatchWrite;
|
module.exports.dispatchWrite = dispatchWrite;
|
||||||
module.exports.dispatchRead = dispatchRead;
|
module.exports.dispatchRead = dispatchRead;
|
||||||
Reference in New Issue
Block a user