lua three o'clock

 Lua functions can accept a variable number of parameters. Similar to the C language, three dots (...) are used in the function parameter list to indicate that the function has variable parameters. Lua puts the parameters of the function in a table called arg.

In addition to the parameters, there is a field n in the arg table that represents the number of parameters.

For example, we could rewrite the print function:

printResult = ""

 

function print(...)

    for i,v in ipairs(arg) do

       printResult = printResult .. tostring(v) .. "\t"

    end

    printResult = printResult . . "\n"

end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325633656&siteId=291194637