[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Non-string recv() with LuaSocket...
- From: Matthew Percival <matthew@...>
- Date: Fri, 21 Apr 2006 09:54:42 +1000
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