summaryrefslogtreecommitdiff
path: root/src/ltablib.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ltablib.js')
-rw-r--r--src/ltablib.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/ltablib.js b/src/ltablib.js
index 20fdf95..c45f7e5 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -9,6 +9,7 @@ const lstate = require('./lstate.js');
const ldo = require('./ldo.js');
const ldebug = require('./ldebug.js');
const llimit = require('./llimit.js');
+const lobject = require('./lobject.js');
const CT = lua.constant_types;
const TS = lua.thread_status;
@@ -35,9 +36,9 @@ const checktab = function(L, arg, what) {
if (lapi.lua_type(L, arg) !== CT.LUA_TTABLE) { /* is it not a table? */
let n = 1;
if (lapi.lua_getmetatable(L, arg) && /* must have metatable */
- (!(what & TAB_R) || checkfield(L, "__index", ++n)) &&
- (!(what & TAB_W) || checkfield(L, "__newindex", ++n)) &&
- (!(what & TAB_L) || checkfield(L, "__len", ++n))) {
+ (!(what & TAB_R) || checkfield(L, lua.to_luastring("__index"), ++n)) &&
+ (!(what & TAB_W) || checkfield(L, lua.to_luastring("__newindex"), ++n)) &&
+ (!(what & TAB_L) || checkfield(L, lua.to_luastring("__len"), ++n))) {
lapi.lua_pop(L, n); /* pop metatable and tested metamethods */
}
else
@@ -53,7 +54,7 @@ const aux_getn = function(L, n, w) {
const addfield = function(L, b, i) {
lapi.lua_geti(L, 1, i);
if (!lapi.lua_isstring(L, -1))
- lauxlib.luaL_error(L, `invalid value (${lauxlib.luaL_typename(L, -1)}) at index ${i} in table for 'concat'`);
+ lauxlib.luaL_error(L, lua.to_luastring(`invalid value (${lobject.jsstring(lauxlib.luaL_typename(L, -1))}) at index ${i} in table for 'concat'`));
lauxlib.luaL_addvalue(b);
};
@@ -67,7 +68,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, "position out of bounds");
+ lauxlib.luaL_argcheck(L, 1 <= pos && pos <= e, 2, lua.to_luastring("position out of bounds"));
for (let i = e; i > pos; i--) { /* move up elements */
lapi.lua_geti(L, 1, i - 1);
lapi.lua_seti(L, 1, i); /* t[i] = t[i - 1] */
@@ -75,7 +76,7 @@ const tinsert = function(L) {
break;
}
default: {
- return lauxlib.luaL_error(L, "wrong number of arguments to 'insert'");
+ return lauxlib.luaL_error(L, lua.to_luastring("wrong number of arguments to 'insert'"));
}
}
@@ -87,7 +88,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, "position out of bounds");
+ lauxlib.luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, lua.to_luastring("position out of bounds"));
lapi.lua_geti(L, 1, pos); /* result = t[pos] */
for (; pos < size; pos++) {
lapi.lua_geti(L, 1, pos + 1);
@@ -112,9 +113,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 < llimit.LUA_MAXINTEGER + f, 3, "too many elements to move");
+ lauxlib.luaL_argcheck(L, f > 0 || e < llimit.LUA_MAXINTEGER + f, 3, lua.to_luastring("too many elements to move"));
let n = e - f + 1; /* number of elements to move */
- lauxlib.luaL_argcheck(L, t <= llimit.LUA_MAXINTEGER - n + 1, 4, "destination wrap around");
+ lauxlib.luaL_argcheck(L, t <= llimit.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around"));
if (t > e || t <= f || (tt !== 1 && lapi.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
for (let i = 0; i < n; i++) {
@@ -172,7 +173,7 @@ const unpack = function(L) {
if (i > e) return 0; /* empty range */
let n = e - i; /* number of elements minus 1 (avoid overflows) */
if (n >= Number.MAX_SAFE_INTEGER || !lapi.lua_checkstack(L, ++n))
- return lauxlib.luaL_error(L, "too many results to unpack");
+ return lauxlib.luaL_error(L, lua.to_luastring("too many results to unpack"));
for (; i < e; i++) /* push arg[i..e - 1] (to avoid overflows) */
lapi.lua_geti(L, 1, i);
lapi.lua_geti(L, 1, e); /* push last element */
@@ -213,7 +214,7 @@ const auxsort = function(L) {
const sort = function(L) {
let n = aux_getn(L, 1, TAB_RW);
if (n > 1) { /* non-trivial interval? */
- lauxlib.luaL_argcheck(L, n < Number.MAX_SAFE_INTEGER, 1, "array too big");
+ lauxlib.luaL_argcheck(L, n < Number.MAX_SAFE_INTEGER, 1, lua.to_luastring("array too big"));
if (!lapi.lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
lauxlib.luaL_checktype(L, 2, CT.LUA_TFUNCTION); /* must be a function */
lapi.lua_settop(L, 2); /* make sure there are two arguments */
@@ -237,4 +238,4 @@ const luaopen_table = function(L) {
return 1;
};
-module.exports.luaopen_table = luaopen_table; \ No newline at end of file
+module.exports.luaopen_table = luaopen_table;