aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-21 22:18:35 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-21 23:53:46 +1000
commit04d5f8bada19aec5ae25038fc9b854f4614b974f (patch)
tree51942afeac4baa422a90762ec6799767ff411ebc /src
parent18d4eb3eda54ee4addb42d4e68039f2016305233 (diff)
downloadfengari-04d5f8bada19aec5ae25038fc9b854f4614b974f.tar.gz
fengari-04d5f8bada19aec5ae25038fc9b854f4614b974f.tar.bz2
fengari-04d5f8bada19aec5ae25038fc9b854f4614b974f.zip
src/lobject.js: Fix luaO_chunkid to actually return a short source name
Diffstat (limited to 'src')
-rw-r--r--src/lobject.js17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 3e5e536..5d3a984 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -230,15 +230,13 @@ const PRE = defs.to_luastring("[string \"");
const POS = defs.to_luastring("\"]");
const luaO_chunkid = function(source, bufflen) {
- source = source instanceof TValue ? source.value : source;
- bufflen = bufflen instanceof TValue ? bufflen.value : bufflen;
let l = source.length;
- let out = [];
+ let out;
if (source[0] === char['=']) { /* 'literal' source */
if (l < bufflen) /* small enough? */
out = source.slice(1);
else { /* truncate it */
- out = out.concat(source.slice(1, bufflen));
+ out = source.slice(1, bufflen);
}
} else if (source[0] === char['@']) { /* file name */
if (l <= bufflen) /* small enough? */
@@ -249,19 +247,16 @@ const luaO_chunkid = function(source, bufflen) {
}
} else { /* string; format as [string "source"] */
let nli = source.indexOf(char['\n']); /* find first new line (if any) */
- let nl = nli > -1 ? 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 = out.concat(source); /* keep it */
+ if (l < bufflen && nli === -1) { /* small one-line source? */
+ out = out.concat(source, POS); /* keep it */
} else {
- if (nl !== null) l = nl.length - source.length; /* stop at first newline */
+ if (nli !== -1) l = nli; /* stop at first newline */
if (l > bufflen) l = bufflen;
- out = out.concat(source).concat(RETS);
+ out = out.concat(source.slice(0, l), RETS, POS);
}
- out = out.concat(POS);
}
-
return out;
};