Ferramentas do usuário

Ferramentas do site


geopro:pedro:tmedisc

Essa é uma revisão anterior do documento!


Operador # para CS, Neighborhood

toda metatable pode ter um operador “len”, que implementaria o operador #. O problema é que, para tabelas, ele não tem como ser chamado:

   function len_event (op)
     if type(op) == "string" then
       return strlen(op)         -- primitive string length
     elseif type(op) == "table" then
       return #op                -- primitive table length
     else
       local h = metatable(op).__len
       if h then
         -- call the handler with the operand
         return (h(op))
       else  -- no handler available: default behavior
         error(···)
       end
     end
   end
geopro/pedro/tmedisc.1274274572.txt.gz · Última modificação: 2010/05/19 13:09 por pedro