title: How to remove a lua table entry by its key?
body: <p>I have a lua table that I use as a hashmap, ie with string keys :</p>
  
  <pre><code>local map = { foo = 1, bar = 2 }
  </code></pre>
  
  <p>I would like to "pop" an element of this table identified by its key. There is a <code>table.remove()</code> method, but it only takes the index of the element to remove (ie a number) and not a generic key. I would like to be able to do <code>table.remove(map, 'foo')</code> and here is how I implemented it :</p>
  
  <pre><code>function table.removekey(table, key)
      local element = table[key]
      table[key] = nil
      return element
  end
  </code></pre>
  
  <p>Is there a better way to do that ?</p>