Skip to content

Commit 1e622da

Browse files
authored
Fixed ii getter-response bindings generator for norns (#332)
* ii getters now return their first arg. breaks existing ii getters * fix norns ii bindings generator script, and support table style event arg * add getter functions to norns bindings
1 parent 5ded53e commit 1e622da

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

util/ii_norns_actions.lua

+24-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ end
2626
function make_ii(files)
2727
local c = header
2828

29+
c = c .. 'actions.init = function()\n'
30+
for _,f in ipairs(files) do
31+
if need_events(f) then
32+
c = c .. ' actions.' .. f.lua_name .. '.event = function(t,v) print("'
33+
.. f.lua_name
34+
.. ' ii: name=\'"..t.name.."\', device="..t.device..", arg="..t.arg..", value="..v) end\n'
35+
end
36+
end
37+
c = c .. 'end\n\n'
38+
2939
local function make_helpers(f)
3040

3141
function make_cmd_alias( device, name, args )
@@ -52,6 +62,7 @@ function make_ii(files)
5262
return cmd
5363
end
5464

65+
-- add .help command
5566
local h = make_cmd_alias( f.lua_name, 'help' )
5667
if f.commands then
5768
for _,v in ipairs( f.commands ) do
@@ -62,19 +73,25 @@ function make_ii(files)
6273
return h
6374
end
6475

65-
c = c .. 'actions.init = function()\n'
66-
for _,f in ipairs(files) do
76+
local function make_getter(f)
77+
local c = ''
6778
if need_events(f) then
68-
c = c .. ' actions.' .. f.lua_name .. '.event = function(i,v) print("'
69-
.. f.lua_name
70-
.. ' ii: "..i.." "..v) end\n'
79+
c = 'actions.' .. f.lua_name .. '.get = function(cmd,...)\n'
80+
.. '\tlocal t = {...}\n'
81+
.. '\tlocal s = string.format("ii.' .. f.lua_name .. '.get(%q",cmd)\n'
82+
.. '\tfor i=1,#t do s = s .. "," .. t[i] end\n'
83+
.. '\tcrow.send(s .. ")")\n'
84+
.. 'end\n'
7185
end
86+
return c
7287
end
73-
c = c .. 'end\n\n'
88+
7489
for _,f in ipairs(files) do
7590
c = c .. 'actions.' .. f.lua_name .. ' = {}\n'
76-
.. make_helpers(f) .. '\n'
91+
.. make_helpers(f)
92+
.. make_getter(f) .. '\n'
7793
end
94+
7895
return c .. footer
7996
end
8097

util/ii_norns_events.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function make_ii(files)
2828

2929
for _,f in ipairs(files) do
3030
if need_events(f) then
31-
c = c .. 'events.' .. f.lua_name .. ' = function(i,v) crow.ii.'
32-
.. f.lua_name .. 'event(i,v) end\n'
31+
c = c .. 'events.' .. f.lua_name .. ' = function(t,v) crow.ii.'
32+
.. f.lua_name .. '.event(t,v) end\n'
3333
end
3434
end
3535

0 commit comments

Comments
 (0)