I have created a wrapper for the scrollview widget and when I first call it everything is fine - the internal ‘scrollview’ variable is referenced as intended.
When I remove the scrollview and, later, create it again, the internal ‘scrollview’ variable is still referencing the old value.
Why is this happening? Have I forgotten something fundamental about Lua closures?
local widget = require("widget") function widget.newDragItemsScrollView( params ) local scrollview = widget.newScrollView( params ) print("scrollview: ",scrollview) function scrollview:add( item, listener, dragtime, angle, radius, touchthreshold ) scrollview:insert( item ) touch = function( event ) touchevent = event if (event.phase == "began") then display.currentStage:setFocus( event.target, event.id ) event.target.hasFocus = true return true elseif (event.target.hasFocus) then if (event.phase == "moved") then scrollview:takeFocus(event) print(scrollview) -- always prints the FIRST value of scrollview return false else display.currentStage:setFocus( event.target, nil ) event.target.hasFocus = nil end return true end return false end item:addEventListener( "touch", touch ) end return scrollview end