lua-users home
lua-l archive

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


I'm looking at the "programming in lua" book, I'm
using a dispatcher very similar to the one at section
9.4

the main loop in 9.4 is:

 for i=1,n do
          local status, res =
coroutine.resume(threads[i])
          if not res then    -- thread finished its
task?
            table.remove(threads, i)
            break
          else    -- timeout
            table.insert(connections, res)
          end
        end


however, if I remove the thread i with 

table.remove(threads,i);

isn't the table "moving" all items after i 1 step
back? 
 thus 1) there will be a thread which won't be called.
and 2) the last thread (n) will have a nil value,
causing potential problems trying to resume nil (I
suppose no major problemas as it'll probably be
ignored)

no pun intended, it's just that I'm starting to learn
lua and I have some concept problems with tables, so I
don't know exactly whats going on in that piece of
code.

TIA
Kak.


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com