lua-users home
lua-l archive

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


Why not convert the IP address to an integer till the last moment of
use ? A search showed up this link. I'm not sure how helpful it will
be http://www.onlamp.com/pub/a/onlamp/2006/02/16/introducing-lua.html?page=3
And the code snippet that Jerome gave might be more relevant here.

On Wed, Sep 17, 2008 at 8:45 PM, Jerome Vuarand
<jerome.vuarand@gmail.com> wrote:
> 2008/9/17  <adimurthy.sriramulu@wipro.com>:
>> In my project requirement there is a lua wrapper function which is
>> function pointer and takes any C function name and its parameters as
>> input and execute that C function.
>> Ex:- vxDo("functionname","memStats","murthy",1,2)
>>
>> its works fine for strings,integers as function parameters as mentioned
>> above.However if we pass IP address ie for example "169.254.0.4" as
>> input then its takes as integer and reads only first element 169 and
>> system hangs.ex:-vxDo("functionname","169.254.0.4","memStats",1,2)
>>
>> It will be gratefull if somebody throws some light on how to parse the
>> whole IP address in lua.
>
> Do you want to pass the ip address as an int ? If so you can use the
> following code:
>
> function iptonumber(str)
>        local num = 0
>        for elem in str:gmatch("%d+") do
>                num = num * 256 + assert(tonumber(elem))
>        end
>        return num
> end
>