df_expr_to_ref: support integer array indices

develop
lethosor 2017-05-07 16:31:30 -04:00
parent 60b5786d93
commit 8bda738466
1 changed files with 5 additions and 3 deletions

@ -659,15 +659,17 @@ df_env = df_shortcut_env()
function df_expr_to_ref(expr) function df_expr_to_ref(expr)
expr = expr:gsub('%["(.-)"%]', function(field) return '.' .. field end) expr = expr:gsub('%["(.-)"%]', function(field) return '.' .. field end)
:gsub('%[\'(.-)\'%]', function(field) return '.' .. field end) :gsub('%[\'(.-)\'%]', function(field) return '.' .. field end)
:gsub('%[(%d+)]', function(field) return '.' .. field end)
local parts = split_string(expr, '%.') local parts = split_string(expr, '%.')
local obj = df_env[parts[1]] local obj = df_env[parts[1]]
for i = 2, #parts do for i = 2, #parts do
local cur = obj[parts[i]] local key = tonumber(parts[i]) or parts[i]
local cur = obj[key]
if i == #parts and ((type(cur) ~= 'userdata') or if i == #parts and ((type(cur) ~= 'userdata') or
type(cur) == 'userdata' and getmetatable(cur) == nil) then type(cur) == 'userdata' and getmetatable(cur) == nil) then
obj = obj:_field(parts[i]) obj = obj:_field(key)
else else
obj = obj[parts[i]] obj = obj[key]
end end
end end
return obj return obj