[OSC_dev] handling nil/inf in oscpack
Ross Bencina
rossb-lists at audiomulch.com
Sat Mar 29 00:16:28 PDT 2008
Hi Graham
Very interesting. I have an oscpack/Lua binding too, we should compare notes.
For the use you describe (with the case statement) I recommend using the argument iterator instead of the argument stream (see the example in oscpack for details). That way the increment will be natural.
Probably the correct fix for the stream interface would be to return INF as a float with value numeric_limits<float>::infinity() and Nil perhaps as an int with value 0.
I agree an ignore manipulator might be handy too:
args >> osc::IgnoreArgument;
I should set up a sourceforge site for oscpack huh...
Best wishes
Ross.
----- Original Message -----
From: Graham Wakefield
To: Developer's list for the OpenSound Control (OSC) Protocol
Sent: Wednesday, March 26, 2008 7:44 AM
Subject: Re: [OSC_dev] handling nil/inf in oscpack
FWIW, I made a nasty kludge for the problem by adding this to class ReceivedMessageArgumentStream:
void hack_next()
{
p_++;
}
And doing this in my handler:
//process
unsigned long argc = m.ArgumentCount();
const char *addr = m.AddressPattern() ? m.AddressPattern() : "";
const char *tags = m.TypeTags() && argc ? m.TypeTags() : "";
osc::ReceivedMessageArgumentStream args = m.ArgumentStream();
//...
for(int i=0; i < argc; i++) {
switch(tags[i])
{
case 'f': {
float v; args >> v;
lua_pushnumber(L, v);
} break;
//.. etc. for other types
case 'T': {
bool v; args >> v;
lua_pushboolean(L, true);
} break;
case 'F': {
bool v; args >> v;
lua_pushboolean(L, false);
} break;
case 'N': {
args.hack_next(); ///<----- yuck
lua_pushnil(L);
} break;
//.. etc.
default: {
args.hack_next(); ///<----- yuck
lua_pushnil(L);
} break;
}
}
But really, I think there should be some method in ReceivedMessageArgumentStream along the lines of args.ignoreArgument().
Best,
Graham
On Mar 25, 2008, at 1:03 PM, grahamwakefield wrote:
Hi,
I'm writing a generic OSC-service for the Lua language, based on oscpack.
All is working wonderfully, except that I'm stuck on how to iterate past
Nil/Infinitum types in received message streams.
I'm not sure how to increment the ReceivedMessageArgumentStream pointer for
N and I types. In the source, there's a comment:
// not sure if it would be useful to stream Nil and Infinitum
// for now it's not possible
So my question: if there's a Nil or Infinitum embedded within a message
stream (e.g., type tags = "iNi"), how can I iterate past the Nil/Infinitum
and get the next argument? For T and F, I can use the >> operator to move to
the next argument, but there isn't an equivalent for N or I. Is there
another way to increment the stream?
Thanks,
Graham
Example:
send("test", 3, nil, 3)
->
received address:"test:
received types: "iNi"
received arg 1: 3
received arg 2: nil
terminate called after throwing an instance of
'osc::WrongArgumentTypeException'
--
View this message in context: http://www.nabble.com/handling-nil-inf-in-oscpack-tp16287337p16287337.html
Sent from the OpenSound Control (OSC) - Dev mailing list archive at Nabble.com.
_______________________________________________
OSC_dev mailing list
OSC_dev at create.ucsb.edu
http://lists.create.ucsb.edu/mailman/listinfo/osc_dev
Be seeing you
grrr waaa
www.grahamwakefield.net
------------------------------------------------------------------------------
_______________________________________________
OSC_dev mailing list
OSC_dev at create.ucsb.edu
http://lists.create.ucsb.edu/mailman/listinfo/osc_dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.create.ucsb.edu/pipermail/osc_dev/attachments/20080329/0e42df14/attachment-0001.html
More information about the OSC_dev
mailing list