diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-17 07:56:18 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann@users.noreply.github.com> | 2017-03-17 10:36:57 +0100 |
commit | 0cbdb3527041d016097aa3384af9c5908af2cce6 (patch) | |
tree | 599980a9095ec8c3c4348ae1edf41170845e1832 /src/lstrlib.js | |
parent | c762a38820fba43b2ca041a78ab2931631a0b5fd (diff) | |
download | fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.tar.gz fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.tar.bz2 fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.zip |
lua_dump, string.dump
Diffstat (limited to 'src/lstrlib.js')
-rw-r--r-- | src/lstrlib.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js index b47138f..83e82b0 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -48,6 +48,23 @@ const str_char = function(L) { return 1; }; +const writer = function(L, b, size, B) { + assert(Array.isArray(b)); + B.push(...b.slice(0, size)); + return 0; +}; + +const str_dump = function(L) { + let b = []; + let strip = lapi.lua_toboolean(L, 2); + lauxlib.luaL_checktype(L, 1, CT.LUA_TFUNCTION); + lapi.lua_settop(L, 1); + if (lapi.lua_dump(L, writer, b, strip) !== 0) + return lauxlib.luaL_error(L, "unable to dump given function"); + lapi.lua_pushrawstring(L, b.map(e => String.fromCharCode(e)).join('')); + return 1; +}; + const SIZELENMOD = luaconf.LUA_NUMBER_FRMLEN.length; const L_NBFD = 16; // TODO: arbitrary @@ -379,6 +396,7 @@ const str_byte = function(L) { const strlib = { "byte": str_byte, "char": str_char, + "dump": str_dump, "format": str_format, "len": str_len, "lower": str_lower, |