Use the table pack and unpack to pack and unpack data. The test code is as follows:
Print ("test table. pack () ---------------- "); function printtable (t) If type (t) =" table "thenfor K, V in pairs (t) doprinttable (v ); endelseprint (t); endendlocal packdata = function (...) local Arg = table. pack (...); -- ARG. n to obtain the number of parameters for the variable part -- print ("Arg. n: ", Arg. n) for K, V in pairs (ARG) Do print ("----------------"); print (K, V); printtable (V); print ("----------------"); end return ARG; endpackdata ({type = 100, Param = {"param1", "param2", "param3"}); -- packdata ("param1", "param2 ", "param3", "param4", "param5"); print ("\ ntest table. unpack () ---------------- "); Local Data = {" AA "," BB "," cc "," DD "} print (table. unpack (data) print (table. unpack (data, 2) print (table. unpack (data, 2, 3 ))
Print data:
Variable Parameter Data packaging and unpacking in Lua tutorial