lua-users home
lua-l archive

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


On 02/18/2017 09:29 AM, Francisco Olarte wrote:
> Maybe I could be convinced
> by a better example.

Thank you for analysis and reply!

Let's try more "real" example.

Suppose we're implementing CRC calculation algorithm with predefined
polynomial (0xEDB88320). By trading space for time calculation may be
sped up by using precalculated values for any given byte of input
(256 values), or two bytes of input (65536 values) and so forth.

Say I do not wish to store 65536 elements table in same source
file with calculating function (which is near dozen lines). And
also I do not wish to calculate this table at load time (as it
is constant and may be precalculated and saved as separate file
by stand-alone code). Moreover, it can be saved as lua code
"return {<crc-values>}".

So in CRC calculation routine I just wish to say something like
"local crc_table = require('CRC_2bytes_EDB88320')" and then start
xor-ing input with it.

Yes, I may nullify "package.loaded" record for that module after
work but it seems like struggling with consequences, not eliminating
reason.

-- Martin