[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Help with Lua Socket Library
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 3 Aug 2011 14:36:23 -0300
> Or some way to convert the lua string "1", for example, to the bytes
> corresponding to C-integer 1?
If x contains the number to be sent, send this string:
string.char(
math.floor(x/256^0)%256,
math.floor(x/256^1)%256,
math.floor(x/256^2)%256,
math.floor(x/256^3)%256
)
or this, depending on the order you want the bytes:
string.char(
math.floor(x/256^3)%256
math.floor(x/256^2)%256,
math.floor(x/256^1)%256,
math.floor(x/256^0)%256,
)