Dynamic Loading

This is a question that many people ask, how can I create an app that can adapt to the device it is run on. The first factor that determines this is how large is the code and how modular can you make it.

There is a very cool trick that can be used in CoronaSDK/LUA that allows for dynamic loading and helps in creating universal apps that will adapt based on the device. This is actually quite an interseting and easy way to manage things. Keep different lua files for each device that you want to run the app on. Keep the specific routines that are for a particular device in the <devicename>.lua Try to keep the majority of the routines with the same function names so that it can work perfectly fine when using any of these lua files.

then the magic line is

require("").loadFunctions()

and the <devicename>.lua file would look like
module(...,package.seeall)

 function loadFunctions()
  -- all the code and functions etc come in here
 end
and you can create a similar file for other platforms. This can then be invoked whether manually or by getting the platform name by using the device Information.

cheers,

?:)

Comments

Popular Posts