You can use string.dump, which “returns a string containing a binary representation (a binary chunk) of the given function, so that a later load on this string returns a copy of the function (but with new upvalues).”
solved How to compress lua to numbers