lua-users home
lua-l archive

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


I did something like that in the past: I had a data file, but some cases were complex, so I put a function there to solve the case.

  ["argenteuil"] =
  {
    ru = { liasse = "25", voie = "rue du Pont d'Argenteuil" },
    av1 = { liasse = "637", voie = "av. d'Argenteuil" },
    av2 = { liasse = "0000", voie = "av. du Vx Ch. d'Argenteuil" },
    special =
      function(voie)
        local f = string.find(string.lower(voie), "rue")
        if f ~= nil then
          return "ru"
        else
          -- Avenue
          f = string.find(string.lower(voie), "ch")
          if f == nil then
            return "av1"
          else
            return "av2"
          end
        end
      end
  },

Then we can check if the type of a field is a function, and if so, call it to get the value.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --