lua-users home
lua-l archive

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


1. How would string.find know that a particular return value should be a number?
2. I don't think it's a job of 'find' routine to interpret the matches fould. It's job is literally 'to find'. 

So, regardless how hard of easy it would be to make string.find do what you are asking for, in my view, it would be the wrong thing to do.

Alex


-----Original Message-----
From: Asko Kauppi [mailto:asko.kauppi@sci.fi]
Sent: Tuesday, September 14, 2004 2:34 PM
To: Lua list
Subject: numeric captures (string.find)



Would it be hard to make 'string.find()' return true numbers (not 
strings with numerical contents, as now):

	local _,_, a,b= string.find( "42 world", "(%d+)%s+(.+)" )

	--now: "42","world"
	--then: 42,"world"

I believe this little change would be welcome, and not cause major 
headaches in applications (they now have 'tonumber()', which would 
become irrelevant but work the same).

What do you think - would it get any votes?

-ak

ps. I tried to fix this with a small wrapper, but it gets very 
inefficient since the pattern string would need to be analyzed for each 
'string.find' call.  Doing it within strlib would just concern the case 
when the capture really is numeric, right?