Simple demo of UI data-binding

Just posted a simple demo of data-binding to user-interface elements in Corona SDK. The purpose is to update variables so that UI elements (textfields in this demo) are updated automatically.

http://swfoo.com/2016/10/08/ui-data-binding-for-corona-sdk/

Dave

That’s a cool use for metatables :slight_smile:

I’m just curious, which benifit has this method over calling function (thas is defined via a metatable as well).

It’s nearly the same effort to do this:

UIElement:setText("newText")

Compared to this:

UIElement.text = "newText"

In both cases a function is called (with your method its done in the background) and the amount of symbols needed for both commands is nearly the same. Additionally, the use of a function is much clearer, as I can see where the change is happening (in the setText function), instead ob reading through the more cryptic meta functions.

The main reason for my use case is I am separating the data (model) from the UI. Most of the time I simply call the function to set text but not in the current app where things get complicated if I keep everything in one place. As for the metatable code, I leave it there and don’t look at it again :slight_smile:

That’s a cool use for metatables :slight_smile:

I’m just curious, which benifit has this method over calling function (thas is defined via a metatable as well).

It’s nearly the same effort to do this:

UIElement:setText("newText")

Compared to this:

UIElement.text = "newText"

In both cases a function is called (with your method its done in the background) and the amount of symbols needed for both commands is nearly the same. Additionally, the use of a function is much clearer, as I can see where the change is happening (in the setText function), instead ob reading through the more cryptic meta functions.

The main reason for my use case is I am separating the data (model) from the UI. Most of the time I simply call the function to set text but not in the current app where things get complicated if I keep everything in one place. As for the metatable code, I leave it there and don’t look at it again :slight_smile: