Disculpa, la verdad he estado algo ocupo y no había podido poner aquí la función para tí. Algo que me emocionó con lua lanes fue que si antes mi función FileFind tardaba escasos 28segundos en buscar todas las dll, dat y exe del directorio de windows (poco más de 1400 archivos) ahora tarda menos de 3 SEGUNDOS, lo cual es impresionante y de locos jajaja (ejecutado en el core de lua tardó sólo 1.6 segundos).
Ahora, un thread creado con lanes no se puede creado sino es a través de un linda object. Pero no veo la necesidad de cancelar subprocesos que tardan muy poco en concluir, salvo que se tratase de un subproceso infinito al estilo de las corutinas de evaluación.
Por cierto, no hay callback ya que no existe comunicación al exterior, ni interior, de un lane sino es con linda objects. Pero, ¿para qué un callback de 3segundos? jajajaja
Sin más preámbulo, te dejo mi función especialmente terminada para vos:
--Globals
require"lanes";
function fFileFind(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd)
require"lfs";
function FileFindA(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd)
local tS = (type(tSearch=="table")) and tSearch or {""};
local bC = bCaseSensitive or false;
if #tS > 0 then
for x, y in pairs(tS) do
local a = (bC==true) and y or string.gsub(y, "(.)", function(s) return string.lower(s) end);
a = string.gsub(a, "(.)*(.)", function(s, sa) return "%b"..s..sa end);
a = string.gsub(a, "*(..)", function(s) return "%b"..s end);
a = string.gsub(a, "(..)(.)%.", function (s, ss) return (s=="%b") and s..ss.."." or s..ss.."%." end)
a = string.gsub(a, "^%.", "%%.")
tS[x] = string.gsub(a, "?", ".");
end
end
return FileFindB(sPath, tS, bSubFolders, bC, tToAdd);
end
function FileFindB(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd)
local tReturn = (type(tToAdd)=="table") and tToAdd or {};
local tDirs = {};
if lfs.chdir(sPath) then
for x in lfs.dir(sPath) do
if x ~= "." and x ~= ".." then
if lfs.attributes(x, "mode") == "file" then
for y, z in pairs(tSearch) do
local a = (bCaseSensitive==false) and x or string.gsub(x, "(.)", function(s) return string.lower(s) end);
if string.find(a, z) then
table.insert(tReturn, #tReturn+1, sPath.."\\"..x);
end
end
elseif lfs.attributes(x, "mode") == "directory" then
if bSubFolders then
table.insert(tDirs, #tDirs+1, sPath.."\\"..x);
end
end
end
end
if #tDirs > 0 and bSubFolders then
for x, y in pairs(tDirs) do
FileFindB(y, tSearch, true, bCaseSensitive, tReturn);
end
end
return (#tReturn>0) and tReturn or nil;
else
return nil;
end
end
return FileFindA(sPath, tSearch, bSubFolders, bCaseSensitive, tToAdd)
end
local FileFind = lanes.gen("*", fFileFind)
--On Click in a button
tFiles = FileFind("C:\\Windows", {".dat", "*.dll", "s*.exe"}, true, false, nil);
-On click in other label or timer
Debug.ShowWindow(true);
if tFiles.status == "done" then
if tFiles[1] then
Debug.Print("Files: "..#tFiles[1].."\r\n"..ptbl(tFiles[1]));--Busca mi función de imprimir tablas
else
Dialog.Message("", "NoFiles");
end
elseif tFiles.status == "error" then
local a, e = tFiles:join()
Debug.Print(tostring(e));
else
Debug.Print("Status: "..tFiles.status.."\r\n");
end