How can I make my module the same as a widget

Good day I would like my module to behave like this:
 

local newButton = widget.newButton{params}  

I would like to make my own version of a widget.newButton

sor far all I can do is this:

--new Module.lua local M = {} M.newButton = function(All Params insert here) --Do something here end return M

I don’t have much problems in here, but it looks so long and confusing for new users of my module, also for myself I still got confused with my function.

To be honest I’m not sure you can make it any simpler than that. You are returning 1 table with an attached function, that’s the minimum that is needed for a module to work as far as I know.  

I think this could only be confusing for people who are new to Lua/Corona, but for people who have a fair idea of how Corona works your module is not confusing or complicated.

The only place it may be long and confusing is inside the newButton function itself (where your example says “–Do something here”), depending on what you do there.

The only thing I can suggest is to change the function definition to this:

function M.newButton(All Params insert here) --Do something here end

There is nothing wrong with the way you have done it, but this way is a bit more consistent with other Corona samples so it may be a bit easier for people to read.

Corona’s Lua widget library is open source.  So, feel free to use it as an example.

   https://github.com/coronalabs/framework-widget/tree/master/widgetLibrary

Thanks guys! This is a big help!

To be honest I’m not sure you can make it any simpler than that. You are returning 1 table with an attached function, that’s the minimum that is needed for a module to work as far as I know.  

I think this could only be confusing for people who are new to Lua/Corona, but for people who have a fair idea of how Corona works your module is not confusing or complicated.

The only place it may be long and confusing is inside the newButton function itself (where your example says “–Do something here”), depending on what you do there.

The only thing I can suggest is to change the function definition to this:

function M.newButton(All Params insert here) --Do something here end

There is nothing wrong with the way you have done it, but this way is a bit more consistent with other Corona samples so it may be a bit easier for people to read.

Corona’s Lua widget library is open source.  So, feel free to use it as an example.

   https://github.com/coronalabs/framework-widget/tree/master/widgetLibrary

Thanks guys! This is a big help!