Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have love.load(), love.draw() and love.update() in different files? and if so how would I go about doing that?

share|improve this question


It seems I misunderstood your question; you are not asking how to switch between different callbacks, you want to have them in different files.

The principle is the same:

load_module = require "main_load"
love.load = load_module.load

I've written a scene manager to do just that. I will open source it some day but to give you an idea here's how it is used:

-- main.lua
function love.load()
  scene_manager.add(require "scenes/foo")
  scene_manager.add(require "scenes/bar")

The change method looks like this:

  current_scene = scenes[scene_name]

Basically you need to iterate over the various methods (load, update as well as mousereleased for instance) and then do love[method_name] = nil.

Then in load_scene you need to set it love[method_name] = current_scene[method_name].

I know this is not a comprehensive answer but it should get you started. So, yes, it can be done.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.