x[1] is {} which, evaluated as a boolean, is true in Lua. The only false objects are `false` and `nil`, unlike other languages such as Python.
As 'x' has weak values the original author expected the garbage collector to dispose of the {} value eventually, but the Lua garbage collector was not running because the loop did not allocate any storage. Adding "local tmp = {}" to the body of the loop causes the loop to terminate eventually because x[1] will return nil.
The crucial point is that the Lua garbage collector is called by the routines that allocate storage.
--