From: Tobias Ulmer Date: Fri, 1 Feb 2013 17:34:38 +0000 (+0100) Subject: Undeclared field access is ok unless field is a string. X-Git-Tag: e2factory-2.3.13rc1~34 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=170df7f12830e17701c8aeebf010a71b9bf8fc69;p=e2factory.git 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 --- 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)