summaryrefslogtreecommitdiff
path: root/src/lauxlib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-03 13:51:20 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-03 15:07:21 +0200
commit278fd3edb6ead6cd65c2293f823887d19e4fbc8e (patch)
tree3ad7b42a93bd51d856e0ccef43395fa1b64fe890 /src/lauxlib.js
parentd231ed14d0816eb26856e948a9ab72f64d46c1eb (diff)
downloadfengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.tar.gz
fengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.tar.bz2
fengari-278fd3edb6ead6cd65c2293f823887d19e4fbc8e.zip
require
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r--src/lauxlib.js7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index d5b69f9..ff8a500 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -561,14 +561,13 @@ const find_subarray = function(arr, subarr, from_index) {
const luaL_gsub = function(L, s, p, r) {
let wild;
- let i = 0;
let b = [];
while ((wild = find_subarray(s, p)) >= 0) {
- b.push(...s.slice(i, wild)); /* push prefix */
+ b.push(...s.slice(0, wild)); /* push prefix */
b.push(...r); /* push replacement in place of pattern */
- i = wild + p.length; /* continue after 'p' */
+ s = s.slice(wild + p.length); /* continue after 'p' */
}
- b.push(s.slice(i)); /* push last suffix */
+ b.push(...s); /* push last suffix */
lua.lua_pushstring(L, b);
return lua.lua_tostring(L, -1);
};