lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It would be possible to go ahead and evaluate it yourself it you want (assuming you're ok with just the dot sugar and ignoring everything else). I didn't bother to translate this into C, but it should be fairly trivial to do:

function lookup(str)
   -- Example str: "foo.bar.baz";
   local current = getfenv(1);
   for var in str:gmatch("([^%.]+)") do
      current = current[var];
   end

   return current;
end


Please note the above sample is untested. I should also point out that this has the added benefit of causing built-in Lua errors, so if I were to do something like "os.some.table.that.doesnt.exist" I will correctly get "Attempt to index field 'some' (a nil value)" without any additional work.

Regards,
-- Matthew P. Del Buono