lua-users home
lua-l archive

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


If the float format is IEEE, you might try reading the data as a string and converting via one of the unpacking libraries at http://lua-users.org/wiki/LibrariesAndBindings - looks like there's a couple of choices: lpack & struct

Matthew Percival wrote:
G'Day,

	I have used LuaSocket in several scripts over the past year, and
currently it works perfectly for all my purposes, but there is something
new I would like to do that it currently cannot handle elegantly.

	I am currently using sockets to access a couple of different daemons,
whereby I can send and receive strings between a C application and a Lua
script.  This works quite well, but I would like to write a new
application where I send strings from Lua and receive floats back.  I
could convert the floats to strings, pass them, then convert them back
on the Lua side, but this would be inefficient and inelegant, so I would
rather pass floats as floats.  The trouble is that LuaSocket's
socket_recv() function expects strings, and Lua does not have types to
begin with, so I am at a bit of a loss as to what to do.

	The best idea I could come up with was to give socket.receive() an
optional argument to specify whether you are receiving a string or a
float.  The problems with this are that it is not a very `Lua' solution
(nowhere else do you specify types), and it does not work well into
socket_recv(), which expects char* as the container for the received
data.  From what I can tell, a wrapper function would not work either.

	I was just wondering if I could get any advice on this issue, as to
what the best path to take would be.  I seem to have exhausted all my
ideas for how to handle this problem, and would appreciate any thoughts
others may have.

	-- Matthew



--
Jim Mellander
Incident Response Manager
Computer Protection Program
Lawrence Berkeley National Laboratory
(510) 486-7204

Your fortune for today is:

Real programmers don't comment their code.  It was hard to write, it
should be hard to understand.