]> git.e2factory.org Git - e2factory.git/commitdiff
Undeclared field access is ok unless field is a string.
authorTobias Ulmer <tu@emlix.com>
Fri, 1 Feb 2013 17:34:38 +0000 (18:34 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:14 +0000 (19:07 +0100)
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 <tu@emlix.com>
generic/strict.lua

index 60bc5b5b33405025a342d826b1d14f378db8848d..02b71d12b23814d783106d8a227a842622cb6a15 100644 (file)
@@ -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)