Your original question asked for a "stock script" for this sort of joining.

puzzlecut_platform_preview_featured.jpg

Only last week, I discovered on Thingiverse: PuzzleCut OpenSCAD Library