An Eye On Design

Alex Souza's Blog
Home » Posts tagged 'lua'

Moving forward with the app

May 11th, 2010 Posted in design, development Tags: ,

[Disclaimer: This blog has no intentions to be a definitive opinion on Lua or Corona development. It is just an opinion, under the perspective of a non-professional developer, working for the first time with both technologies. If you find anything wrong with the expressed opinions, please feel free to comment and I will revise the text.]

I had lots of progresses in the past days, not only with Lua, but also with Corona. I bought the SDK, which gave me access to beta 2. Although I am not using any features from the beta code, it seemed to be very stable and with good potential.

I spent most of my time setting the interface (portrait and landscape modes), also learning the correct way to align text (thanks to all support coming from Corona forums!) and positioning/animating my main icons. Here a list of situations I found:

- As I mentioned, my app has portrait and landscape modes. In landscape, users will see a full 480×320 picture rendered. In portrait, they must see part of the “big picture”, in 320×480. I couldn’t find a way to use just one big image and position it accordingly. At the end, my temporary solution was to use 2 images, one for each scenario. My main concern here is the total size of the application, as I am duplicating files;

- I found a bug in rotating the status bar (it does not rotate at this moment). Ansca already flagged this as an official bug (see the image below);

photo 

App in portrait mode, with full menu closed (see the arrow).

Checking the current design, plus considering my and Corona’s limitations, I have reviewed some features and changing a little the application scope. Also, getting involved with Lua, I decided to review some coding too (that’s why I am not posting it here). I am cleaning the current code and I will post an update late today or tomorrow.

Overall, I am starting to enjoy Lua and looking forward to finish this app, in order to start a new one (probably a game).

photo1

App in landscape mode, with full menu opened.

Welcome! Bem vindo!

May 4th, 2010 Posted in development Tags: ,

[Disclaimer: This blog has no intentions to be a definitive opinion on Lua or Corona development. It is just an opinion under the perspective of a non-professional developer, working for the first time with both technologies. If you find anything wrong with the expressed opinions, please feel free to comment and I will revise the text.]

My app must be international. Saying that, I planned to allow it to find which is the current language setup in the device and, enabling the correct idiom according that. I created an “.idi” file for each language I am planning to reach. For example, the english.idi file contains:

line 1: Send Mail

line 2: More Picts

line 3: More Stories

and the list goes on…

Below the code I used to make the selection, according the information coming from the phone:

   1: — Read idiom file according locale

   2: local language = system.getPreference( “ui”, “language” )

   3: local translatedStrings = {}

   4: local function loadIdiom (language)

   5: local path = system.pathForFile(language, system.ResourceDirectory)

   6: local file = io.open(path, “r”)

   7: if file then

   8:    local i = 0

   9:    while true do

  10:      i = i + 1

  11:      local line = file:read(“*l”)

  12:       if line == nil then break end

  13:           — load all strings according idiom

  14:         translatedStrings[i] = line –.. “\n”

  15:     end

  16:       print(translatedStrings[1])  –shows first line

  17:   end

  18:   io.close(file)

  19: end

  20:  

  21: if language == “en” then

  22:  loadIdiom(“english.idi”)

  23: elseif language == “pt” then

  24:  loadIdiom(“brazilian.idi”)

  25: else

  26:  loadIdiom(“english.idi”)

  27: end

  28:  

As you can see, I started getting the current language at line 2. Lines 21 to 27 select the correct .idi file and call the function loadIdiom, which reads the correct file and save all lines in a table (array). With this table, I will be able to call the correct string according the number of the line. For example, when I need to refer to string Send Mail, I will use translatedStrings[1], considering the string Send Mail is in the first line of the .idi file.

Hope it helps!

Alex

Lua and Corona

May 3rd, 2010 Posted in development Tags: ,

image

After mocked up my main interface and define my feature list, I evaluated the things I can and cannot do with the current Corona SDK (I can’t get access to the beta SDK as I am using the trial version). My list of CAN’T do includes:

- no support for SQLLite database (this is crucial in my case as I will have a list of places that must be available, even if the user is not connected) – I am addressing this with data in a text file. This is not the way I would like to implement but, considering I will have only hundreds of records, it will work;

- no MapKit integration, meaning I will not be able to render a map in a small part of the screen (when the user taps “see in the map” I will have to render a full HTML file showing the map, over the main screen;

- no native components nor keyboard available in landscape mode. This is hard, specially because I was thinking to address iPad as one of my targeting platform (Apple requires that the iPad interface works both in Portrait or Landscape);

- no email integration (I can’t create the email’s body programmatically);

Ansca has published its roadmap for Corona but, although several topics seems to be in their list, dates are far from final (in most cases they only say Q2/Q3, meaning something may be available from April to September– this is not the best way to get new customers to their platform!)

Knowing my limits, I read all Corona documents, plus the Lua official book and started to code. Some findings at this moment (please feel free to correct me if I missed something):

- You can’t find the same number of Lua samples in the web as you do for languages like Javascript or PHP. It is hard to move on when you are stuck;

- Lua book is not updated (the live code is different than the code printed);

- Corona does not implement the full Lua 5, meaning some functions are not available (after hours trying to work with dofile, for example, I figured out this is not available in Corona);

[Update: Scott's comment below confirms that all Lua 5.1 is implemented in Corona. Thanks for this info. I hope Ansca can create a table with the functions not available due security issues with the iPhone SDK]

- Because Corona does not have integration with SQLLite yet (Lua  can do that), I have to work a lot with arrays, a concept Lua does not have – the closest thing is tables. Problem is, tables are much more difficult/confuse to use than arrays (if you are familiar with arrays). Basic functions like arrayName.count (counts the number of elements in an array) do not exist in Lua tables (yes, in order to count how many elements I have in an array, I had to create a function who reads element by element and return the number found – crazy!).

[Update: Clearly I missed this info. There is a way to count arrays without the function I have used. In fact is is much simpler than I even imagined: to count the number of elements in a table called "places", all you have to do is: #places]

Although I expect a miserable life in the next weeks, developing in a language I do not know, without many examples to search, plus the fact Corona SDK documents could be improved (also it is oriented to games instead of apps), I will keep you posted on my progresses.

[Update: I agree that Corona offers lots of good examples and samples but I still think they could improve their documentation.]

Why am I doing that? Because I really think it is going to be easier to learn Lua/Corona plus developing my features according the limitations, than to learn Object-C. Time will tell if I am right or wrong (and you are going to know from here).

BTW, I have written a few functions I will comment in the next postings.

Alex