From 83de14b90b5f5c80a168d317cf41884aa20a24a0 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Fri, 15 Dec 2017 16:25:27 +1100
Subject: src/defs.js: Automatically convert js strings

---
 src/defs.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/defs.js b/src/defs.js
index a2c5c75..c231c3d 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -248,7 +248,9 @@ const to_luastring = function(str, cache) {
 };
 
 const from_userstring = function(str) {
-    assert(is_luastring(str), "expects an array of bytes");
+    if (typeof str === "string")
+        return to_luastring(str);
+    assert(is_luastring(str), "expects an array of bytes or javascript string");
     return str;
 };
 
-- 
cgit v1.2.3-70-g09d2


From eb214f05b57f2fe0e980d54a0573167b20c218d8 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Thu, 28 Dec 2017 23:14:48 +1100
Subject: src/lauxlib.js: luaL_checkstring is just luaL_checklstring

---
 src/lauxlib.js | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/lauxlib.js b/src/lauxlib.js
index e6d407f..b4d839d 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -315,16 +315,14 @@ const luaL_checktype = function(L, arg, t) {
         tag_error(L, arg, t);
 };
 
-const luaL_checkstring = function(L, n) {
-    return luaL_checklstring(L, n, null);
-};
-
 const luaL_checklstring = function(L, arg) {
     let s = lua.lua_tolstring(L, arg);
     if (s === null || s === undefined) tag_error(L, arg, lua.LUA_TSTRING);
     return s;
 };
 
