lua-users home
lua-l archive

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



On 07/05/2014 12:46, Philipp Janda wrote:
Am 07.05.2014 17:13 schröbte Thiago L.:

On 07/05/2014 12:00, Philipp Janda wrote:
Am 07.05.2014 15:40 schröbte Thiago L.:
So I have a challenge for you all: A table copy script in less than 270
chars


239 bytes. Stole some of your tricks. Not extensively tested but seems
to work ...

Philipp

Uhh it doesn't handle replacing _G.pairs with nil...

That is true. Of course you could add a local one-letter alias for `pairs` at the cost of 4 extra characters. While you are at it, replace `pairs(a)` with `next,a ` which saves another byte. So it's about 242 bytes now.

Also I don't like that wrapper function nonsense...
(table.copy.shallow(t,1) etc... bugs and obfuscation...)

There are no wrapper functions. I just used one function to implement the other via an extra boolean parameter (which you suggested in your OP, btw.).
What I talked about was deep KEY copy...
So for a table where t[x]=y where x is a table, you could make it keep x as it is or copy it by setting a boolean...

Both versions can't handle extra arguments correctly (my `shallow`, your `deep`), and both are properly obfuscated. I optimized specifically for code size which I thought was the challenge (obviously I misunderstood) ...

Of course, I wouldn't write nor use either version under normal circumstances.

Philipp