title: Corona SDK - How do we connect external functions to main.lua?
body: <p>Right now we have all our code gathered in main.lua. We don't want to work with object oriented code, but still find an easy way of splitting the different objects up into separated files.</p>
  
  <p>In our main.lua file we have objects like water, boat, boy, island and cloud - all together creating one massive bit of code. We want to have "BEGIN WATER 3" in it's own lua file and be able to execute that code in main.lua with a simple function instead. How do we do that?</p>
  
  <p>Here an example from our main.lua file, displaying "water3":</p>
  
  <pre><code>--------------- BEGIN WATER 3 ---------------------------------------------------------
  
  local watere = display.newImage( "water3.png", true )
  game:insert( watere )
  watere.y = 619
  watere.x = 500
  watere.xScale = 2
  
  --water sound
  local wavesound5 = media.newEventSound("waves.wav")
  
  local function playWave5 (event)
    media.playEventSound(wavesound5)
  end
  
  local w,h = display.contentWidth, display.contentHeight
  
  local function callbackFunc()
    print( "Transition 1 completed" )
  end
  
  local function mainwater(watere)
  end
  
  function loopar()
    local myTween = transition.to(watere, {time=2300, x=(400), y=(h-140), transition=easing.inOutQuad, onComplete=loopar2})
  end
  
  function loopar2()
    local myTween = transition.to(watere, {time=2200, x=(w-500), y=(h-120), transition=easing.inOutQuad, onComplete=loopar})
  end
  
  local listener2 = function()
    print( "Transition 2 completed" )
  end
  
  local myTween = transition.to(watere, {time=2300, x=(w-400), y=(h-140), transition=easing.inOutQuad, onComplete=loopar})
  
  watere:addEventListener("touch", playWave5)
  
  ---------------- END WATER 3 ---------------------------------------------------------
  </code></pre>