diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-04-04 11:23:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-04-04 11:23:41 -0300 |
commit | 03c6a05ec836c3a90a6b8d730120afdad39c092b (patch) | |
tree | 31f0bdf82969b1e082e92d7b5dd5d9e1496d64af | |
parent | 3d0b5edfe4df7ec54d6885b6b6ce917faddf6661 (diff) | |
download | lua-03c6a05ec836c3a90a6b8d730120afdad39c092b.tar.gz lua-03c6a05ec836c3a90a6b8d730120afdad39c092b.tar.bz2 lua-03c6a05ec836c3a90a6b8d730120afdad39c092b.zip |
no more nil-in-table
-rw-r--r-- | lapi.c | 23 | ||||
-rw-r--r-- | lcode.c | 55 | ||||
-rw-r--r-- | lcode.h | 3 | ||||
-rw-r--r-- | ljumptab.h | 2 | ||||
-rw-r--r-- | llex.c | 4 | ||||
-rw-r--r-- | llex.h | 4 | ||||
-rw-r--r-- | lobject.h | 10 | ||||
-rw-r--r-- | lopcodes.c | 6 | ||||
-rw-r--r-- | lopcodes.h | 5 | ||||
-rw-r--r-- | lparser.c | 16 | ||||
-rw-r--r-- | lparser.h | 5 | ||||
-rw-r--r-- | ltablib.c | 6 | ||||
-rw-r--r-- | ltm.c | 30 | ||||
-rw-r--r-- | ltm.h | 6 | ||||
-rw-r--r-- | lua.h | 5 | ||||
-rw-r--r-- | lvm.c | 15 |
16 files changed, 23 insertions, 172 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.289 2018/02/27 17:48:28 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.290 2018/02/27 20:01:55 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -705,27 +705,6 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | |||
705 | } | 705 | } |
706 | 706 | ||
707 | 707 | ||
708 | static int auxkeydef (lua_State *L, int idx, int remove) { | ||
709 | int res; | ||
710 | lua_lock(L); | ||
711 | api_checknelems(L, 1); | ||
712 | res = luaT_keydef(L, index2value(L, idx), s2v(L->top - 1), remove); | ||
713 | L->top--; /* remove key */ | ||
714 | lua_unlock(L); | ||
715 | return res; | ||
716 | } | ||
717 | |||
718 | |||
719 | LUA_API void lua_removekey (lua_State *L, int idx) { | ||
720 | auxkeydef(L, idx, 1); | ||
721 | } | ||
722 | |||
723 | |||
724 | LUA_API int lua_keyin (lua_State *L, int idx) { | ||
725 | return auxkeydef(L, idx, 0); | ||
726 | } | ||
727 | |||
728 | |||
729 | LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { | 708 | LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { |
730 | Table *t; | 709 | Table *t; |
731 | lua_lock(L); | 710 | lua_lock(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.159 2018/03/07 15:55:38 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.160 2018/03/16 14:22:09 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -678,10 +678,6 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { | |||
678 | e->k = VNONRELOC; /* becomes a non-relocatable value */ | 678 | e->k = VNONRELOC; /* becomes a non-relocatable value */ |
679 | break; | 679 | break; |
680 | } | 680 | } |
681 | case VUNDEF: { /* not a real expression */ | ||
682 | luaK_semerror(fs->ls, "'undef' is not a value!!"); | ||
683 | break; | ||
684 | } | ||
685 | case VUPVAL: { /* move value to some (pending) register */ | 681 | case VUPVAL: { /* move value to some (pending) register */ |
686 | e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); | 682 | e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0); |
687 | e->k = VRELOC; | 683 | e->k = VRELOC; |
@@ -1410,48 +1406,6 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { | |||
1410 | } | 1406 | } |
1411 | 1407 | ||
1412 | 1408 | ||
1413 | static void normalizeindexed (FuncState *fs, expdesc *v) { | ||
1414 | if (v->k != VINDEXED) { /* not in proper form? */ | ||
1415 | int key = fs->freereg; /* register with key value */ | ||
1416 | luaK_reserveregs(fs, 1); | ||
1417 | switch (v->k) { | ||
1418 | case VINDEXI: | ||
1419 | luaK_int(fs, key, v->u.ind.idx); | ||
1420 | break; | ||
1421 | case VINDEXSTR: | ||
1422 | luaK_codek(fs, key, v->u.ind.idx); | ||
1423 | break; | ||
1424 | case VINDEXUP: | ||
1425 | luaK_codek(fs, key, v->u.ind.idx); | ||
1426 | luaK_codeABC(fs, OP_GETUPVAL, fs->freereg, v->u.ind.t, 0); | ||
1427 | v->u.ind.t = fs->freereg; | ||
1428 | luaK_reserveregs(fs, 1); /* one more register for the upvalue */ | ||
1429 | break; | ||
1430 | default: | ||
1431 | luaK_semerror(fs->ls, "'undef' is not a value!!"); | ||
1432 | break; | ||
1433 | } | ||
1434 | v->u.ind.idx = key; | ||
1435 | v->k = VINDEXED; | ||
1436 | } | ||
1437 | freeregs(fs, v->u.ind.t, v->u.ind.idx); | ||
1438 | } | ||
1439 | |||
1440 | |||
1441 | static void codeisdef (FuncState *fs, int eq, expdesc *v) { | ||
1442 | normalizeindexed(fs, v); | ||
1443 | v->u.info = luaK_codeABCk(fs, OP_ISDEF, 0, v->u.ind.t, v->u.ind.idx, eq); | ||
1444 | v->k = VRELOC; | ||
1445 | } | ||
1446 | |||
1447 | |||
1448 | void luaK_codeundef (FuncState *fs, expdesc *v) { | ||
1449 | normalizeindexed(fs, v); | ||
1450 | v->u.info = luaK_codeABC(fs, OP_UNDEF, v->u.ind.t, v->u.ind.idx, 0); | ||
1451 | v->k = VRELOC; | ||
1452 | } | ||
1453 | |||
1454 | |||
1455 | /* | 1409 | /* |
1456 | ** Apply prefix operation 'op' to expression 'e'. | 1410 | ** Apply prefix operation 'op' to expression 'e'. |
1457 | */ | 1411 | */ |
@@ -1500,7 +1454,7 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { | |||
1500 | break; | 1454 | break; |
1501 | } | 1455 | } |
1502 | case OPR_EQ: case OPR_NE: { | 1456 | case OPR_EQ: case OPR_NE: { |
1503 | if (!tonumeral(v, NULL) && fs->ls->t.token != TK_UNDEF) | 1457 | if (!tonumeral(v, NULL)) |
1504 | luaK_exp2RK(fs, v); | 1458 | luaK_exp2RK(fs, v); |
1505 | /* else keep numeral, which may be an immediate operand */ | 1459 | /* else keep numeral, which may be an immediate operand */ |
1506 | break; | 1460 | break; |
@@ -1597,10 +1551,7 @@ void luaK_posfix (FuncState *fs, BinOpr opr, | |||
1597 | break; | 1551 | break; |
1598 | } | 1552 | } |
1599 | case OPR_EQ: case OPR_NE: { | 1553 | case OPR_EQ: case OPR_NE: { |
1600 | if (e2->k == VUNDEF) | 1554 | codeeq(fs, opr, e1, e2); |
1601 | codeisdef(fs, opr == OPR_NE, e1); | ||
1602 | else | ||
1603 | codeeq(fs, opr, e1, e2); | ||
1604 | break; | 1555 | break; |
1605 | } | 1556 | } |
1606 | case OPR_LT: case OPR_LE: { | 1557 | case OPR_LT: case OPR_LE: { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.71 2018/03/07 15:55:38 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.72 2018/03/19 20:03:44 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -90,7 +90,6 @@ LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, | |||
90 | expdesc *v2, int line); | 90 | expdesc *v2, int line); |
91 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); | 91 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); |
92 | LUAI_FUNC void luaK_finish (FuncState *fs); | 92 | LUAI_FUNC void luaK_finish (FuncState *fs); |
93 | LUAI_FUNC void luaK_codeundef (FuncState *fs, expdesc *e); | ||
94 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); | 93 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); |
95 | 94 | ||
96 | 95 | ||
@@ -79,8 +79,6 @@ static void *disptab[] = { | |||
79 | &&L_OP_GEI, | 79 | &&L_OP_GEI, |
80 | &&L_OP_TEST, | 80 | &&L_OP_TEST, |
81 | &&L_OP_TESTSET, | 81 | &&L_OP_TESTSET, |
82 | &&L_OP_UNDEF, | ||
83 | &&L_OP_ISDEF, | ||
84 | &&L_OP_CALL, | 82 | &&L_OP_CALL, |
85 | &&L_OP_TAILCALL, | 83 | &&L_OP_TAILCALL, |
86 | &&L_OP_RETURN, | 84 | &&L_OP_RETURN, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.100 2018/02/23 13:13:31 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.101 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,7 +41,7 @@ static const char *const luaX_tokens [] = { | |||
41 | "and", "break", "do", "else", "elseif", | 41 | "and", "break", "do", "else", "elseif", |
42 | "end", "false", "for", "function", "goto", "if", | 42 | "end", "false", "for", "function", "goto", "if", |
43 | "in", "local", "nil", "not", "or", "repeat", | 43 | "in", "local", "nil", "not", "or", "repeat", |
44 | "return", "then", "true", "undef", "until", "while", | 44 | "return", "then", "true", "until", "while", |
45 | "//", "..", "...", "==", ">=", "<=", "~=", | 45 | "//", "..", "...", "==", ">=", "<=", "~=", |
46 | "<<", ">>", "::", "<eof>", | 46 | "<<", ">>", "::", "<eof>", |
47 | "<number>", "<integer>", "<name>", "<string>" | 47 | "<number>", "<integer>", "<name>", "<string>" |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.h,v 1.80 2018/01/28 15:13:26 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.81 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -28,7 +28,7 @@ enum RESERVED { | |||
28 | TK_AND = FIRST_RESERVED, TK_BREAK, | 28 | TK_AND = FIRST_RESERVED, TK_BREAK, |
29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, | 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, |
30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, | 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, |
31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNDEF, TK_UNTIL, TK_WHILE, | 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, |
32 | /* other terminal symbols */ | 32 | /* other terminal symbols */ |
33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, | 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, |
34 | TK_SHL, TK_SHR, | 34 | TK_SHL, TK_SHR, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.140 2018/02/26 13:35:03 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.141 2018/02/26 14:16:05 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -160,15 +160,9 @@ typedef StackValue *StkId; /* index to stack elements */ | |||
160 | #define isreallyempty(v) checktag((v), LUA_TEMPTY) | 160 | #define isreallyempty(v) checktag((v), LUA_TEMPTY) |
161 | 161 | ||
162 | 162 | ||
163 | #if defined(LUA_NILINTABLE) | 163 | /* By default, entries with any kind of nil are considered empty */ |
164 | |||
165 | #define isempty(v) isreallyempty(v) | ||
166 | |||
167 | #else /* By default, entries with any kind of nil are considered empty */ | ||
168 | |||
169 | #define isempty(v) ttisnilorempty(v) | 164 | #define isempty(v) ttisnilorempty(v) |
170 | 165 | ||
171 | #endif | ||
172 | 166 | ||
173 | /* macro defining an empty value */ | 167 | /* macro defining an empty value */ |
174 | #define EMPTYCONSTANT {NULL}, LUA_TEMPTY | 168 | #define EMPTYCONSTANT {NULL}, LUA_TEMPTY |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.79 2018/02/21 15:49:32 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.80 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -79,8 +79,6 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
79 | "GEI", | 79 | "GEI", |
80 | "TEST", | 80 | "TEST", |
81 | "TESTSET", | 81 | "TESTSET", |
82 | "UNDEF", | ||
83 | "ISDEF", | ||
84 | "CALL", | 82 | "CALL", |
85 | "TAILCALL", | 83 | "TAILCALL", |
86 | "RETURN", | 84 | "RETURN", |
@@ -164,8 +162,6 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
164 | ,opmode(0, 0, 1, 0, iABC) /* OP_GEI */ | 162 | ,opmode(0, 0, 1, 0, iABC) /* OP_GEI */ |
165 | ,opmode(0, 0, 1, 0, iABC) /* OP_TEST */ | 163 | ,opmode(0, 0, 1, 0, iABC) /* OP_TEST */ |
166 | ,opmode(0, 0, 1, 1, iABC) /* OP_TESTSET */ | 164 | ,opmode(0, 0, 1, 1, iABC) /* OP_TESTSET */ |
167 | ,opmode(0, 0, 0, 0, iABC) /* OP_UNDEF */ | ||
168 | ,opmode(0, 0, 0, 1, iABC) /* OP_ISDEF */ | ||
169 | ,opmode(1, 1, 0, 1, iABC) /* OP_CALL */ | 165 | ,opmode(1, 1, 0, 1, iABC) /* OP_CALL */ |
170 | ,opmode(1, 1, 0, 1, iABC) /* OP_TAILCALL */ | 166 | ,opmode(1, 1, 0, 1, iABC) /* OP_TAILCALL */ |
171 | ,opmode(0, 1, 0, 0, iABC) /* OP_RETURN */ | 167 | ,opmode(0, 1, 0, 0, iABC) /* OP_RETURN */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.189 2018/02/21 15:49:32 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.190 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -266,9 +266,6 @@ OP_GEI,/* A sB if ((R(A) >= sB) ~= k) then pc++ */ | |||
266 | OP_TEST,/* A if (not R(A) == k) then pc++ */ | 266 | OP_TEST,/* A if (not R(A) == k) then pc++ */ |
267 | OP_TESTSET,/* A B if (not R(B) == k) then R(A) := R(B) else pc++ */ | 267 | OP_TESTSET,/* A B if (not R(B) == k) then R(A) := R(B) else pc++ */ |
268 | 268 | ||
269 | OP_UNDEF,/* A B R(A)[R(B)] = undef */ | ||
270 | OP_ISDEF,/* A B C R(A) = (R(B)[R(C)] == undef */ | ||
271 | |||
272 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ | 269 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ |
273 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ | 270 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ |
274 | 271 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.178 2018/02/17 19:20:00 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.179 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -893,11 +893,6 @@ static void primaryexp (LexState *ls, expdesc *v) { | |||
893 | singlevar(ls, v); | 893 | singlevar(ls, v); |
894 | return; | 894 | return; |
895 | } | 895 | } |
896 | case TK_UNDEF: { | ||
897 | luaX_next(ls); | ||
898 | init_exp(v, VUNDEF, 0); | ||
899 | return; | ||
900 | } | ||
901 | default: { | 896 | default: { |
902 | luaX_syntaxerror(ls, "unexpected symbol"); | 897 | luaX_syntaxerror(ls, "unexpected symbol"); |
903 | } | 898 | } |
@@ -1183,10 +1178,6 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { | |||
1183 | else { /* assignment -> '=' explist */ | 1178 | else { /* assignment -> '=' explist */ |
1184 | int nexps; | 1179 | int nexps; |
1185 | checknext(ls, '='); | 1180 | checknext(ls, '='); |
1186 | if (nvars == 1 && testnext(ls, TK_UNDEF)) { | ||
1187 | luaK_codeundef(ls->fs, &lh->v); | ||
1188 | return; | ||
1189 | } | ||
1190 | nexps = explist(ls, &e); | 1181 | nexps = explist(ls, &e); |
1191 | if (nexps != nvars) | 1182 | if (nexps != nvars) |
1192 | adjust_assign(ls, nvars, nexps, &e); | 1183 | adjust_assign(ls, nvars, nexps, &e); |
@@ -1652,11 +1643,6 @@ static void statement (LexState *ls) { | |||
1652 | luaX_next(ls); /* skip LOCAL */ | 1643 | luaX_next(ls); /* skip LOCAL */ |
1653 | if (testnext(ls, TK_FUNCTION)) /* local function? */ | 1644 | if (testnext(ls, TK_FUNCTION)) /* local function? */ |
1654 | localfunc(ls); | 1645 | localfunc(ls); |
1655 | else if (testnext(ls, TK_UNDEF)) | ||
1656 | (void)0; /* ignore */ | ||
1657 | /* old versions may need to declare 'local undef' | ||
1658 | when using 'undef' with no environment; so this | ||
1659 | version accepts (and ignores) these declarations */ | ||
1660 | else | 1646 | else |
1661 | localstat(ls); | 1647 | localstat(ls); |
1662 | break; | 1648 | break; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.80 2017/12/14 14:24:02 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.81 2018/03/07 15:55:38 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -52,8 +52,7 @@ typedef enum { | |||
52 | VRELOC, /* expression can put result in any register; | 52 | VRELOC, /* expression can put result in any register; |
53 | info = instruction pc */ | 53 | info = instruction pc */ |
54 | VCALL, /* expression is a function call; info = instruction pc */ | 54 | VCALL, /* expression is a function call; info = instruction pc */ |
55 | VVARARG, /* vararg expression; info = instruction pc */ | 55 | VVARARG /* vararg expression; info = instruction pc */ |
56 | VUNDEF /* the 'undef' "expression" */ | ||
57 | } expkind; | 56 | } expkind; |
58 | 57 | ||
59 | 58 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.95 2018/02/27 18:47:32 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.96 2018/03/16 14:18:18 roberto Exp roberto $ |
3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -95,8 +95,8 @@ static int tremove (lua_State *L) { | |||
95 | lua_geti(L, 1, pos + 1); | 95 | lua_geti(L, 1, pos + 1); |
96 | lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */ | 96 | lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */ |
97 | } | 97 | } |
98 | lua_pushinteger(L, pos); | 98 | lua_pushnil(L); |
99 | lua_removekey(L, 1); /* remove entry t[pos] */ | 99 | lua_seti(L, 1, pos); /* remove entry t[pos] */ |
100 | return 1; | 100 | return 1; |
101 | } | 101 | } |
102 | 102 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.65 2018/02/26 14:16:05 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.66 2018/02/27 17:48:28 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -38,7 +38,6 @@ LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { | |||
38 | void luaT_init (lua_State *L) { | 38 | void luaT_init (lua_State *L) { |
39 | static const char *const luaT_eventname[] = { /* ORDER TM */ | 39 | static const char *const luaT_eventname[] = { /* ORDER TM */ |
40 | "__index", "__newindex", | 40 | "__index", "__newindex", |
41 | "__undef", "__isdef", | ||
42 | "__gc", "__mode", "__len", "__eq", | 41 | "__gc", "__mode", "__len", "__eq", |
43 | "__add", "__sub", "__mul", "__mod", "__pow", | 42 | "__add", "__sub", "__mul", "__mod", "__pow", |
44 | "__div", "__idiv", | 43 | "__div", "__idiv", |
@@ -250,30 +249,3 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) { | |||
250 | setnilvalue(s2v(where + i)); | 249 | setnilvalue(s2v(where + i)); |
251 | } | 250 | } |
252 | 251 | ||
253 | |||
254 | int luaT_keydef (lua_State *L, TValue *obj, TValue *key, int remove) { | ||
255 | const TValue *tm; | ||
256 | TMS event = remove ? TM_UNDEF : TM_ISDEF; | ||
257 | if (!ttistable(obj)) { /* not a table? */ | ||
258 | tm = luaT_gettmbyobj(L, obj, event); /* get its metamethod */ | ||
259 | if (notm(tm)) { /* no metamethod? */ | ||
260 | const char *msg = remove ? "remove key from" : "check key from"; | ||
261 | luaG_typeerror(L, obj, msg); /* error */ | ||
262 | } | ||
263 | /* else will call metamethod 'tm' */ | ||
264 | } | ||
265 | else { /* 'obj' is a table */ | ||
266 | Table *t = hvalue(obj); | ||
267 | tm = fasttm(L, t->metatable, event); | ||
268 | if (tm == NULL) { /* no metamethod? */ | ||
269 | const TValue *val = luaH_get(t, key); /* get entry */ | ||
270 | int res = !isempty(val); /* true if entry is not empty */ | ||
271 | if (remove && res) /* key is present and should be removed? */ | ||
272 | setempty(cast(TValue*, val)); /* remove it */ | ||
273 | return res; | ||
274 | } | ||
275 | /* else will call metamethod 'tm' */ | ||
276 | } | ||
277 | luaT_callTMres(L, tm, obj, key, L->top); | ||
278 | return !l_isfalse(s2v(L->top)); | ||
279 | } | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 2.33 2018/02/23 13:13:31 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.34 2018/02/27 17:48:28 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,8 +19,6 @@ | |||
19 | typedef enum { | 19 | typedef enum { |
20 | TM_INDEX, | 20 | TM_INDEX, |
21 | TM_NEWINDEX, | 21 | TM_NEWINDEX, |
22 | TM_UNDEF, | ||
23 | TM_ISDEF, | ||
24 | TM_GC, | 22 | TM_GC, |
25 | TM_MODE, | 23 | TM_MODE, |
26 | TM_LEN, | 24 | TM_LEN, |
@@ -91,7 +89,5 @@ LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, | |||
91 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, | 89 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, |
92 | StkId where, int wanted); | 90 | StkId where, int wanted); |
93 | 91 | ||
94 | LUAI_FUNC int luaT_keydef (lua_State *L, TValue *obj, TValue *key, int remove); | ||
95 | |||
96 | 92 | ||
97 | #endif | 93 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.344 2018/03/05 14:15:32 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.345 2018/03/16 15:33:34 roberto Exp roberto $ |
3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
@@ -331,9 +331,6 @@ LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s); | |||
331 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); | 331 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); |
332 | LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); | 332 | LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); |
333 | 333 | ||
334 | LUA_API void (lua_removekey) (lua_State *L, int idx); | ||
335 | LUA_API int (lua_keyin) (lua_State *L, int idx); | ||
336 | |||
337 | 334 | ||
338 | /* | 335 | /* |
339 | ** {============================================================== | 336 | ** {============================================================== |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.351 2018/03/16 14:21:20 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.352 2018/04/02 17:52:07 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1560,19 +1560,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1560 | } | 1560 | } |
1561 | vmbreak; | 1561 | vmbreak; |
1562 | } | 1562 | } |
1563 | vmcase(OP_UNDEF) { | ||
1564 | TValue *rb = vRB(i); | ||
1565 | luaT_keydef(L, vra, rb, 1); | ||
1566 | vmbreak; | ||
1567 | } | ||
1568 | vmcase(OP_ISDEF) { | ||
1569 | TValue *rb = vRB(i); | ||
1570 | TValue *rc = vRC(i); | ||
1571 | int res; | ||
1572 | Protect(res = luaT_keydef(L, rb, rc, 0)); | ||
1573 | setbvalue(vra, res == GETARG_k(i)); | ||
1574 | vmbreak; | ||
1575 | } | ||
1576 | vmcase(OP_CALL) { | 1563 | vmcase(OP_CALL) { |
1577 | int b = GETARG_B(i); | 1564 | int b = GETARG_B(i); |
1578 | int nresults = GETARG_C(i) - 1; | 1565 | int nresults = GETARG_C(i) - 1; |