points = nil function getPoints() return points end function init(points_) points = points_ end function eval(t) if points == nil or #points < 2 then return nil end -- make a lua copy of the points local cache = {} for pointIdx, p in ipairs(points) do table.insert(cache, { x = p:getX(), y = p:getY() }) end -- compute the relevant point on the copy and return it for i = 2, #cache, 1 do for k = 1, #cache+1-i, 1 do cache[k].x = (1-t)*cache[k].x + t*cache[k+1].x cache[k].y = (1-t)*cache[k].y + t*cache[k+1].y end end return point.new(cache[1].x, cache[1].y) end