lua-users home
lua-l archive

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


> 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,
		)