Skip to content

Instantly share code, notes, and snippets.

@jaseknighter
Last active September 30, 2021 03:59
Show Gist options
  • Save jaseknighter/91fd4189f5062a82d21f72e0d24cbfae to your computer and use it in GitHub Desktop.
Save jaseknighter/91fd4189f5062a82d21f72e0d24cbfae to your computer and use it in GitHub Desktop.
---sequin clone tester
-- press k2 to attempt to clone a sequin
--update line below with location of Sequins.lua
Sequins = include "splnkr/lib/Sequins"
function init()
sequins1 = Sequins{1,2,3}
set_redraw_timer()
end
function enc(n, d)
end
function key(n,z)
if n==2 and z == 0 then
print("trying to clone")
sequin2 = fn.deep_copy(sequins1)
end
end
--------------------------
-- redraw
--------------------------
function set_redraw_timer()
redrawtimer = metro.init(function()
redraw()
end, 1/1, -1)
redrawtimer:start()
end
function redraw()
screen.clear()
screen.move(20,20)
if sequins2 then
screen.text("sequins2: ".. sequins2())
else
screen.text("press k2: clone sequins1")
end
screen.move(20,35)
screen.text("sequins1: ".. sequins1())
screen.update()
end
------------------------------
-- deep copy function
------------------------------
fn = {}
function fn.deep_copy(orig)
local orig_type = type(orig)
local copy
if orig_type == "table" then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[fn.deep_copy(orig_key)] = fn.deep_copy(orig_value)
end
setmetatable(copy, fn.deep_copy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function cleanup ()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment