String (g) Match

3

Well, I'm trying to transform a string into a table. I tried this way:

toset = "nb = 10, gb = 20, sb = 0, sfb = 0, ub = 0;"
toget = "nb = (.-), gb = (.-), sb = (.-), sfb = (.-), ub = (.-);"
t = toset:gmatch(toget)
for a,b,c,d,e in pairs(t) do
print(a.." "..b.." "..c.." "..d.." "..e)
end

But returns this error:

[string "stdin"]:4: bad argument #1 to 'pairs' (table expected, got function)

Does anyone know how to solve it? Thank you.

    
asked by anonymous 22.09.2014 / 00:57

1 answer

5

If you trust this string, then use

t = loadstring("return {"..toset.."}")()

Then you can check the contents of t with

for k,v in pairs(t) do
   print(k,v)
end
    
22.09.2014 / 01:23