+const luaL_checkstring = luaL_checklstring;
+
 const luaL_optlstring = function(L, arg, def) {
     if (lua.lua_type(L, arg) <= 0) {
         return def;
-- 
cgit v1.2.3-70-g09d2


From f9375fcb71171d7b18190fa59ec402f7f68e26dd Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Fri, 29 Dec 2017 00:47:42 +1100
Subject: src/lauxlib.js: Convert default argument to luaL_optlstring on demand

---
 src/lauxlib.js | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src')

diff --git a/src/lauxlib.js b/src/lauxlib.js
index b4d839d..8cb608d 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -325,6 +325,8 @@ const luaL_checkstring = luaL_checklstring;
 
 const luaL_optlstring = function(L, arg, def) {
     if (lua.lua_type(L, arg) <= 0) {
+        if (typeof str === "string")
+            def = lua.to_luastring(def);
         return def;
     } else return luaL_checklstring(L, arg);
 };
-- 
cgit v1.2.3-70-g09d2


From c93673f0af0ebdc5165cf0acc340f65b6c6fa786 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Fri, 29 Dec 2017 00:48:15 +1100
Subject: src/: Pass js string to luaL_opt(l)string

---
 src/lbaselib.js | 6 +++---
 src/ldblib.js   | 2 +-
 src/loadlib.js  | 4 ++--
 src/loslib.js   | 2 +-
 src/lstrlib.js  | 2 +-
 src/ltablib.js  | 2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)

(limited to 'src')

diff --git a/src/lbaselib.js b/src/lbaselib.js
index 86ba6cc..d000ae4 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -108,7 +108,7 @@ const opts = [
     "isrunning"
 ].map((e) => lua.to_luastring(e));
 const luaB_collectgarbage = function(L) {
-    lauxlib.luaL_checkoption(L, 1, lua.to_luastring("collect"), opts);
+    lauxlib.luaL_checkoption(L, 1, "collect", opts);
     lauxlib.luaL_optinteger(L, 2, 0);
     lauxlib.luaL_error(L, lua.to_luastring("lua_gc not implemented"));
 };
@@ -341,14 +341,14 @@ const generic_reader = function(L, ud) {
 
 const luaB_load = function(L) {
     let s = lua.lua_tostring(L, 1);
-    let mode = lauxlib.luaL_optstring(L, 3, lua.to_luastring("bt", true));
+    let mode = lauxlib.luaL_optstring(L, 3, "bt");
     let env = !lua.lua_isnone(L, 4) ? 4 : 0;  /* 'env' index or 0 if no 'env' */
     let status;
     if (s !== null) {  /* loading a string? */
         let chunkname = lauxlib.luaL_optstring(L, 2, s);
         status = lauxlib.luaL_loadbufferx(L, s, s.length, chunkname, mode);
     } else {  /* loading from a reader function */
-        let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
+        let chunkname = lauxlib.luaL_optstring(L, 2, "=(load)");
         lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
         lua.lua_settop(L, RESERVEDSLOT);  /* create reserved slot */
         status = lua.lua_load(L, generic_reader, null, chunkname, mode);
diff --git a/src/ldblib.js b/src/ldblib.js
index e687ec1..eb64b03 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -120,7 +120,7 @@ const db_getinfo = function(L) {
     let thread = getthread(L);
     let arg = thread.arg;
     let L1 = thread.thread;
-    let options = lauxlib.luaL_optstring(L, arg + 2, lua.to_luastring("flnStu", true));
+    let options = lauxlib.luaL_optstring(L, arg + 2, "flnStu");
     checkstack(L, L1, 3);
     if (lua.lua_isfunction(L, arg + 1)) {  /* info about a function? */
         options = lua.lua_pushfstring(L, lua.to_luastring(">%s"), options);  /* add '>' to 'options' */
diff --git a/src/loadlib.js b/src/loadlib.js
index 0be1742..53d764b 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -294,8 +294,8 @@ const ll_searchpath = function(L) {
         L,
         lauxlib.luaL_checkstring(L, 1),
         lauxlib.luaL_checkstring(L, 2),
-        lauxlib.luaL_optstring(L, 3, lua.to_luastring(".")),
-        lauxlib.luaL_optstring(L, 4, lua.to_luastring(lua.LUA_DIRSEP))
+        lauxlib.luaL_optstring(L, 3, "."),
+        lauxlib.luaL_optstring(L, 4, lua.LUA_DIRSEP)
     );
     if (f !== null) return 1;
     else {  /* error message is on top of the stack */
diff --git a/src/loslib.js b/src/loslib.js
index ecd42f1..99e5787 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -86,7 +86,7 @@ const checkoption = function(L, conv, i, buff) {
 
 
 const os_date = function(L) {
-    let s = lauxlib.luaL_optlstring(L, 1, lua.to_luastring("%c"));
+    let s = lauxlib.luaL_optlstring(L, 1, "%c");
     let t = lauxlib.luaL_opt(L, l_checktime, 2, new Date().getTime() / 1000) * 1000;
     let stm = new Date(t);
     let utc = false;
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 362942d..a8a017f 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -617,7 +617,7 @@ const str_rep = function(L) {
     let s = lauxlib.luaL_checkstring(L, 1);
     let l = s.length;
     let n = lauxlib.luaL_checkinteger(L, 2);
-    let sep = lauxlib.luaL_optstring(L, 3, lua.to_luastring(""));
+    let sep = lauxlib.luaL_optstring(L, 3, "");
     let lsep = sep.length;
     if (n <= 0) lua.lua_pushliteral(L, "");
     else if (l + lsep < l || l + lsep > MAXSIZE / n)  /* may overflow? */
diff --git a/src/ltablib.js b/src/ltablib.js
index 70ff595..56671c4 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -130,7 +130,7 @@ const tmove = function(L) {
 
 const tconcat = function(L) {
     let last = aux_getn(L, 1, TAB_R);
-    let sep = lauxlib.luaL_optlstring(L, 2, lua.to_luastring(""));
+    let sep = lauxlib.luaL_optlstring(L, 2, "");
     let i = lauxlib.luaL_optinteger(L, 3, 1);
     last = lauxlib.luaL_optinteger(L, 4, last);
 
-- 
cgit v1.2.3-70-g09d2


From 1371afafae9144b30475262f06940c4057485d02 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Fri, 29 Dec 2017 02:31:22 +1100
Subject: src/: Pass js strings to auxlib functions such as luaL_argcheck

---
 src/lbaselib.js            | 10 +++++-----
 src/lcorolib.js            |  2 +-
 src/ldblib.js              | 14 +++++++-------
 src/lmathlib.js            | 12 ++++++------
 src/loslib.js              |  2 +-
 src/lstrlib.js             | 26 +++++++++++++-------------
 src/ltablib.js             | 12 ++++++------
 src/lutf8lib.js            | 20 ++++++++++----------
 tests/test-suite/ltests.js |  8 ++++----
 9 files changed, 53 insertions(+), 53 deletions(-)

(limited to 'src')

diff --git a/src/lbaselib.js b/src/lbaselib.js
index d000ae4..2e8de76 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -63,7 +63,7 @@ const luaB_getmetatable = function(L) {
 const luaB_setmetatable = function(L) {
     let t = lua.lua_type(L, 2);
     lauxlib.luaL_checktype(L, 1, lua.LUA_TTABLE);
-    lauxlib.luaL_argcheck(L, t === lua.LUA_TNIL || t === lua.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
+    lauxlib.luaL_argcheck(L, t === lua.LUA_TNIL || t === lua.LUA_TTABLE, 2, "nil or table expected");
     if (lauxlib.luaL_getmetafield(L, 1, lua.to_luastring("__metatable", true)) !== lua.LUA_TNIL)
         return lauxlib.luaL_error(L, lua.to_luastring("cannot change a protected metatable", true));
     lua.lua_settop(L, 2);
@@ -80,7 +80,7 @@ const luaB_rawequal = function(L) {
 
 const luaB_rawlen = function(L) {
     let t = lua.lua_type(L, 1);
-    lauxlib.luaL_argcheck(L, t === lua.LUA_TTABLE || t === lua.LUA_TSTRING, 1, lua.to_luastring("table or string expected", true));
+    lauxlib.luaL_argcheck(L, t === lua.LUA_TTABLE || t === lua.LUA_TSTRING, 1, "table or string expected");
     lua.lua_pushinteger(L, lua.lua_rawlen(L, 1));
     return 1;
 };
@@ -115,7 +115,7 @@ const luaB_collectgarbage = function(L) {
 
 const luaB_type = function(L) {
     let t = lua.lua_type(L, 1);
-    lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, lua.to_luastring("value expected", true));
+    lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, "value expected");
     lua.lua_pushstring(L, lua.lua_typename(L, t));
     return 1;
 };
@@ -209,7 +209,7 @@ const luaB_tonumber = function(L) {
         let base = lauxlib.luaL_checkinteger(L, 2);
         lauxlib.luaL_checktype(L, 1, lua.LUA_TSTRING);  /* no numbers as strings */
         let s = lua.lua_tostring(L, 1);
-        lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, lua.to_luastring("base out of range", true));
+        lauxlib.luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
         let n = b_str2int(s, base);
         if (n !== null) {
             lua.lua_pushinteger(L, n);
@@ -253,7 +253,7 @@ const luaB_select = function(L) {
         let i = lauxlib.luaL_checkinteger(L, 1);
         if (i < 0) i = n + i;
         else if (i > n) i = n;
-        lauxlib.luaL_argcheck(L, 1 <= i, 1, lua.to_luastring("index out of range", true));
+        lauxlib.luaL_argcheck(L, 1 <= i, 1, "index out of range");
         return n - i;
     }
 };
diff --git a/src/lcorolib.js b/src/lcorolib.js
index a72d22b..321331b 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -5,7 +5,7 @@ const lauxlib = require('./lauxlib.js');
 
 const getco = function(L) {
     let co = lua.lua_tothread(L, 1);
-    lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("thread expected", true));
+    lauxlib.luaL_argcheck(L, co, 1, "thread expected");
     return co;
 };
 
diff --git a/src/ldblib.js b/src/ldblib.js
index eb64b03..5d8f5c4 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -30,7 +30,7 @@ const db_getmetatable = function(L) {
 
 const db_setmetatable = function(L) {
     const t = lua.lua_type(L, 2);
-    lauxlib.luaL_argcheck(L, t == lua.LUA_TNIL || t == lua.LUA_TTABLE, 2, lua.to_luastring("nil or table expected", true));
+    lauxlib.luaL_argcheck(L, t == lua.LUA_TNIL || t == lua.LUA_TTABLE, 2, "nil or table expected");
     lua.lua_settop(L, 2);
     lua.lua_setmetatable(L, 1);
     return 1;  /* return 1st argument */
@@ -134,7 +134,7 @@ const db_getinfo = function(L) {
     }
 
     if (!lua.lua_getinfo(L1, options, ar))
-        lauxlib.luaL_argerror(L, arg + 2, lua.to_luastring("invalid option", true));
+        lauxlib.luaL_argerror(L, arg + 2, "invalid option");
     lua.lua_newtable(L);  /* table to collect results */
     if (options.indexOf('S'.charCodeAt(0)) > -1) {
         settabss(L, lua.to_luastring("source", true), ar.source);
@@ -176,7 +176,7 @@ const db_getlocal = function(L) {
     } else {  /* stack-level argument */
         let level = lauxlib.luaL_checkinteger(L, arg + 1);
         if (!lua.lua_getstack(L1, level, ar))  /* out of range? */
-            return lauxlib.luaL_argerror(L, arg+1, lua.to_luastring("level out of range", true));
+            return lauxlib.luaL_argerror(L, arg+1, "level out of range");
         checkstack(L, L1, 1);
         let name = lua.lua_getlocal(L1, ar, nvar);
         if (name) {
@@ -200,7 +200,7 @@ const db_setlocal = function(L) {
     let level = lauxlib.luaL_checkinteger(L, arg + 1);
     let nvar = lauxlib.luaL_checkinteger(L, arg + 2);
     if (!lua.lua_getstack(L1, level, ar))  /* out of range? */
-        return lauxlib.luaL_argerror(L, arg + 1, lua.to_luastring("level out of range", true));
+        return lauxlib.luaL_argerror(L, arg + 1, "level out of range");
     lauxlib.luaL_checkany(L, arg + 3);
     lua.lua_settop(L, arg + 3);
     checkstack(L, L1, 1);
@@ -242,7 +242,7 @@ const db_setupvalue = function(L) {
 const checkupval = function(L, argf, argnup) {
     let nup = lauxlib.luaL_checkinteger(L, argnup);  /* upvalue index */
     lauxlib.luaL_checktype(L, argf, lua.LUA_TFUNCTION);  /* closure */
-    lauxlib.luaL_argcheck(L, (lua.lua_getupvalue(L, argf, nup) !== null), argnup, lua.to_luastring("invalid upvalue index", true));
+    lauxlib.luaL_argcheck(L, (lua.lua_getupvalue(L, argf, nup) !== null), argnup, "invalid upvalue index");
     return nup;
 };
 
@@ -255,8 +255,8 @@ const db_upvalueid = function(L) {
 const db_upvaluejoin = function(L) {
     let n1 = checkupval(L, 1, 2);
     let n2 = checkupval(L, 3, 4);
-    lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 1), 1, lua.to_luastring("Lua function expected", true));
-    lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 3), 3, lua.to_luastring("Lua function expected", true));
+    lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 1), 1, "Lua function expected");
+    lauxlib.luaL_argcheck(L, !lua.lua_iscfunction(L, 3), 3, "Lua function expected");
     lua.lua_upvaluejoin(L, 1, n1, 3, n2);
     return 0;
 };
diff --git a/src/lmathlib.js b/src/lmathlib.js
index e056fd8..ac41d8a 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -21,13 +21,13 @@ const math_random = function(L) {
             up = lauxlib.luaL_checkinteger(L, 2);
             break;
         }
-        default: return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments", true));
+        default: return lauxlib.luaL_error(L, "wrong number of arguments");
     }
 
     /* random integer in the interval [low, up] */
-    lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty", true));
+    lauxlib.luaL_argcheck(L, low <= up, 1, "interval is empty");
     lauxlib.luaL_argcheck(L, low >= 0 || up <= luaconf.LUA_MAXINTEGER + low, 1,
-        lua.to_luastring("interval too large", true));
+        "interval too large");
 
     r *= (up - low) + 1;
     lua.lua_pushinteger(L, Math.floor(r) + low);
@@ -162,7 +162,7 @@ const math_rad = function(L) {
 const math_min = function(L) {
     let n = lua.lua_gettop(L);  /* number of arguments */
     let imin = 1;  /* index of current minimum value */
-    lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true));
+    lauxlib.luaL_argcheck(L, n >= 1, 1, "value expected");
     for (let i = 2; i <= n; i++){
         if (lua.lua_compare(L, i, imin, lua.LUA_OPLT))
             imin = i;
@@ -174,7 +174,7 @@ const math_min = function(L) {
 const math_max = function(L) {
     let n = lua.lua_gettop(L);  /* number of arguments */
     let imax = 1;  /* index of current minimum value */
-    lauxlib.luaL_argcheck(L, n >= 1, 1, lua.to_luastring("value expected", true));
+    lauxlib.luaL_argcheck(L, n >= 1, 1, "value expected");
     for (let i = 2; i <= n; i++){
         if (lua.lua_compare(L, imax, i, lua.LUA_OPLT))
             imax = i;
@@ -201,7 +201,7 @@ const math_fmod = function(L) {
         let d = lua.lua_tointeger(L, 2);
         /* no special case needed for -1 in javascript */
         if (d === 0) {
-            lauxlib.luaL_argerror(L, 2, lua.to_luastring("zero", true));
+            lauxlib.luaL_argerror(L, 2, "zero");
         } else
             lua.lua_pushinteger(L, (lua.lua_tointeger(L, 1) % d)|0);
     } else {
diff --git a/src/loslib.js b/src/loslib.js
index 99e5787..09ee168 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -144,7 +144,7 @@ const os_time = function(L) {
 
 const l_checktime = function(L, arg) {
     let t = lauxlib.luaL_checkinteger(L, arg);
-    // lauxlib.luaL_argcheck(L, t, arg, lua.to_luastring("time out-of-bounds"));
+    // lauxlib.luaL_argcheck(L, t, arg, "time out-of-bounds");
     return t;
 };
 
diff --git a/src/lstrlib.js b/src/lstrlib.js
index a8a017f..ddb2161 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -306,7 +306,7 @@ const str_format = function(L) {
                     if (form.length <= 2 || form[2] === 0) {  /* no modifiers? */
                         lauxlib.luaL_addvalue(b);  /* keep entire string */
                     } else {
-                        lauxlib.luaL_argcheck(L, s.length === strlen(s), arg, lua.to_luastring("string contains zeros", true));
+                        lauxlib.luaL_argcheck(L, s.length === strlen(s), arg, "string contains zeros");
                         if (form.indexOf('.'.charCodeAt(0)) < 0 && s.length >= 100) {
                             /* no precision and string is too long to be formatted */
                             lauxlib.luaL_addvalue(b);  /* keep entire string */
@@ -534,7 +534,7 @@ const str_pack = function(L) {
                 let n = lauxlib.luaL_checkinteger(L, arg);
                 if (size < SZINT) {  /* need overflow check? */
                     let lim = 1 << (size * 8) - 1;
-                    lauxlib.luaL_argcheck(L, -lim <= n && n < lim, arg, lua.to_luastring("integer overflow", true));
+                    lauxlib.luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow");
                 }
                 packint(b, n, h.islittle, size, n < 0);
                 break;
@@ -542,7 +542,7 @@ const str_pack = function(L) {
             case KOption.Kuint: {  /* unsigned integers */
                 let n = lauxlib.luaL_checkinteger(L, arg);
                 if (size < SZINT)
-                    lauxlib.luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, lua.to_luastring("unsigned overflow", true));
+                    lauxlib.luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, "unsigned overflow");
                 packint(b, n>>>0, h.islittle, size, false);
                 break;
             }
@@ -558,7 +558,7 @@ const str_pack = function(L) {
             case KOption.Kchar: {  /* fixed-size string */
                 let s = lauxlib.luaL_checkstring(L, arg);
                 let len = s.length;
-                lauxlib.luaL_argcheck(L, len <= size, arg, lua.to_luastring("string longer than given size", true));
+                lauxlib.luaL_argcheck(L, len <= size, arg, "string longer than given size");
                 lauxlib.luaL_addlstring(b, s, len);  /* add string */
                 while (len++ < size)  /* pad extra space */
                     lauxlib.luaL_addchar(b, LUAL_PACKPADBYTE);
@@ -569,7 +569,7 @@ const str_pack = function(L) {
                 let len = s.length;
                 lauxlib.luaL_argcheck(L,
                     size >= 4 /* sizeof(size_t) */ || len < (1 << (size * NB)),
-                    arg, lua.to_luastring("string length does not fit in given size", true));
+                    arg, "string length does not fit in given size");
                 packint(b, len, h.islittle, size, 0);  /* pack length */
                 lauxlib.luaL_addlstring(b, s, len);
                 totalsize += len;
@@ -578,7 +578,7 @@ const str_pack = function(L) {
             case KOption.Kzstr: {  /* zero-terminated string */
                 let s = lauxlib.luaL_checkstring(L, arg);
                 let len = s.length;
-                lauxlib.luaL_argcheck(L, s.indexOf(0) < 0, arg, lua.to_luastring("strings contains zeros", true));
+                lauxlib.luaL_argcheck(L, s.indexOf(0) < 0, arg, "strings contains zeros");
                 lauxlib.luaL_addlstring(b, s, len);
                 lauxlib.luaL_addchar(b, 0);  /* add zero at the end */
                 totalsize += len + 1;
@@ -651,10 +651,10 @@ const str_byte = function(L) {
     if (pose > l) pose = l;
     if (posi > pose) return 0;  /* empty interval; return no values */
     if (pose - posi >= Number.MAX_SAFE_INTEGER)  /* arithmetic overflow? */
-        return lauxlib.luaL_error(L, lua.to_luastring("string slice too long", true));
+        return lauxlib.luaL_error(L, "string slice too long");
 
     let n = (pose - posi) + 1;
-    lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
+    lauxlib.luaL_checkstack(L, n, "string slice too long");
     for (let i = 0; i < n; i++)
         lua.lua_pushinteger(L, s[posi + i - 1]);
     return n;
@@ -673,12 +673,12 @@ const str_packsize = function(L) {
         let size = details.size;
         let ntoalign = details.ntoalign;
         size += ntoalign;  /* total space used by option */
-        lauxlib.luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, lua.to_luastring("format result too large", true));
+        lauxlib.luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, "format result too large");
         totalsize += size;
         switch (opt) {
             case KOption.Kstring:  /* strings with length count */
             case KOption.Kzstr:    /* zero-terminated string */
-                lauxlib.luaL_argerror(L, 1, lua.to_luastring("variable-length format", true));
+                lauxlib.luaL_argerror(L, 1, "variable-length format");
                 /* call never return, but to avoid warnings: *//* fall through */
             default:  break;
         }
@@ -738,7 +738,7 @@ const str_unpack = function(L) {
     let ld = data.length;
     let pos = posrelat(lauxlib.luaL_optinteger(L, 3, 1), ld) - 1;
     let n = 0;  /* number of results */
-    lauxlib.luaL_argcheck(L, pos <= ld && pos >= 0, 3, lua.to_luastring("initial position out of string", true));
+    lauxlib.luaL_argcheck(L, pos <= ld && pos >= 0, 3, "initial position out of string");
     while (fmt.off < fmt.s.length) {
         let details = getdetails(h, pos, fmt);
         let opt = details.opt;
@@ -768,7 +768,7 @@ const str_unpack = function(L) {
             }
             case KOption.Kstring: {
                 let len = unpackint(L, data.slice(pos), h.islittle, size, 0);
-                lauxlib.luaL_argcheck(L, pos + len + size <= ld, 2, lua.to_luastring("data string too short", true));
+                lauxlib.luaL_argcheck(L, pos + len + size <= ld, 2, "data string too short");
                 lua.lua_pushstring(L, data.slice(pos + size, pos + size + len));
                 pos += len;  /* skip string */
                 break;
@@ -1323,7 +1323,7 @@ const str_gsub = function(L) {
     let ms = new MatchState(L);
     let b = new lauxlib.luaL_Buffer();
     lauxlib.luaL_argcheck(L, tr === lua.LUA_TNUMBER || tr === lua.LUA_TSTRING || tr === lua.LUA_TFUNCTION || tr === lua.LUA_TTABLE, 3,
-        lua.to_luastring("string/function/table expected", true));
+        "string/function/table expected");
     lauxlib.luaL_buffinit(L, b);
     if (anchor) {
         p = p.slice(1); lp--;  /* skip anchor character */
diff --git a/src/ltablib.js b/src/ltablib.js
index 56671c4..215610f 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -62,7 +62,7 @@ const tinsert = function(L) {
             break;
         case 3: {
             pos = lauxlib.luaL_checkinteger(L, 2);  /* 2nd argument is the position */
-            lauxlib.luaL_argcheck(L, 1 <= pos && pos <= e, 2, lua.to_luastring("position out of bounds", true));
+            lauxlib.luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
             for (let i = e; i > pos; i--) {  /* move up elements */
                 lua.lua_geti(L, 1, i - 1);
                 lua.lua_seti(L, 1, i);  /* t[i] = t[i - 1] */
@@ -70,7 +70,7 @@ const tinsert = function(L) {
             break;
         }
         default: {
-            return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments to 'insert'", true));
+            return lauxlib.luaL_error(L, "wrong number of arguments to 'insert'");
         }
     }
 
@@ -82,7 +82,7 @@ const tremove = function(L) {
     let size = aux_getn(L, 1, TAB_RW);
     let pos = lauxlib.luaL_optinteger(L, 2, size);
     if (pos !== size)  /* validate 'pos' if given */
-        lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, lua.to_luastring("position out of bounds", true));
+        lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
     lua.lua_geti(L, 1, pos);  /* result = t[pos] */
     for (; pos < size; pos++) {
         lua.lua_geti(L, 1, pos + 1);
@@ -107,9 +107,9 @@ const tmove = function(L) {
     checktab(L, 1, TAB_R);
     checktab(L, tt, TAB_W);
     if (e >= f) {  /* otherwise, nothing to move */
-        lauxlib.luaL_argcheck(L, f > 0 || e < luaconf.LUA_MAXINTEGER + f, 3, lua.to_luastring("too many elements to move", true));
+        lauxlib.luaL_argcheck(L, f > 0 || e < luaconf.LUA_MAXINTEGER + f, 3, "too many elements to move");
         let n = e - f + 1;  /* number of elements to move */
-        lauxlib.luaL_argcheck(L, t <= luaconf.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around", true));
+        lauxlib.luaL_argcheck(L, t <= luaconf.LUA_MAXINTEGER - n + 1, 4, "destination wrap around");
 
         if (t > e || t <= f || (tt !== 1 && lua.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
             for (let i = 0; i < n; i++) {
@@ -291,7 +291,7 @@ const auxsort = function(L, lo, up, rnd) {
 const sort = function(L) {
     let n = aux_getn(L, 1, TAB_RW);
     if (n > 1) {  /* non-trivial interval? */
-        lauxlib.luaL_argcheck(L, n < luaconf.LUA_MAXINTEGER, 1, lua.to_luastring("array too big", true));
+        lauxlib.luaL_argcheck(L, n < luaconf.LUA_MAXINTEGER, 1, "array too big");
         if (!lua.lua_isnoneornil(L, 2))  /* is there a 2nd argument? */
             lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION);  /* must be a function */
         lua.lua_settop(L, 2);  /* make sure there are two arguments */
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index f581a9e..4298a33 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -59,8 +59,8 @@ const utflen = function(L) {
     let posi = u_posrelat(lauxlib.luaL_optinteger(L, 2, 1), len);
     let posj = u_posrelat(lauxlib.luaL_optinteger(L, 3, -1), len);
 
-    lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= len, 2, lua.to_luastring("initial position out of string"));
-    lauxlib.luaL_argcheck(L, --posj < len, 3, lua.to_luastring("final position out of string"));
+    lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= len, 2, "initial position out of string");
+    lauxlib.luaL_argcheck(L, --posj < len, 3, "final position out of string");
 
     while (posi <= posj) {
         let dec = utf8_decode(s, posi);
@@ -78,7 +78,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, lua.to_luastring("value out of range", true));
+    lauxlib.luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range");
     lua.lua_pushstring(L, lua.to_luastring(String.fromCodePoint(code)));
 };
 
@@ -111,14 +111,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, lua.to_luastring("position out of range", true));
+    lauxlib.luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, "position out of 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, lua.to_luastring("initial position is a continuation byte", true));
+            lauxlib.luaL_error(L, "initial position is a continuation byte");
 
         if (n < 0) {
             while (n < 0 && posi > 0) {  /* move back */
@@ -155,19 +155,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, lua.to_luastring("out of range", true));
-    lauxlib.luaL_argcheck(L, pose <= s.length, 3, lua.to_luastring("out of range", true));
+    lauxlib.luaL_argcheck(L, posi >= 1, 2, "out of range");
+    lauxlib.luaL_argcheck(L, pose <= s.length, 3, "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, lua.to_luastring("string slice too long", true));
+        return lauxlib.luaL_error(L, "string slice too long");
     let n = (pose - posi) + 1;
-    lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
+    lauxlib.luaL_checkstack(L, n, "string slice too long");
     n = 0;
     for (posi -= 1; posi < pose;) {
         let dec = utf8_decode(s, posi);
         if (dec === null)
-            return lauxlib.luaL_error(L, lua.to_luastring("invalid UTF-8 code", true));
+            return lauxlib.luaL_error(L, "invalid UTF-8 code");
         lua.lua_pushinteger(L, dec.code);
         posi = dec.pos;
         n++;
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index 08bb603..fa6d697 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -552,7 +552,7 @@ const newstate = function(L) {
 
 const getstate = function(L) {
     let L1 = lua.lua_touserdata(L, 1);
-    lauxlib.luaL_argcheck(L, L1 !== null, 1, lua.to_luastring("state expected", true));
+    lauxlib.luaL_argcheck(L, L1 !== null, 1, "state expected");
     return L1;
 };
 
@@ -751,7 +751,7 @@ const makeCfunc = function(L) {
 const coresume = function(L) {
     let status;
     let co = lua.lua_tothread(L, 1);
-    lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("coroutine expected", true));
+    lauxlib.luaL_argcheck(L, co, 1, "coroutine expected");
     status = lua.lua_resume(co, L, 0);
     if (status != lua.LUA_OK && status !== lua.LUA_YIELD) {
         lua.lua_pushboolean(L, 0);
@@ -805,7 +805,7 @@ const buildop = function(p, pc) {
 
 const listcode = function(L) {
     lauxlib.luaL_argcheck(L, lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
-        1, lua.to_luastring("Lua function expected", true));
+        1, "Lua function expected");
     let p = obj_at(L, 1);
     lua.lua_newtable(L);
     setnameval(L, lua.to_luastring("maxstack", true), p.maxstacksize);
@@ -821,7 +821,7 @@ const listcode = function(L) {
 const listk = function(L) {
     lauxlib.luaL_argcheck(L,
         lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1),
-        1, lua.to_luastring("Lua function expected"), true);
+        1, "Lua function expected");
     let p = obj_at(L, 1);
     lua.lua_createtable(L, p.k.length, 0);
     for (let i = 0; i < p.k.length; i++) {
-- 
cgit v1.2.3-70-g09d2