The DMC Corona Library is a collection of classes and utilities that I have created while developing apps using Corona SDK. I thought it might be useful to others so I decided to polish it to make it into a re-usable framework.
Right now there are three core files (more coming):
There are many examples contained within the library and online documentation is available.
The library can be found on github: https://github.com/dmccuskey/DMC-Corona-Library
Enjoy !
====================================
Here are the details:
This file contains several methods and object classes which together form an object-oriented framework to use when programming in Lua with Corona SDK. Though it's not just for Corona - the top-level object classes can be used when developing software in plain Lua.
When doing OOP, these classes provide:
dmc_objects is structured after the classical inheritance model, thus is easy to learn and use by people with varying levels of experience. This also helps give a solid organizational structure when using a language that is relatively unstructured.
The framework also abstracts the details of doing inheritance in Lua so that both experienced and inexperienced users of the language can focus on the code being written, and not the gory details of the language - ie, there is no need to learn about Lua metatables until you want to know. All of that is taken care of so you can get things done.
Because of the way Lua performs lookups for properties and methods, there can be a small performance penalty when using objects with many levels of inheritance. The solution for this is to get an object's properties and methods as close to the object as possible (ie, ON the object). dmc_objects does this for you so you can get the execution speed without having to sacrifice the benefit of code organization provided by object-oriented programming.
The object model in dmc_objects was built to provide getters and setters in your object classes ! Go ahead, you can say it, "Yay, getters and setters !!!"
Among other object-related methods, dmc_objects has superClass() to access an object's parent, and superCall() which allows you to call an overridden method on a super class !
The core Corona Object API and Corona Physics Body API have been added to the pertinent base classes in dmc_objects. This allows you to treat your custom objects as if they were native Corona Display Objects †.
There is flexible, built-in support to print objects during debugging.
† You can treat them like Corona objects 99.5% of the time. Don't worry, the other 0.5% is easy to understand. :)
Documentation
Quick Guide: http://docs.davidmccuskey.com/display/docs/Quick+Guide+-+dmc_objects
API: http://docs.davidmccuskey.com/display/docs/dmc_objects.lua
Main Docs: http://docs.davidmccuskey.com/display/docs/dmc_buttons+Documentation
Examples
There are several examples in the folder examples/dmc_objects/ which show how to setup OOP structures in Lua. Among these are some original Corona examples which have been modified to use dmc_objects and fit into an OOP style of programming. These will make it easier to see how to move your projects to be object-oriented as well.
This file contains classes to create different types of graphical buttons and button groups. It can create:
The code in this file is also great if you're looking for an example of multi-level class inheritance in Lua. If you want an easier example of multi-level inheritance, see examples/dmc_objects/DMC-Multishapes/.
Documentation
Quick Guide: http://docs.davidmccuskey.com/display/docs/Quick+Guide+-+dmc_buttons
API: http://docs.davidmccuskey.com/display/docs/dmc_buttons.lua
Main Docs: http://docs.davidmccuskey.com/display/docs/dmc_buttons+Documentation
Examples
There are examples in the folder examples/dmc_buttons/ which show how to use the dmc_buttons library. Other examples use the button class as well - check in examples/dmc_objects/.
This file is a small, but growing list of helpful utility functions. At the moment they are mostly concerned with tables. It provides these functions:
Documentation
API: http://docs.davidmccuskey.com/display/docs/dmc_utils.lua
Examples
As of yet there are no specific examples for dmc_utils, however the other files in this library make use of it. Check them for examples.
License
(The MIT License)
Nice one David,
It is a very good tight implementation like a C++ class, which is good and hmmmm, not required all the time.
Nevertheless, a good port of lua to c++ ?;)
cheers
?:)
Thanks for sharing, the tab bar example rocks!
Hi,
In the dmc_objects.lua file, you encapsulate the Corona functions, does this mean any new functions created by Corona you will need to add to your class?
thanks,
hi marqshaw,
right now, yes - you'd have to add new functions as they come available.
however, since i've hacked into the Lua property lookup to implement getters/setters, i'm sure it would be pretty easy to include auto-lookup on the Corona object itself.
as you can imagine, it would certainly be preferable to have that in place so to lessen the maintenance for the project. i'll make sure that's on my todo list, unless you want to submit a patch. :)
cheers,
david
I have trouble inserting objects into display groups. when i do this a get "bad argument #-2 to 'insert' (Proxy expected, got nil)". is it a bug or known limitation?
hi krzysiek,
that error is happening because Corona display groups only accept native Corona objects.
by design, there is always a native Corona object available in a dmc object which can be added to a display group. by default this object is itself a Corona display group and is accessible via the property called 'display'.
here are some lines of code taken from one of the code examples at github. they form a simple example of how this works:
1 2 3 4 5 6 7 8 9 10 11 12 | -- here we have a native Corona display group object local shapeGroup = display.newGroup() -- here we create a object which uses the dmc object library local shape = ShapeFactory.create() --[[ we want to add the dmc object to the native Corona display group, so we pass in the native Corona object contained within the dmc object. it is accessible via the property 'display' --]] shapeGroup:insert( shape.display ) |
cheers
David
David,
I am looking for some add-ons into the libraries. Would you be available/interested in hear what I need (I will pay the implementations, of course)?
If so, send me a note to alex@asouza.com
@gtatarkin I kind of hoped the automated the process. Or I mis understood their message. They asked us to redownload Cider cause some things couldn't be done through the regular update. Don't think they want to answer a lot of mails handing out new links and passwords by hand.
Looks pretty sweet, can't wait to test it out!