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
source:match(“%d*”)在lua中的含义是什么?_Lua - Fatal编程技术网

source:match(“%d*”)在lua中的含义是什么?

source:match(“%d*”)在lua中的含义是什么?,lua,Lua,我对上面代码中%d之后的*感到困惑。如有任何意见,我们将不胜感激 都在Lua参考手册中 -- Parse speed value as kilometers by hours. function Measure.parse_value_speed(source) local n = tonumber(source:match("%d*")) if n then if string.match(source, "mph") or string.match(source, "mp/h

我对上面代码中%d之后的*感到困惑。如有任何意见,我们将不胜感激

都在Lua参考手册中

-- Parse speed value as kilometers by hours.
function Measure.parse_value_speed(source)
  local n = tonumber(source:match("%d*"))
  if n then
    if string.match(source, "mph") or string.match(source, "mp/h") then
      n = n * miles_to_kilometers
    end
    return n
  end
end
是string.matchsource的语法糖,%d*

string.matchs,pattern[,init]查找字符串s中的第一个模式匹配项。如果它找到一个,则匹配 从模式返回捕获;否则返回nil。如果 模式指定不捕获,然后返回整个匹配。A. 第三,可选的数值参数init指定从何处开始 搜索其默认值为1,可以为负值

, . 通过先查阅文档,可以避免很多问题。请不要误解,提问是可以的。不过,我们也欢迎您尽可能少的努力。谢谢。我的意思是,tonumbersource:match%dsource:match%d*中%d的后面是source.matchsource,%d*的缩写,它依次是string.matchsource,%d*,只要source是字符串,就通过metatablecorrect。%d和*的含义在第一个链接中描述。
source:match("%d*")