Changes

Jump to navigation Jump to search

Overview of the API

539 bytes removed, 03:08, 7 May 2014
m
Line 73: Line 73:  
Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.</source>
 
Note : the (N) commented line only indicates the meaning of the routine. Those functions don't really exist.</source>
   −
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed. In other words, we cannot use niether '''gc''' nor '''platform.gc()''' (which are the same) in order to draw somthing on the screen if we are outside of '''on.paint()''' (except if your outside function is called within on.paint() ). This also means that we don't need to pass '''gc''' as parameter, because we can rather use '''platform.gc()''' for any functions called within on.paint(). This is exactly what [https://github.com/adriweb/BetterLuaAPI-for-TI-Nspire/blob/master/BetterLuaAPI.lua the BetterLuaAPI library for Nspire] does.  
+
Now we can understand how everything is linked, just by a main loop. This helps you to understand that you don't have to code a loop yourself, because the screen wouldn't be refreshed. This also helps to see when the screen gets refreshed.  
    
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).  
 
Here is an example of a simple Lua program that displays a message only when a key is pressed (and let the screen blank otherwise).  
Line 94: Line 94:  
  platform.window:invalidate() -- force display
 
  platform.window:invalidate() -- force display
 
  end</source>
 
  end</source>
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that&nbsp;? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again&nbsp;? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.  
+
When you open the document, the script is read once. It initializes and overwrites all the functions and globals with the ones you defined. Thus, '''message''' is nil. Once the '''on.paint()''' event is called, '''message''' is nil, thus, nothing is done. When you press a key that calls '''on.charIn()''' (see below for more information), '''message''' is now "Hello World" and we tell the '''platform''' that the screen has to be refreshed. Then, '''on.paint()''' is called again, '''message''' is not nil then we display it, erase '''message''' and launch a timer. Why is that&nbsp;? Because if we call '''platform.window:invalidate()''' right there, we won't refresh the screen. Why again&nbsp;? Just look at the pseudo-code above. We set the window as drawn after each call of on.paint(). Thus a timer is necessary to manually recall '''on.paint()''' and exit the '''on.paint()''' function to draw the screen. When the timer is ended, '''on.timer()''' is called and we refresh the screen. The screen is then redrawn but there is nothing to draw because '''message''' is nil. Thus, the graphic context lets the screen blank.
    
== gc (as in Graphics Context)  ==
 
== gc (as in Graphics Context)  ==

Navigation menu