Conversation
| @@ -0,0 +1,40 @@ | |||
| -- REMOVE NEXT LINE BEFORE MERGING | |||
| package.path = ';./src/?/init.lua;./src/?.lua;/usr/local/share/lua/5.1/?.lua' | |||
There was a problem hiding this comment.
Looks like you intended on removing this before creating the PR?
There was a problem hiding this comment.
I will remove it in an upcoming commit, like the comment and the PR says this is just a quick draft I put together for @davidgranstrom and you to review, thanks
But I guess eveyone installs with luarocks makeand this was not even needed in the first place!
| return pcall(self.plugin.open, self.plugin, ...) | ||
| end | ||
|
|
||
| function losc:poll(...) |
There was a problem hiding this comment.
you beat me to the PR!
I would add some documentation here:
--- Polls an OSC server.
-- Used by non-blocking plugins.
-- @param[opt] ... Plugin specific arguments.
-- @return bool representing if the plugin dispatched a message
-- @usage losc:poll()
There was a problem hiding this comment.
Thanks I'll add it!
I should maybe link to the PIL page that has an example of this as well: https://www.lua.org/pil/9.4.html
It's about coroutines but the purpose of the :timeout() method is clearly shown
|
Hi @Simon-L and thanks for this PR! I think The signature could look like this: --- Poll raw OSC packets.
-- @param[opt] ... Plugin specific arguments.
-- @return status, osc packet bytes or nil/error
-- @usage
-- -- nil is a valid return value so always check status and packet
-- -- before accessing the data.
-- local status, packet = losc:poll()
-- if status and packet then
-- -- do something with packet
-- end
function losc:poll(...)
if not self.plugin then
error('"poll" must be implemented using a plugin.')
end
return pcall(self.plugin.poll, self.plugin, ...)
endThis would be the implementation (for -- non-blocking
function M:open(host, port, timeout)
host = host or self.options.recvAddr
host = socket.dns.toip(host)
port = port or self.options.recvPort
self.handle:setsockname(host, port)
self.handle:settimeout(timeout or 0.0)
end
function M:poll()
return (self.handle:receive())
endAnd the main loop of your example would look like this: local i = 0
while true do
print("Loop iteration " .. i)
require'socket'.select(nil, nil, 0.25) -- equivalent for sleep() to simulate other tasks
local status, data = osc:poll()
if status and data then
local ok, err = pcall(Pattern.dispatch, data, udp)
if not ok then
print(err)
end
end
i = i + 1
endWe could also add Let me know what you think! |
|
@davidgranstrom I like the idea of having the |
|
Hey there thanks for the thoughts. I absolutely agree about not automatically dispatching although semantically speaking a non-blocking mode doesn't imply dispatching any differently than the blocking mode, but I get the idea! This also brings to the table the idea of being able to (re)route osc messages. @halee88 As far as I can tell from the code and @davidgranstrom's examples above, |
|
@Simon-L ahh good catch! I didn't see that |
Please do not merge as is :)
Related to #33 and #32
Attempted to add necessary methods for non-blocking, as far as I can tell this is working.
Basically it sets a timeout on receive so poll() just returns and other things can happen inbetween polling for new messages, what do you think? I haven't checked using other plugins with these changes.
Note that the new example has a temporary line to run from the source repo and bypas globally installed losc