limit on the number of captures using string.find?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

limit on the number of captures using string.find?

Jon Gross

Greetings from a lua newcomer!

I've searched the archive, but haven't found anything that is helpful  
for a problem I'm having.

I've run into a situation where I have a really long string that I'm  
reading from a file.

I need to split it up into pieces, that I can later reference (sort  
of like (foo,bar,baz) = split(/\s/,$str) in perl), so I'm doing this:


local pat = string.rep("baz", 46)

local _,_,foo,bar,bar = string.find(s, pat)

the problem is that whenever I make the pattern contain more than 31  
repetitions, lua complains:

lua: ./tcpext.lua:10: too many captures


Is there a limit on the number of captures that you can do?  If there  
is, does anyone have a good way of grabbing more than 31 chunks from  
a string and assigning those chunks to variables?

Any help is greatly appreciated!


--
Jon Gross
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: limit on the number of captures using string.find?

Jon Gross

On Feb 7, 2006, at 1:24 PM, Jon Gross wrote:

>
> Greetings from a lua newcomer!
>
> I've searched the archive, but haven't found anything that is  
> helpful for a problem I'm having.
>
> I've run into a situation where I have a really long string that  
> I'm reading from a file.
>
> I need to split it up into pieces, that I can later reference (sort  
> of like (foo,bar,baz) = split(/\s/,$str) in perl), so I'm doing this:
>
>
> local pat = string.rep("baz", 46)
>
> local _,_,foo,bar,bar = string.find(s, pat)
>
> the problem is that whenever I make the pattern contain more than  
> 31 repetitions, lua complains:
>
> lua: ./tcpext.lua:10: too many captures
>
>
> Is there a limit on the number of captures that you can do?  If  
> there is, does anyone have a good way of grabbing more than 31  
> chunks from a string and assigning those chunks to variables?

I found my problem in lstrlib.c -  a quick change, and a recompile,  
and off I go...

--
Jon Gross
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: limit on the number of captures using string.find?

Javier Guerra Giraldez
On Tuesday 07 February 2006 6:02 pm, Jon Gross wrote:
> On Feb 7, 2006, at 1:24 PM, Jon Gross wrote:
> >
> > Is there a limit on the number of captures that you can do?  If
> > there is, does anyone have a good way of grabbing more than 31
> > chunks from a string and assigning those chunks to variables?
>
> I found my problem in lstrlib.c -  a quick change, and a recompile,
> and off I go...

much better would be to string.gfind() iterator to loop over it.

--
Javier

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: limit on the number of captures using string.find?

Jon Gross

On Feb 7, 2006, at 3:37 PM, Javier Guerra wrote:

> On Tuesday 07 February 2006 6:02 pm, Jon Gross wrote:
>> On Feb 7, 2006, at 1:24 PM, Jon Gross wrote:
>>>
>>> Is there a limit on the number of captures that you can do?  If
>>> there is, does anyone have a good way of grabbing more than 31
>>> chunks from a string and assigning those chunks to variables?
>>
>> I found my problem in lstrlib.c -  a quick change, and a recompile,
>> and off I go...
>
> much better would be to string.gfind() iterator to loop over it.
>

Of course it would!

I've switched to that now that I've spent a little more time learning  
more lua...like I said, I'm a beginner.

Thanks for the pointer!


--
Jon Gross
[hidden email]