Log In  

I was playing around with loops and learning exactly how iterators work and stumbled across this...

When we write the following:

for k,v in pairs(t) do ... end

In regular lua it is identical in function to writing this:

for k,v in next,t do ... end

Because that's what pairs(t) returns: the builtin next() function, which iterates over the hash table that underlies lua tables, and t.

In PICO-8, we don't have direct access to next(), but we can get it:

next=pairs(any table, doesn't matter)

Once done, we've spent 5 tokens getting it. However, the "in next,t" form of the loop is one token shorter (and two characters). So if you convert more than 5 loops, you're saving.

I know it's minor, but I know some of you end up scrimping and saving for single tokens, so I thought I'd pass it on. Um. Enjoy? ;)


@zep: any chance we could just get next() available directly?

P#43095 2017-08-05 16:42 ( Edited 2017-08-05 20:45)


[Please log in to post a comment]