summaryrefslogtreecommitdiff
path: root/src/lutf8lib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-29 11:57:43 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-03-29 14:37:07 +0200
commit2e5b595a2e04fe72555a565af4aae43560946473 (patch)
tree750e770114181283acb0fd78f7ad241c17c3d9a7 /src/lutf8lib.js
parent36f3247d47c1ad854fa89aabf17f6d954a6a6657 (diff)
downloadfengari-2e5b595a2e04fe72555a565af4aae43560946473.tar.gz
fengari-2e5b595a2e04fe72555a565af4aae43560946473.tar.bz2
fengari-2e5b595a2e04fe72555a565af4aae43560946473.zip
Never use js strings internally
Diffstat (limited to 'src/lutf8lib.js')
-rw-r--r--src/lutf8lib.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index 053fb56..1df6096 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -91,8 +91,8 @@ const utflen = function(L) {
let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), s.length);
let posj = u_posrelat(lauxlib.luaL_optinteger(L, 3, -1), s.length);
- lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 2, "initial position out of string");
- lauxlib.luaL_argcheck(L, --posj < s.length, 3, "final position out of string");
+ lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 2, lua.to_luastring("initial position out of string"));
+ lauxlib.luaL_argcheck(L, --posj < s.length, 3, lua.to_luastring("final position out of string"));
lapi.lua_pushinteger(L, s.slice(posi, posj + 1).length);
return 1;
@@ -100,7 +100,7 @@ const utflen = function(L) {
const pushutfchar = function(L, arg) {
let code = lauxlib.luaL_checkinteger(L, arg);
- lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range");
+ lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, lua.to_luastring("value out of range"));
lapi.lua_pushstring(L, `${String.fromCharCode(code)}`);
};
@@ -134,14 +134,14 @@ const byteoffset = function(L) {
let posi = n >= 0 ? 1 : s.length + 1;
posi = u_posrelat(lauxlib.luaL_optinteger(L, 3, posi), s.length);
- lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, "position ot ouf range");
+ lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, lua.to_luastring("position ot ouf range"));
if (n === 0) {
/* find beginning of current byte sequence */
while (posi > 0 && iscont(s[posi])) posi--;
} else {
if (iscont(s[posi]))
- lauxlib.luaL_error(L, "initial position is a continuation byte");
+ lauxlib.luaL_error(L, lua.to_luastring("initial position is a continuation byte"));
if (n < 0) {
while (n < 0 && posi > 0) { /* move back */
@@ -179,19 +179,19 @@ const codepoint = function(L) {
let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), s.length);
let pose = u_posrelat(lauxlib.luaL_optinteger(L, 3, posi), s.length);
- lauxlib.luaL_argcheck(L, posi >= 1, 2, "out of range");
- lauxlib.luaL_argcheck(L, pose <= s.length, 3, "out of range");
+ lauxlib.luaL_argcheck(L, posi >= 1, 2, lua.to_luastring("out of range"));
+ lauxlib.luaL_argcheck(L, pose <= s.length, 3, lua.to_luastring("out of range"));
if (posi > pose) return 0; /* empty interval; return no values */
if (pose - posi >= Number.MAX_SAFE_INTEGER)
- return lauxlib.luaL_error(L, "string slice too long");
+ return lauxlib.luaL_error(L, lua.to_luastring("string slice too long"));
let n = (pose - posi) + 1;
- lauxlib.luaL_checkstack(L, n, "string slice too long");
+ lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long"));
n = 0;
for (s = s.slice(posi - 1); n < pose - posi;) {
let dec = utf8_decode(s);
if (dec === null)
- return lauxlib.luaL_error(L, "invalid UTF-8 code");
+ return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code"));
s = dec.string;
let code = dec.code;
lapi.lua_pushinteger(L, code);
@@ -220,7 +220,7 @@ const iter_aux = function(L) {
let code = dec ? dec.code : null;
let next = dec ? dec.string : null;
if (next === null || iscont(next[0]))
- return lauxlib.luaL_error(L, "invalid UTF-8 code");
+ return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code"));
lapi.lua_pushinteger(L, n + 1);
lapi.lua_pushinteger(L, code);
return 2;
@@ -253,4 +253,4 @@ const luaopen_utf8 = function(L) {
return 1;
};
-module.exports.luaopen_utf8 = luaopen_utf8; \ No newline at end of file
+module.exports.luaopen_utf8 = luaopen_utf8;