diff options
author | daurnimator <quae@daurnimator.com> | 2018-03-30 16:39:41 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-03-30 16:42:26 +1100 |
commit | fb3b9c3b3f0ee1a04ec264d1b40bd1cccf24a999 (patch) | |
tree | 3166cfef0f1c8cde6b6662b46791dfb66f681e3d | |
parent | 2f2bd7fad5342583f85e99ec67eea74fad5fafdd (diff) | |
parent | 1371afafae9144b30475262f06940c4057485d02 (diff) | |
download | fengari-fb3b9c3b3f0ee1a04ec264d1b40bd1cccf24a999.tar.gz fengari-fb3b9c3b3f0ee1a04ec264d1b40bd1cccf24a999.tar.bz2 fengari-fb3b9c3b3f0ee1a04ec264d1b40bd1cccf24a999.zip |
Merge branch 'accept-jsstrings'
-rw-r--r-- | src/defs.js | 8 | ||||
-rw-r--r-- | src/lauxlib.js | 6 | ||||
-rw-r--r-- | src/lbaselib.js | 16 | ||||
-rw-r--r-- | src/lcorolib.js | 2 | ||||
-rw-r--r-- | src/ldblib.js | 16 | ||||
-rw-r--r-- | src/lmathlib.js | 12 | ||||
-rw-r--r-- | src/loadlib.js | 4 | ||||
-rw-r--r-- | src/loslib.js | 4 | ||||
-rw-r--r-- | src/lstrlib.js | 28 | ||||
-rw-r--r-- | src/ltablib.js | 14 | ||||
-rw-r--r-- | src/lutf8lib.js | 20 | ||||
-rw-r--r-- | tests/test-suite/ltests.js | 10 |
12 files changed, 72 insertions, 68 deletions
diff --git a/src/defs.js b/src/defs.js index 856a854..98269ea 100644 --- a/src/defs.js +++ b/src/defs.js @@ -224,7 +224,13 @@ const to_luastring = function(str, cache) { }; const from_userstring = function(str) { - if (!is_luastring(str)) throw new TypeError("expects an array of bytes"); + if (!is_luastring(str)) { + if (typeof str === "string") { + str = to_luastring(str); + } else { + throw new TypeError("expects an array of bytes or javascript string"); + } + } return str; }; diff --git a/src/lauxlib.js b/src/lauxlib.js index 5abbaaa..475fd1b 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -402,16 +402,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_tolstring(L, arg); if (s === null || s === undefined) tag_error(L, arg, LUA_TSTRING); return s; }; +const luaL_checkstring = luaL_checklstring; + const luaL_optlstring = function(L, arg, def) { if (lua_type(L, arg) <= 0) { return def === null ? null : from_userstring(def); diff --git a/src/lbaselib.js b/src/lbaselib.js index 9f0eb7a..b589d6f 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -156,7 +156,7 @@ const luaB_getmetatable = function(L) { const luaB_setmetatable = function(L) { let t = lua_type(L, 2); luaL_checktype(L, 1, LUA_TTABLE); - luaL_argcheck(L, t === LUA_TNIL || t === LUA_TTABLE, 2, to_luastring("nil or table expected", true)); + luaL_argcheck(L, t === LUA_TNIL || t === LUA_TTABLE, 2, "nil or table expected"); if (luaL_getmetafield(L, 1, to_luastring("__metatable", true)) !== LUA_TNIL) return luaL_error(L, to_luastring("cannot change a protected metatable")); lua_settop(L, 2); @@ -173,7 +173,7 @@ const luaB_rawequal = function(L) { const luaB_rawlen = function(L) { let t = lua_type(L, 1); - luaL_argcheck(L, t === LUA_TTABLE || t === LUA_TSTRING, 1, to_luastring("table or string expected", true)); + luaL_argcheck(L, t === LUA_TTABLE || t === LUA_TSTRING, 1, "table or string expected"); lua_pushinteger(L, lua_rawlen(L, 1)); return 1; }; @@ -201,14 +201,14 @@ const opts = [ "isrunning" ].map((e) => to_luastring(e)); const luaB_collectgarbage = function(L) { - luaL_checkoption(L, 1, to_luastring("collect"), opts); + luaL_checkoption(L, 1, "collect", opts); luaL_optinteger(L, 2, 0); luaL_error(L, to_luastring("lua_gc not implemented")); }; const luaB_type = function(L) { let t = lua_type(L, 1); - luaL_argcheck(L, t !== LUA_TNONE, 1, to_luastring("value expected", true)); + luaL_argcheck(L, t !== LUA_TNONE, 1, "value expected"); lua_pushstring(L, lua_typename(L, t)); return 1; }; @@ -294,7 +294,7 @@ const luaB_tonumber = function(L) { let base = luaL_checkinteger(L, 2); luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ let s = lua_tostring(L, 1); - luaL_argcheck(L, 2 <= base && base <= 36, 2, to_luastring("base out of range", true)); + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); let n = b_str2int(s, base); if (n !== null) { lua_pushinteger(L, n); @@ -338,7 +338,7 @@ const luaB_select = function(L) { let i = luaL_checkinteger(L, 1); if (i < 0) i = n + i; else if (i > n) i = n; - luaL_argcheck(L, 1 <= i, 1, to_luastring("index out of range", true)); + luaL_argcheck(L, 1 <= i, 1, "index out of range"); return n - i; } }; @@ -425,14 +425,14 @@ const generic_reader = function(L, ud) { const luaB_load = function(L) { let s = lua_tostring(L, 1); - let mode = luaL_optstring(L, 3, to_luastring("bt", true)); + let mode = luaL_optstring(L, 3, "bt"); let env = !lua_isnone(L, 4) ? 4 : 0; /* 'env' index or 0 if no 'env' */ let status; if (s !== null) { /* loading a string? */ let chunkname = luaL_optstring(L, 2, s); status = luaL_loadbufferx(L, s, s.length, chunkname, mode); } else { /* loading from a reader function */ - let chunkname = luaL_optstring(L, 2, to_luastring("=(load)", true)); + let chunkname = luaL_optstring(L, 2, "=(load)"); luaL_checktype(L, 1, LUA_TFUNCTION); lua_settop(L, RESERVEDSLOT); /* create reserved slot */ status = lua_load(L, generic_reader, null, chunkname, mode); diff --git a/src/lcorolib.js b/src/lcorolib.js index eb402b8..a52abf5 100644 --- a/src/lcorolib.js +++ b/src/lcorolib.js @@ -38,7 +38,7 @@ const { to_luastring } = require("./fengaricore.js"); const getco = function(L) { let co = lua_tothread(L, 1); - luaL_argcheck(L, co, 1, to_luastring("thread expected", true)); + luaL_argcheck(L, co, 1, "thread expected"); return co; }; diff --git a/src/ldblib.js b/src/ldblib.js index 9edabe7..03be3df 100644 --- a/src/ldblib.js +++ b/src/ldblib.js @@ -104,7 +104,7 @@ const db_getmetatable = function(L) { const db_setmetatable = function(L) { const t = lua_type(L, 2); - luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, to_luastring("nil or table expected", true)); + luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table expected"); lua_settop(L, 2); lua_setmetatable(L, 1); return 1; /* return 1st argument */ @@ -194,7 +194,7 @@ const db_getinfo = function(L) { let thread = getthread(L); let arg = thread.arg; let L1 = thread.thread; - let options = luaL_optstring(L, arg + 2, to_luastring("flnStu", true)); + let options = luaL_optstring(L, arg + 2, "flnStu"); checkstack(L, L1, 3); if (lua_isfunction(L, arg + 1)) { /* info about a function? */ options = lua_pushfstring(L, to_luastring(">%s"), options); /* add '>' to 'options' */ @@ -208,7 +208,7 @@ const db_getinfo = function(L) { } if (!lua_getinfo(L1, options, ar)) - luaL_argerror(L, arg + 2, to_luastring("invalid option", true)); + luaL_argerror(L, arg + 2, "invalid option"); lua_newtable(L); /* table to collect results */ if (luastring_indexOf(options, 83 /* 'S'.charCodeAt(0) */) > -1) { settabss(L, to_luastring("source", true), ar.source); @@ -250,7 +250,7 @@ const db_getlocal = function(L) { } else { /* stack-level argument */ let level = luaL_checkinteger(L, arg + 1); if (!lua_getstack(L1, level, ar)) /* out of range? */ - return luaL_argerror(L, arg+1, to_luastring("level out of range", true)); + return luaL_argerror(L, arg+1, "level out of range"); checkstack(L, L1, 1); let name = lua_getlocal(L1, ar, nvar); if (name) { @@ -274,7 +274,7 @@ const db_setlocal = function(L) { let level = luaL_checkinteger(L, arg + 1); let nvar = luaL_checkinteger(L, arg + 2); if (!lua_getstack(L1, level, ar)) /* out of range? */ - return luaL_argerror(L, arg + 1, to_luastring("level out of range", true)); + return luaL_argerror(L, arg + 1, "level out of range"); luaL_checkany(L, arg + 3); lua_settop(L, arg + 3); checkstack(L, L1, 1); @@ -316,7 +316,7 @@ const db_setupvalue = function(L) { const checkupval = function(L, argf, argnup) { let nup = luaL_checkinteger(L, argnup); /* upvalue index */ luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ - luaL_argcheck(L, (lua_getupvalue(L, argf, nup) !== null), argnup, to_luastring("invalid upvalue index", true)); + luaL_argcheck(L, (lua_getupvalue(L, argf, nup) !== null), argnup, "invalid upvalue index"); return nup; }; @@ -329,8 +329,8 @@ const db_upvalueid = function(L) { const db_upvaluejoin = function(L) { let n1 = checkupval(L, 1, 2); let n2 = checkupval(L, 3, 4); - luaL_argcheck(L, !lua_iscfunction(L, 1), 1, to_luastring("Lua function expected", true)); - luaL_argcheck(L, !lua_iscfunction(L, 3), 3, to_luastring("Lua function expected", true)); + luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); + luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); lua_upvaluejoin(L, 1, n1, 3, n2); return 0; }; diff --git a/src/lmathlib.js b/src/lmathlib.js index 665fbc4..8313e93 100644 --- a/src/lmathlib.js +++ b/src/lmathlib.js @@ -66,13 +66,13 @@ const math_random = function(L) { up = luaL_checkinteger(L, 2); break; } - default: return luaL_error(L, to_luastring("wrong number of arguments", true)); + default: return luaL_error(L, "wrong number of arguments"); } /* random integer in the interval [low, up] */ - luaL_argcheck(L, low <= up, 1, to_luastring("interval is empty", true)); + luaL_argcheck(L, low <= up, 1, "interval is empty"); luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1, - to_luastring("interval too large", true)); + "interval too large"); r *= (up - low) + 1; lua_pushinteger(L, Math.floor(r) + low); @@ -213,7 +213,7 @@ const math_rad = function(L) { const math_min = function(L) { let n = lua_gettop(L); /* number of arguments */ let imin = 1; /* index of current minimum value */ - luaL_argcheck(L, n >= 1, 1, to_luastring("value expected", true)); + luaL_argcheck(L, n >= 1, 1, "value expected"); for (let i = 2; i <= n; i++){ if (lua_compare(L, i, imin, LUA_OPLT)) imin = i; @@ -225,7 +225,7 @@ const math_min = function(L) { const math_max = function(L) { let n = lua_gettop(L); /* number of arguments */ let imax = 1; /* index of current minimum value */ - luaL_argcheck(L, n >= 1, 1, to_luastring("value expected", true)); + luaL_argcheck(L, n >= 1, 1, "value expected"); for (let i = 2; i <= n; i++){ if (lua_compare(L, imax, i, LUA_OPLT)) imax = i; @@ -252,7 +252,7 @@ const math_fmod = function(L) { let d = lua_tointeger(L, 2); /* no special case needed for -1 in javascript */ if (d === 0) { - luaL_argerror(L, 2, to_luastring("zero", true)); + luaL_argerror(L, 2, "zero"); } else lua_pushinteger(L, (lua_tointeger(L, 1) % d)|0); } else { diff --git a/src/loadlib.js b/src/loadlib.js index 533291c..f6679ba 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -361,8 +361,8 @@ const ll_searchpath = function(L) { L, luaL_checkstring(L, 1), luaL_checkstring(L, 2), - luaL_optstring(L, 3, to_luastring(".")), - luaL_optstring(L, 4, to_luastring(LUA_DIRSEP)) + luaL_optstring(L, 3, "."), + luaL_optstring(L, 4, 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 53a4228..6fec903 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -130,7 +130,7 @@ const checkoption = function(L, conv, i, buff) { const os_date = function(L) { - let s = luaL_optlstring(L, 1, to_luastring("%c")); + let s = luaL_optlstring(L, 1, "%c"); let t = luaL_opt(L, l_checktime, 2, new Date().getTime() / 1000) * 1000; let stm = new Date(t); let utc = false; @@ -188,7 +188,7 @@ const os_time = function(L) { const l_checktime = function(L, arg) { let t = luaL_checkinteger(L, arg); - // luaL_argcheck(L, t, arg, to_luastring("time out-of-bounds")); + // luaL_argcheck(L, t, arg, "time out-of-bounds"); return t; }; diff --git a/src/lstrlib.js b/src/lstrlib.js index fcaea79..67c4537 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -381,7 +381,7 @@ const str_format = function(L) { if (form.length <= 2 || form[2] === 0) { /* no modifiers? */ luaL_addvalue(b); /* keep entire string */ } else { - luaL_argcheck(L, s.length === strlen(s), arg, to_luastring("string contains zeros", true)); + luaL_argcheck(L, s.length === strlen(s), arg, "string contains zeros"); if (luastring_indexOf(form, 46 /* '.'.charCodeAt(0) */) < 0 && s.length >= 100) { /* no precision and string is too long to be formatted */ luaL_addvalue(b); /* keep entire string */ @@ -601,7 +601,7 @@ const str_pack = function(L) { let n = luaL_checkinteger(L, arg); if (size < SZINT) { /* need overflow check? */ let lim = 1 << (size * 8) - 1; - luaL_argcheck(L, -lim <= n && n < lim, arg, to_luastring("integer overflow", true)); + luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow"); } packint(b, n, h.islittle, size, n < 0); break; @@ -609,7 +609,7 @@ const str_pack = function(L) { case Kuint: { /* unsigned integers */ let n = luaL_checkinteger(L, arg); if (size < SZINT) - luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, to_luastring("unsigned overflow", true)); + luaL_argcheck(L, (n>>>0) < (1 << (size * NB)), arg, "unsigned overflow"); packint(b, n>>>0, h.islittle, size, false); break; } @@ -625,7 +625,7 @@ const str_pack = function(L) { case Kchar: { /* fixed-size string */ let s = luaL_checkstring(L, arg); let len = s.length; - luaL_argcheck(L, len <= size, arg, to_luastring("string longer than given size", true)); + luaL_argcheck(L, len <= size, arg, "string longer than given size"); luaL_addlstring(b, s, len); /* add string */ while (len++ < size) /* pad extra space */ luaL_addchar(b, LUAL_PACKPADBYTE); @@ -636,7 +636,7 @@ const str_pack = function(L) { let len = s.length; luaL_argcheck(L, size >= 4 /* sizeof(size_t) */ || len < (1 << (size * NB)), - arg, 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 */ luaL_addlstring(b, s, len); totalsize += len; @@ -645,7 +645,7 @@ const str_pack = function(L) { case Kzstr: { /* zero-terminated string */ let s = luaL_checkstring(L, arg); let len = s.length; - luaL_argcheck(L, luastring_indexOf(s, 0) < 0, arg, to_luastring("strings contains zeros", true)); + luaL_argcheck(L, luastring_indexOf(s, 0) < 0, arg, "strings contains zeros"); luaL_addlstring(b, s, len); luaL_addchar(b, 0); /* add zero at the end */ totalsize += len + 1; @@ -703,7 +703,7 @@ const str_rep = function(L) { let s = luaL_checkstring(L, 1); let l = s.length; let n = luaL_checkinteger(L, 2); - let sep = luaL_optstring(L, 3, to_luastring("")); + let sep = luaL_optstring(L, 3, ""); let lsep = sep.length; if (n <= 0) lua_pushliteral(L, ""); else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */ @@ -737,10 +737,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 luaL_error(L, to_luastring("string slice too long", true)); + return luaL_error(L, "string slice too long"); let n = (pose - posi) + 1; - luaL_checkstack(L, n, to_luastring("string slice too long", true)); + luaL_checkstack(L, n, "string slice too long"); for (let i = 0; i < n; i++) lua_pushinteger(L, s[posi + i - 1]); return n; @@ -759,12 +759,12 @@ const str_packsize = function(L) { let size = details.size; let ntoalign = details.ntoalign; size += ntoalign; /* total space used by option */ - luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, to_luastring("format result too large", true)); + luaL_argcheck(L, totalsize <= MAXSIZE - size, 1, "format result too large"); totalsize += size; switch (opt) { case Kstring: /* strings with length count */ case Kzstr: /* zero-terminated string */ - luaL_argerror(L, 1, to_luastring("variable-length format", true)); + luaL_argerror(L, 1, "variable-length format"); /* call never return, but to avoid warnings: *//* fall through */ default: break; } @@ -824,7 +824,7 @@ const str_unpack = function(L) { let ld = data.length; let pos = posrelat(luaL_optinteger(L, 3, 1), ld) - 1; let n = 0; /* number of results */ - luaL_argcheck(L, pos <= ld && pos >= 0, 3, to_luastring("initial position out of string", true)); + 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; @@ -854,7 +854,7 @@ const str_unpack = function(L) { } case Kstring: { let len = unpackint(L, data.subarray(pos), h.islittle, size, 0); - luaL_argcheck(L, pos + len + size <= ld, 2, to_luastring("data string too short", true)); + luaL_argcheck(L, pos + len + size <= ld, 2, "data string too short"); lua_pushstring(L, data.subarray(pos + size, pos + size + len)); pos += len; /* skip string */ break; @@ -1421,7 +1421,7 @@ const str_gsub = function(L) { let ms = new MatchState(L); let b = new luaL_Buffer(); luaL_argcheck(L, tr === LUA_TNUMBER || tr === LUA_TSTRING || tr === LUA_TFUNCTION || tr === LUA_TTABLE, 3, - to_luastring("string/function/table expected", true)); + "string/function/table expected"); luaL_buffinit(L, b); if (anchor) { p = p.subarray(1); lp--; /* skip anchor character */ diff --git a/src/ltablib.js b/src/ltablib.js index 6f408da..a521720 100644 --- a/src/ltablib.js +++ b/src/ltablib.js @@ -105,7 +105,7 @@ const tinsert = function(L) { break; case 3: { pos = luaL_checkinteger(L, 2); /* 2nd argument is the position */ - luaL_argcheck(L, 1 <= pos && pos <= e, 2, to_luastring("position out of bounds", true)); + luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds"); for (let i = e; i > pos; i--) { /* move up elements */ lua_geti(L, 1, i - 1); lua_seti(L, 1, i); /* t[i] = t[i - 1] */ @@ -113,7 +113,7 @@ const tinsert = function(L) { break; } default: { - return luaL_error(L, to_luastring("wrong number of arguments to 'insert'", true)); + return luaL_error(L, "wrong number of arguments to 'insert'"); } } @@ -125,7 +125,7 @@ const tremove = function(L) { let size = aux_getn(L, 1, TAB_RW); let pos = luaL_optinteger(L, 2, size); if (pos !== size) /* validate 'pos' if given */ - luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, to_luastring("position out of bounds", true)); + luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds"); lua_geti(L, 1, pos); /* result = t[pos] */ for (; pos < size; pos++) { lua_geti(L, 1, pos + 1); @@ -150,9 +150,9 @@ const tmove = function(L) { checktab(L, 1, TAB_R); checktab(L, tt, TAB_W); if (e >= f) { /* otherwise, nothing to move */ - luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, to_luastring("too many elements to move", true)); + luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, "too many elements to move"); let n = e - f + 1; /* number of elements to move */ - luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, to_luastring("destination wrap around", true)); + luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, "destination wrap around"); if (t > e || t <= f || (tt !== 1 && lua_compare(L, 1, tt, LUA_OPEQ) !== 1)) { for (let i = 0; i < n; i++) { @@ -173,7 +173,7 @@ const tmove = function(L) { const tconcat = function(L) { let last = aux_getn(L, 1, TAB_R); - let sep = luaL_optlstring(L, 2, to_luastring("")); + let sep = luaL_optlstring(L, 2, ""); let lsep = sep.length; let i = luaL_optinteger(L, 3, 1); last = luaL_optinteger(L, 4, last); @@ -335,7 +335,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? */ - luaL_argcheck(L, n < LUA_MAXINTEGER, 1, to_luastring("array too big", true)); + luaL_argcheck(L, n < LUA_MAXINTEGER, 1, "array too big"); if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ luaL_checktype(L, 2, LUA_TFUNCTION); /* must be a function */ lua_settop(L, 2); /* make sure there are two arguments */ diff --git a/src/lutf8lib.js b/src/lutf8lib.js index 3e3e194..34d1365 100644 --- a/src/lutf8lib.js +++ b/src/lutf8lib.js @@ -85,8 +85,8 @@ const utflen = function(L) { let posi = u_posrelat(luaL_optinteger(L, 2, 1), len); let posj = u_posrelat(luaL_optinteger(L, 3, -1), len); - luaL_argcheck(L, 1 <= posi && --posi <= len, 2, to_luastring("initial position out of string")); - luaL_argcheck(L, --posj < len, 3, to_luastring("final position out of string")); + luaL_argcheck(L, 1 <= posi && --posi <= len, 2, "initial position out of string"); + luaL_argcheck(L, --posj < len, 3, "final position out of string"); while (posi <= posj) { let dec = utf8_decode(s, posi); @@ -105,7 +105,7 @@ const utflen = function(L) { const p_U = to_luastring("%U"); const pushutfchar = function(L, arg) { let code = luaL_checkinteger(L, arg); - luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, to_luastring("value out of range", true)); + luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range"); lua_pushfstring(L, p_U, code); }; @@ -138,14 +138,14 @@ const byteoffset = function(L) { let posi = n >= 0 ? 1 : s.length + 1; posi = u_posrelat(luaL_optinteger(L, 3, posi), s.length); - luaL_argcheck(L, 1 <= posi && --posi <= s.length, 3, to_luastring("position out of range", true)); + 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])) - luaL_error(L, to_luastring("initial position is a continuation byte", true)); + luaL_error(L, "initial position is a continuation byte"); if (n < 0) { while (n < 0 && posi > 0) { /* move back */ @@ -182,19 +182,19 @@ const codepoint = function(L) { let posi = u_posrelat(luaL_optinteger(L, 2, 1), s.length); let pose = u_posrelat(luaL_optinteger(L, 3, posi), s.length); - luaL_argcheck(L, posi >= 1, 2, to_luastring("out of range", true)); - luaL_argcheck(L, pose <= s.length, 3, to_luastring("out of range", true)); + luaL_argcheck(L, posi >= 1, 2, "out of range"); + 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 luaL_error(L, to_luastring("string slice too long", true)); + return luaL_error(L, "string slice too long"); let n = (pose - posi) + 1; - luaL_checkstack(L, n, to_luastring("string slice too long", true)); + 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 luaL_error(L, to_luastring("invalid UTF-8 code", true)); + return luaL_error(L, "invalid UTF-8 code"); lua_pushinteger(L, dec.code); posi = dec.pos; n++; diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js index 4cadcd4..6fc086c 100644 --- a/tests/test-suite/ltests.js +++ b/tests/test-suite/ltests.js @@ -559,7 +559,7 @@ const newstate = function(L) { const getstate = function(L) { let L1 = lua.lua_touserdata(L, 1); - lauxlib.luaL_argcheck(L, L1 !== null, 1, to_luastring("state expected", true)); + lauxlib.luaL_argcheck(L, L1 !== null, 1, "state expected"); return L1; }; @@ -678,7 +678,7 @@ const panicback = function(L) { const checkpanic = function(L) { let b = new Aux(); let code = lauxlib.luaL_checkstring(L, 1); - b.paniccode = lauxlib.luaL_optstring(L, 2, to_luastring("", true)); + b.paniccode = lauxlib.luaL_optstring(L, 2, ""); b.L = L; let L1 = lua.lua_newstate(); /* create new state */ if (L1 === null) { /* error? */ @@ -758,7 +758,7 @@ const makeCfunc = function(L) { const coresume = function(L) { let status; let co = lua.lua_tothread(L, 1); - lauxlib.luaL_argcheck(L, co, 1, 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); @@ -812,7 +812,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, to_luastring("Lua function expected", true)); + 1, "Lua function expected"); let p = obj_at(L, 1); lua.lua_newtable(L); setnameval(L, to_luastring("maxstack", true), p.maxstacksize); @@ -828,7 +828,7 @@ const listcode = function(L) { const listk = function(L) { lauxlib.luaL_argcheck(L, lua.lua_isfunction(L, 1) && !lua.lua_iscfunction(L, 1), - 1, 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++) { |