我对Lua很陌生。
说我有一根"1234567890“字串。
我想迭代所有可能的3位数。(即123,234,345,456....)
for m in string.gmatch("1234567890","%d%d%d") do
print (m)
end
但这给出了输出123,456,789。
我应该使用什么样的模式?
其次,还有一个相关的问题,我如何指定一个3-digit数字?"%3d"似乎不起作用。"%d%d%d"是唯一的路吗?
注意:这不是标记Regular expression,因为Lua没有Reg
我有以下代码:
local a = "/Users/diego/Desktop/nvim-file-location/lua/nvim-file-location/init.lua"
local b = "/Users/diego/Desktop/nvim-file-location"
local r = a:gsub(b, "")
print("path:", a)
print("cwd:", b)
print("replaced:", r)
我期望被替换的一个输出如下:
replaced:
我想把这个python代码转换成lua。
for i in range(1000,9999):
if str(i).endswith('9'):
print(i)
我已经走了这么远,
for var=1000,9000 then
if tostring(var).endswith('9') then
print (var)
end
end
但我不知道lua和endswith()是什么意思,我在写nmap脚本,
第一次与lua这样工作,请让我知道是否有任何错误,就我目前的代码。
我使用LUA的string.format(str,regex)来获取一些关键字。
local RICH_TAGS = {
"texture",
"img",
}
--\[((img)|(texture))=
local START_OF_PATTER = "\\[("
for index = 1, #RICH_TAGS - 1 do
START_OF_PATTER = START_OF_PATTER .. "(" .. RICH_TAGS[index]..")|"
end
START_OF_
我是Lua的新手,所以我现在正在学习操作符部分。Lua中是否有可以处理字符串的通配符?
我来自PHP背景,实际上我正在尝试编写以下代码:
--scan the directory's files
for file in lfs.dir(doc_path) do
--> look for any files ending with .jpg
if file is like ".jpg" then
--do something if any files ending with .JPG are scanned
end
e
我正在编写一个LUA脚本,用于阻止传入数据的任何部分中包含字符串"@7.7.7.7“的所有行。为此,使用了以下正则表达式:
local reg = regex.new("555d%|@7\.7\.7\.7\\b\|abc.com")
虽然这确实阻止了@7.7.7.7,但它也阻止了@757.787.84.91我对Lua编程语言进行了研究,它表明%(而不是)是魔术字符的转义字符。(点)因此,在模式“555d%x@7.7.7.7\b\\”中,\没有任何效果。被认为与任何字符匹配。然而奇怪的是,当我用%替换\时,它并没有阻塞包含"@7.7.7.7“的行。新模式如下:
l
我正在摆弄Lua,试图创建我自己的“脚本语言”。
它实际上只是一个字符串,它被转换成Lua代码,然后通过使用loadstring来执行。我的字符串模式有问题。当您分支(例如,在变量声明中定义一个变量)时,它会出错。例如,下面的代码会出错:
local code = [[
define x as private: function()
define y as private: 5;
end;
]]
--defining y inside of another variable declaration, causes error
之所以会发生这种情况,是因为声明变量
我试图创建一个正则表达式来匹配一个句子。
这是一个片段。
local utf8 = require 'lua-utf8'
function matchsent(text)
local text = text
for sent in utf8.gmatch(text, "[^\r\n]+\.[\r\n ]") do
print(sent)
print('-----')
end
end
但是,它不像python那样工作。我知道Lua使用不同的regex模式,它的regex功能是有限的,但是为什么上面的regex会给我一个语
有几个LUA脚本必须不断地执行。为了控制它的状态,我编写了小cmd/批处理文件:
@echo off
setlocal enableextension enabledelayedexpansion
set LIST=C:\123\lua_list
set EXEC_CMD="lua.exe"
for /f %%a in (%LIST%) do (
wmic process where "name like '%EXEC_CMD%'" get commandline | findstr /i %%a > nul
if errorlevel
我在项目的根目录中有一个松散的实用程序脚本name.ts。当需要时,我使用ts-node调用它。此脚本在实际源代码中的任何位置都未被引用。 我的程序的实际源代码在src下。 每当我尝试运行tsc (在tsconfig.json中,rootDir被设置为./src)时,它抛出: error TS6059: File '/home/rijndael/projects/mc/js/lua/generate.ts' is not under 'rootDir' '/home/rijndael/projects/mc/js/lua/scripts-ts'