LUA queue implementation
<p>I am trying to implement a simple FIFO queue in Lua, code as follows:</p>

<pre><code>dataQ = {}
dataQ.first = 0
dataQ.last = -1
dataQ.data = {}

function insert(q, val)
  q.last = q.last + 1
  q.data[q.last] = val
end

function remove(q)
    if (q.first &gt; q.last) then 
      rval = -1
    else
      print("remove: q.data[q.first]= ", q.data[q.first], "  q.first= ", q.first)
      local rval = q.data[q.first]
      print("remove: rval= ", rval)
      q.data[q.first] = nil        -- to allow garbage collection
      q.first = q.first + 1
      print("remove: q.first= ", q.first)
    end
    return rval
end

insert(dataQ,"a")
insert(dataQ,"b")
insert(dataQ,"c")
for i,v in pairs(dataQ.data) do
    print(i, v)
end
repeat
    local x = remove(dataQ)
    print("list item= ", x)
until (dataQ.first &gt; dataQ.last)
</code></pre>

<p>When I load the script into the ESP8266 (via ESPlorer) I get the following lua interpreter error:</p>

<pre><code>LUA interpreter error detected!
stdin: 1: ')' expected near ']w([[   print("remove: rval= ", rval)]]);
</code></pre>

<p>However the script runs, and I get the following output:</p>

<pre><code>1   b
2   c
0   a
remove: q.data[q.first]=    a     q.first=  0
remove: rval=   nil
remove: q.first=    1
list item=  nil
</code></pre>

<p>The queue insert function appears to be working as expected, but the queue remove function is not. The first lua print statement in the remove function shows the correct expected value for q.data[q.first], but after the assignment of rval the value is "nil" instead of the expected "a"</p>

<p>I think I am misunderstanding a fundamental lua concept here, but I can't figure out what it is. </p>