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/lapi.js | |
parent | c762a38820fba43b2ca041a78ab2931631a0b5fd (diff) | |
download | fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.tar.gz fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.tar.bz2 fengari-0cbdb3527041d016097aa3384af9c5908af2cce6.zip |
lua_dump, string.dump
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lapi.js b/src/lapi.js index 96fe207..a51796b 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -4,6 +4,7 @@ const assert = require('assert'); const ldebug = require('./ldebug.js'); const ldo = require('./ldo.js'); +const ldump = require('./ldump.js'); const lfunc = require('./lfunc.js'); const llex = require('./llex.js'); const lobject = require('./lobject.js'); @@ -239,6 +240,18 @@ const lua_pushstring = function (L, s) { return s; }; +// Push string without 8-bit conversion +const lua_pushrawstring = function(L, s) { + if (typeof s !== "string") + L.stack[L.top] = ldo.nil; + else { + L.stack[L.top] = new TValue(CT.LUA_TLNGSTR, s.split('').map(e => e.charCodeAt(0))); + } + L.top++; + assert(L.top <= L.ci.top, "stack overflow"); + return s; +}; + const lua_pushliteral = lua_pushstring; const lua_pushcclosure = function(L, fn, n) { @@ -693,6 +706,14 @@ const lua_load = function(L, reader, data, chunckname, mode) { return status; }; +const lua_dump = function(L, writer, data, strip) { + assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack"); + let o = L.stack[L.top -1]; + if (o.ttisLclosure()) + return ldump.luaU_dump(L, o.p, writer, data, strip); + return 1; +}; + const lua_status = function(L) { return L.status; }; @@ -835,6 +856,7 @@ module.exports.lua_compare_ = lua_compare_; module.exports.lua_concat = lua_concat; module.exports.lua_copy = lua_copy; module.exports.lua_createtable = lua_createtable; +module.exports.lua_dump = lua_dump; module.exports.lua_error = lua_error; module.exports.lua_gc = lua_gc; module.exports.lua_getallocf = lua_getallocf; @@ -871,6 +893,7 @@ module.exports.lua_pushliteral = lua_pushliteral; module.exports.lua_pushlstring = lua_pushlstring; module.exports.lua_pushnil = lua_pushnil; module.exports.lua_pushnumber = lua_pushnumber; +module.exports.lua_pushrawstring = lua_pushrawstring; module.exports.lua_pushstring = lua_pushstring; module.exports.lua_pushthread = lua_pushthread; module.exports.lua_pushtvalue = lua_pushtvalue; |