C/C++ Background ... Best Way To Begin Corona?

I’m getting ready to purchase Corona, as I find it works very well for what I am currently needing. However, I have a general new user/programming question for anyone else who has used Corona after using standard programming.

I have a background in C/C++, so I understand the basics of Corona/Lua. However, I think my biggest hang-up is the lack of a main loop.

Without getting too existential about it, how should I go about “thinking” of the main.lua file?

Do I consider it to be similar to a main(){} without the opening and closing brackets?

I notice that items stay live throughout the process. I can draw stuff to the screen and it stays there: there is no end of the loop to terminate the program. It doesn’t kill automatically.

I guess I’m just a little foggy on how to think about the way the program works. It doesn’t flow like C/C++, so I am a little lost. What resources would be best for me to further my understanding of Lua/Corona vs C/C++?

Thanks a ton. [import]uid: 30399 topic_id: 11719 reply_id: 311719[/import]

You can fake it, just create a main loop, and in main.lua the last line of the script just calls main().

I just think if Lua as a functional programming, like C. I am coming from Objective C withs its delegates and mvc design.

Thinking of this as just functional helps me [import]uid: 61610 topic_id: 11719 reply_id: 42655[/import]

You might think of main.lua as a main() without the { }, but it is also kind of like the global space. All the variables (not inside a function) you declare are global. These are like global variables in C/C++. These don’t go away either.

But you are ultimately thinking about the problem wrong if you are looking for a main-loop. Corona is a event driven, and most modern APIs have moved to event driven systems because main-loop polling wastes CPU cycles and batteries.

In event driven programming, you are supposed to react to specific situations, not try to control everything at once.

If you really must think in terms of a run-loop, you might pretend this is the Corona architecture:

// Fake Corona code:  
int main()  
{  
 LoadLuaScripts();  
 ExecuteMainLua()  
 while(1)  
 {  
 switch(GetSystemState())  
 {  
 case NEXT\_FRAME:  
 InvokeLuaEnterFrame()  
 break;  
 case NEW\_MOTION\_DATA:  
 InvokeLuaAccelerometerGyroscopeGPSCompass();  
 break;  
 case END\_DISPLAY\_OBJECT\_ANIMATION:  
 InvokeLuaDisplayObjectEnd();  
 break;  
 // etc   
 }  
  
 }  
}  

Your obligation is to write useful things in the callback functions. We never give you direct access to control the while(1) loop.

But since all our platforms are also event driven, our code doesn’t really look like that.

[import]uid: 7563 topic_id: 11719 reply_id: 42904[/import]

Wow, awesome! Thanks for the helpful hints. I appreciate them. [import]uid: 30399 topic_id: 11719 reply_id: 42968[/import]