-
Notifications
You must be signed in to change notification settings - Fork 4
WIP: Add non-blocking mode #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| -- REMOVE NEXT LINE BEFORE MERGING | ||
| package.path = ';./src/?/init.lua;./src/?.lua;/usr/local/share/lua/5.1/?.lua' | ||
|
|
||
| local losc = require'losc' | ||
| local plugin = require'losc.plugins.udp-socket' | ||
|
|
||
| local udp = plugin.new { | ||
| recvAddr = 'localhost', | ||
| recvPort = 9000, | ||
| non_blocking = true, -- do not block on :open(), :poll() handles processing | ||
| ignore_late = true, -- ignore late bundles | ||
| } | ||
| local osc = losc.new {plugin = udp} | ||
|
|
||
| local function print_data(data) | ||
| local msg = data.message | ||
| print('address: ' .. msg.address, 'timestamp: ' .. data.timestamp) | ||
| for index, argument in ipairs(msg) do | ||
| print('index: ' .. index, 'arg: ' .. argument) | ||
| end | ||
| end | ||
|
|
||
| osc:add_handler('/test', function(data) | ||
| print_data(data) | ||
| end) | ||
|
|
||
| osc:add_handler('/param/{x,y,z}', function(data) | ||
| print_data(data) | ||
| end) | ||
|
|
||
| osc:open() -- non blocking call :) | ||
|
|
||
| local i = 0 | ||
|
|
||
| while true do | ||
| print("Loop iteration " .. i) | ||
| require'socket'.select(nil, nil, 2) -- equivalent for sleep() to simulate other tasks | ||
| osc:poll() | ||
| i = i + 1 | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,13 @@ function losc:open(...) | |
| return pcall(self.plugin.open, self.plugin, ...) | ||
| end | ||
|
|
||
| function losc:poll(...) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you beat me to the PR!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I'll add it! |
||
| if not self.plugin then | ||
| error('"poll" must be implemented using a plugin.') | ||
| end | ||
| return pcall(self.plugin.poll, self.plugin, ...) | ||
| end | ||
|
|
||
| --- Closes an OSC server. | ||
| -- @param[opt] ... Plugin specific arguments. | ||
| -- @return status, nil or error | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you intended on removing this before creating the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!