From 170df7f12830e17701c8aeebf010a71b9bf8fc69 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 1 Feb 2013 18:34:38 +0100 Subject: [PATCH] Undeclared field access is ok unless field is a string. strict does not have the ability to declare fields like arr[1]. Until functionality is added that allows this, disable the fatal error for all non-string types. Also fix up a couple of comments. Signed-off-by: Tobias Ulmer --- generic/strict.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/generic/strict.lua b/generic/strict.lua index 60bc5b5..02b71d1 100644 --- a/generic/strict.lua +++ b/generic/strict.lua @@ -37,6 +37,7 @@ local function what() end --- Lock a table against adding fields explicitly or by implicit assignment. +-- Prevent reading from undeclared fields. -- @param t table to lock function strict.lock(t) assert(type(t) == "table") @@ -61,7 +62,7 @@ function strict.lock(t) mt.__index = function(t, k, v) local mt = getmetatable(t) - if not mt.__declared[k] and what() ~= "C" then + if type(k) == 'string' and not mt.__declared[k] and what() ~= "C" then error("variable "..k.." is not declared") end @@ -90,7 +91,7 @@ end --- Test whether a table is locked. -- The implementation determines this by looking at certain keys, it's therefore --- not 100% accurate. +-- not 100% reliable. -- @param t table to check -- @return true if it's locked, false if not function strict.islocked(t) -- 2.39.5