I am not good in Lua and can not help you with this part, but on the CC Forum are many Turtle Programs and most of them are for Mining. http://www.computercraft.info/forums2/index.php?/forum/21-turtle-programs/
And when you want to dig a Space out, you can use Buildcraft Filler and Land marks...