This is a code dump of a script I wrote to change train schedules in factorio. The API states that the schedule must be deep-copied by value and then can be modified and set as one object rather than mutating the in-place runtime object/structure.
The deepcopy function from http://lua-users.org/wiki/CopyTable seems to work fine for this purpose.
/c
function deepcopy(orig, copies)
copies = copies or {}
local orig_type = type(orig)
local copy