Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编程语言Lua中的整数_Lua_Numbers_Concatenation_Lua Table - Fatal编程技术网

编程语言Lua中的整数

编程语言Lua中的整数,lua,numbers,concatenation,lua-table,Lua,Numbers,Concatenation,Lua Table,我想通过table.concat获取所有数字 number = { 100.5, 0.90, 500.10 }; print( table.concat( number, ', ' ) ) -- output 100.5, 0.9, 500.1 number = { 100.5, 0.90, 500.10 }; print( table.concat( math.floor( number ), ', ' ) ) -- output 100 如何修复此错误?您不能,因为Lua中没有现成的表转换

我想通过
table.concat获取所有数字

number = { 100.5, 0.90, 500.10 };
print( table.concat( number, ', ' ) )
-- output 100.5, 0.9, 500.1
number = { 100.5, 0.90, 500.10 };
print( table.concat( math.floor( number ), ', ' ) )
-- output 100

如何修复此错误?

您不能,因为Lua中没有现成的表转换函数,您必须使用转换后的值创建一个新表,并满足以下条件:

number = { 100.5, 0.90, 500.10 };
intT ={}
for i, v in ipairs(number) do
     table.insert(intT, math.ceil(v))
end
print( table.concat( intT, ', ' ) )
如果您有很多这样的变换,那么很容易创建这样的变换器:

function map(f, t)
    local newT ={}
    for i, v in ipairs(t) do
        table.insert(newT, f(v))
    end    
    return  newT 
end
print( table.concat( map(math.ceil, number), ', ' ) )