lua-users home
lua-l archive

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



Luiz Henrique de Figueiredo wrote:
That works if you always want that behavior, but I'd like it to only
return the nop function in particular cases.

If those "particular cases" depend on the table or index, then you can write

 settagmethod(tag(object),"index", function (t,i) DO SOMETHING HERE end)

I should have been more specific - I'd like to be able to use both types of lookups on the same table.

For example:

function ChatApp:draw()
  self:drawOutputText()
  ...
end

function Socket:receive()
  ...
  self._delegate:?socket_received_(self, data)
end


In this example, the Socket's delegate happens to be the ChatApp. I'd like the delegate message to be sent if the ChatApp implements the socket_received_ method and to be ignored otherwise, but I want the drawOutputText to raise an error if it's missing. Same table, different lookup behavior.

Steve