Jump to content



Photo
- - - - -

Takeflight's Luazm Guide For Casio-Basic Developers


  • Please log in to reply
No replies to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 01 May 2013 - 10:25 PM

(originally posted on the Take Flight blog by myself)

Should I use LuaZM for my project?



Posted Image

If you are developing a math program that requires lots of user string input, the current version of LuaZM may not be ideal. But pretty much anything else you would have wanted to do in BASIC can be done better (and faster) in Lua.

Operators



The operators in Lua are a little different than in BASIC.
== equals
~= does not equal
> more than
< less than
>= more than or equal to
<= less than or equal to

Note that the single equals sign (=) is not used as an equality operator. It is used to assign values to variables, as we'll see later on.

Variables



Variables can have any name you want



Unlike with BASIC, with Lua you can name a variable pretty much anything you want (besides names like if or break, which are reserved for Lua program execution). No more running out of letters for variables!

Assigning values to variables



In Casio-BASIC, variable assignment is done with the -> symbol, like this:

Value->Variable

In Lua, the assignment operator is the single equals sign (=), and the value and variable in the opposite places:

Variable=Value

Variable types



Number



A number can be stored to a variable, just like in BASIC. Lua actually has different kinds of number types, but the programmer doesn't usually have to worry about them. 1, 8.9758, -159 are all examples of valid Lua number values.

String



A string is just a line of numbers and letters, treated as data, just like in BASIC. The differences are that a string variable name can be anything, and you can have as many string variables as you want, instead of being limited to 6. Another interesting difference with strings in Lua is that you do not have to convert them to a number to use them as numeral values. So "3"+3 will return 6. "Hello Moon", "TakeFlight", and "145" are all valid string values.

Table



Lua's most interesting data type is the table. They are extremely versatile, and are used in almost any substantial program. They can hold any data type, or combination of data types in an organized array.

train={cars=2,speed=50}

Tables can also be used as dictionaries. For instance, with this table train[1], train.cars, and train["cars"] all return the same value.

More advanced information about Lua data types

Graphics



The screen does not update automatically



Unlike in BASIC, all drawing commands are drawn to Video RAM (VRAM), instead of displaying immediately. To update the screen, you have to run zmg.fastCopy(). This will copy the VRAM to the screen.

Sprites



LuaZM can display sprites generated with SourceCoder. There are currently two sprite routines, zmg.copySprite() and zmg.copySpriteMask(). However, with the current version of LuaZM, zmg.copySpriteMask() is pretty buggy. Syntax for these functions can be found on PrizmWiki.


Getkey Routines



NOTE: All the getkey routines use the same keycodes.

zmg.keyMenuFast



This routine is pretty much exactly the same as Getkey in BASIC. It returns the key last pressed. It differs from BASIC in that [AC/on] will cause the program to stop, and <span class=MENU' /> will take you to the Main Menu.

zmg.keyMenu



This is a blocking routine, which means that program execution will pause until a key is pressed. Good for use in GUIs or menus, limited use in games.

zmg.keyDirect and zmg.keyDirectPoll



zmg.keyDirect will tell you if a key was pressed during the last polling period. A polling period is the time from one zmg.keyDirectPoll to the next. This function is very useful for programs that need to handle more than one keypress at a time.
[icode]zmg.keyDirect(key)[icode] will (ideally) return 0, 1, 2, or 3 according to what actually happened to the key during the last polling period, but in this version of LuaZM the return codes don't seem to work properly. However, you can still tell if a key has been pressed in the last polling period like this:

if zmg.keyDirect(key)>1 then
-- code
end

Misc



Getting user input



The current version of LuaZM does not have a user input routine, although there will be one in the next release. Until then, we have included a user input routine in Back2BASIC.


Drawing Y= graphs



This function is also available through Back2BASIC.

zmg.drawText bug



If you try to draw text off the screen with this version of LuaZM, the calculator will freeze. That may be confusing when debugging, so if your code is freezing the calculator, comment out all your zmg.drawText commands and see if that fixes it.

Conclusion



This article is not a one-stop resource to Lua, nor is it meant to be. It is meant to help former BASIC programmers understand the Lua language and how it relates or differs from BASIC. I hope it isn't too confusing, and I can't wait to see what you can do as a future programmer. Happy Coding!


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users