lua-users home
lua-l archive

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

On Mon, Aug 1, 2011 at 2:47 PM, Chris Datfung <> wrote:
> I have a variable that contains numeric values separated by a comma, e.g.
> Values = "1, 7, 5". I want to figure out which value within that variable is
> the lowest and highest. The math.min and math.max functions seem most
> appropriate except that they wont accept a variable as an argument. Is this
> possible with the built in math functions or do I need to parse the variable
> and compare values with tonumber()?
> Thanks,
> Chris

It definitely isn't readily possible just with math functions. If your
'Values' string does not come from an untrusted source you could do
something a little hacky like this:

 MaxValue = math.max(loadstring("return " .. Values)())

...otherwise, yes, you will need to parse it yourself.