Hi,
What I am going to demonstrate here is extremely abstract. If there is interest I can follow up with a more detailed blog post on some various methods of building Lua based plugins at some point, but for now this will hopefully give you something to study.
This is aimed at answering your original question. There are a number of different things to consider depending on the functionality of your specific plugin, including scope, and whether there will be any asynchronous activity within separate modules. Such as methods from the Corona network library.
When developing in Lua, I tend to lean toward composition; passing specific modules to other modules where that functionality is needed. But again, this is very dependent on what you are trying to achieve with the plugin. Some methods are better than others.
In my experience, there are three main approaches; class instances, composition, and event driven. As noted, I tend to use composition, and because of the asynchronous nature of Corona, event driven more often. As others have mentioned, there is always a central point of entry which handles the other modules accordingly.
With all of that in mind, here are the various pieces presented in an abstract way and only with your original question in mind based on the composition methodology.
So first the project tree:
plugin
myplugin
dataHandling.lua
engine.lua
rendering.lua
myplugin.lua
main.lua
And the files:
myplugin.lua
local Library = require "CoronaLibrary"
-- Create library
local lib = Library:new{ name='myplugin', publisherId='com.develephant' }
return setmetatable( lib, { __index = require("plugin.myplugin.engine") } )
engine.lua
--=============================================================================
--== Plugin Components
--=============================================================================
local rendering = require("plugin.myplugin.rendering")
local dataHandling = require("plugin.myplugin.dataHandling")
--=============================================================================
--== Main Engine
--=============================================================================
local engine = {}
--=============================================================================
--== Engine Methods
--=============================================================================
function engine.doSomething()
--call a render method
rendering.doSomething()
--do some data handling
dataHandling.doSomething()
end
function engine.doSomethingWithInput(var1, var2)
--call rendering with argument
local result = rendering.doRenderThing(var1)
--return the result
return result
end
function engine.renderWithDataHandling()
local res = rendering.withDataHandling(dataHandling)
end
--=============================================================================
--== Engine Export
--=============================================================================
return engine
rendering.lua
--=============================================================================
--== Rendering Component
--=============================================================================
local rendering = {}
function rendering.doSomething()
--render something
end
function rendering.renderThing(var)
--render a thing, return result
return some_result
end
function rendering.withDataHandling(dataHandling)
local result = dataHandling.getSomeData()
--do some rendering stuff
return some_result
end
return rendering
dataHandling.lua
--=============================================================================
--== DataHandling Component
--=============================================================================
local dataHandling = {}
function dataHandling.doSomething()
--data handle and return result
return some_result
end
function dataHandling.getSomeData()
--get some data
return some_result
end
return dataHandling
main.lua
local myplugin = require("plugin.myplugin")
--These following methods live in the engine.lua
myplugin.doSomething()
local result = myplugin.doSomethingWithInput("hello")
This may end up leaving you with more questions than answers, but it does demonstrate a method to solve your original question in regards to plugins.
Hope this helps at least give you some initial direction.
-dev