lua-users home
lua-l archive

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


IMHO this can easily be achieved with gmatch.

On Wed, Dec 1, 2010 at 10:25 PM, Peter Odding <peter@peterodding.com> wrote:
>> LuaTeX adds this function to the string library:
>> ...
>> This function as it stands should not be added to the standard library.
>> However, an iterator function string.split(s,[,m]) such that
>> string.explode is equivalent to
>>
>> function(str,delim)
>>     local t={}
>>     for k in str:split(delim) do t[#t+1]=k end
>>     return t
>>     end
>>
>> maybe with delim not as restricted as in LuaTeX (i.e. normal string
>> patterns allowed) would be handy in many other applications too.
>> You can sort of mock it up using existing string functions but it
>> is surprisingly tricky to get it right.
>
> I've attached two scripts which implement the split() function you describe,
> both support Lua patterns. One returns a table, the other an iterator. I
> can't guarantee they're bug free, but they are definitely a good start.
>
>  - Peter
>