for table pack/unpack use code from Lua 5.2.2 source (ltablib.c:400-430)