lua-users home
lua-l archive

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

2008/9/17  <>:
> 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 "" as
> input then its takes as integer and reads only first element 169 and
> system hangs.ex:-vxDo("functionname","","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))
	return num