summaryrefslogtreecommitdiffstats
path: root/patches/lua-5.1.4/0010-__newindex-metamethod-may-not-work-if-metatable-is-i.patch
blob: 6c9f7e1df94f35d805ccc2908897c6b5d7bce8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= <benoit.burnichon@airtag.com>
Date: Tue, 6 Dec 2011 14:27:04 +0100
Subject: [PATCH] __newindex metamethod may not work if metatable is its own
 metatable.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Comes from http://www.lua.org/bugs.html#5.1.4-10

reported by Cuero Bugot on 09 Aug 2011.
Example:
 --
 meta={}
 setmetatable(meta, meta)
 meta.__newindex = function(t, key, value) print("set") end
 o = setmetatable({}, meta)
 o.x = 10    -- should print 'set'
 --

Signed-off-by: Benoît Burnichon <benoit.burnichon@airtag.com>
---
 src/lvm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/lvm.c b/src/lvm.c
index 4ac2e71..ca7bea0 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -142,6 +142,7 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
       if (!ttisnil(oldval) ||  /* result is no nil? */
           (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
         setobj2t(L, oldval, val);
+        h->flags = 0;
         luaC_barriert(L, h, val);
         return;
       }