how to use string.find on a table together with a regular expression

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
coroco
Noobzor
Noobzor
Posts: 10
Joined: Wed Jul 28, 2021 4:01 pm
Reputation: 0

how to use string.find on a table together with a regular expression

Post by coroco »

hi, so I have a function that prints modules, the problem is that I don't know what to use to find the module, I tried string find on the table but I get an error "bad argument # 1 to 'find' (string expected, got table)" so what do I need to use to search for a given module?

An example with string.find

Code: Select all

string.find(v,'gam(.*).tmp')
must be with a regular expression because the module suffix is ​​mutable np gamxxxx.tmp

function modules

Code: Select all



function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = ''..k end
         if v == 'Gam4B80.tmp' then print(v)
         end
         s = s .. '['..k..'] = ' .. dump(v)

      end
      return s .. '} '
   else
      return tostring(o)
   end
end

t = enumModules()
d = dump(t)



GreenHouse
Expert Cheater
Expert Cheater
Posts: 852
Joined: Fri Oct 12, 2018 10:25 pm
Reputation: 896

Re: how to use string.find on a table together with a regular expression

Post by GreenHouse »

Like a month ago I did make a DLL's and symbols dumper, and I used string.match for it, so you should be able to make it work that way:

Code: Select all

string.match(StringVariable,'StringToFind')
So, use match to see if it includes 'gam' and '.tmp' in its name, and if so then print it or do what you want to do with it.

coroco
Noobzor
Noobzor
Posts: 10
Joined: Wed Jul 28, 2021 4:01 pm
Reputation: 0

Re: how to use string.find on a table together with a regular expression

Post by coroco »

GreenHouse wrote:
Thu Sep 16, 2021 7:41 am
Like a month ago I did make a DLL's and symbols dumper, and I used string.match for it, so you should be able to make it work that way:

Code: Select all

string.match(StringVariable,'StringToFind')
So, use match to see if it includes 'gam' and '.tmp' in its name, and if so then print it or do what you want to do with it.
problem with lua engine throws 'string expected, got table' error
Image

Code: Select all

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = ''..k end

         if string.match(v,'gam(.*)') then print(v) end

         s = s .. '['..k..'] = ' .. dump(v)
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

t = enumModules()
d = dump(t)

coroco
Noobzor
Noobzor
Posts: 10
Joined: Wed Jul 28, 2021 4:01 pm
Reputation: 0

Re: how to use string.find on a table together with a regular expression

Post by coroco »

I managed to solve it, I don't know if code it is fully correct but it works

Code: Select all

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = ''..k end
         s = s .. '['..k..'] = ' .. dump(v)
         a = tostring(v)
         if string.find(a,'^Gam(.*).tmp') then print(a) end
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

t = enumModules()
d = dump(t)



Post Reply

Who is online

Users browsing this forum: No registered users