summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 14:57:49 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-20 21:37:27 +0100
commit7d58c3b7314e4a63591fa375546cfc76a042e644 (patch)
treec51d390ee3830f924b2fb1e289b9461c8310d625 /src/lobject.js
parent5860ec2bde3b220eff01b3bd1462e60905ef2fe9 (diff)
downloadfengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.gz
fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.bz2
fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.zip
ldebug, lua_error, error
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 3a519c9..0a0b615 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -203,8 +203,46 @@ class CClosure extends TValue {
}
+const RETS = "...";
+const PRE = "[string \"";
+const POS = "\"]";
+
+const luaO_chunkid = function(source, bufflen) {
+ let l = source.length;
+ let out = "";
+ if (source[0] === '=') { /* 'literal' source */
+ if (l < bufflen) /* small enough? */
+ out = `${source.slice(1)}`;
+ else { /* truncate it */
+ out += `${source.slice(1, bufflen)}`;
+ }
+ } else if (source[0] === '@') { /* file name */
+ if (l <= bufflen) /* small enough? */
+ out = `${source.slice(1)}`;
+ else { /* add '...' before rest of name */
+ bufflen -= RETS.length;
+ out = `${RETS}${source.slice(1, l - bufflen)}`;
+ }
+ } else { /* string; format as [string "source"] */
+ let nli = source.indexOf('\n'); /* find first new line (if any) */
+ let nl = nli ? source.slice(nli) : null;
+ out = `${PRE}`; /* add prefix */
+ bufflen -= PRE.length - RETS.length; - POS.length + 1; /* save space for prefix+suffix+'\0' */
+ if (l < bufflen && nl === null) { /* small one-line source? */
+ out += `${source}`; /* keep it */
+ } else {
+ if (nl !== null) l = nl.length - source.length; /* stop at first newline */
+ if (l > bufflen) l = bufflen;
+ out += `${source}${RETS}`;
+ }
+ out += POS;
+ }
+
+ return out;
+};
-module.exports.LClosure = LClosure;
-module.exports.CClosure = CClosure;
-module.exports.TValue = TValue;
-module.exports.Table = Table; \ No newline at end of file
+module.exports.LClosure = LClosure;
+module.exports.CClosure = CClosure;
+module.exports.TValue = TValue;
+module.exports.Table = Table;
+module.exports.luaO_chunkid = luaO_chunkid; \ No newline at end of file