lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks dirk,

But as i said, i need to specify a starting position (which doesn't exist in gmatch and gsub functions) and can't afford to split my string.



Le 29/05/2015 21:22, Dirk Laurie a écrit :
I usually do it with gsub. Not my own idea, I saw it in
some code of Roberto's.

t = {}
data:gsub(pattern,
    function(captures)
       t[#t+1] = do_something_with_captures
    end)

In yiour example, where you want numbers and booleans
to be translated, I would do this:

item = (function ()
    local code = load(item)
    if code then return code() end
end)() or item

If "item" is valid Lua code, it is replaced by its value, otherwise
it stays unchanged.