interactive_lua.lua

NAME
SYNOPSIS
DESCRIPTION

NAME

interactive_lua.lua − Using Lua interactively with AKFAvatar

SYNOPSIS

interactive_lua.lua

DESCRIPTION

Using Lua interactively with AKFAvatar.

This could for example be used as a calculator. When you start a line with an equal sign ("=") then the result(s) of the expression is shown. For example, when you enter "=10/4" it prints "2.5".

Note that it might show a different character for the decimal point, depending on your language settings. But when you want to enter a decimal fraction, you have to use the American notation with a point.

You can define your own variables. For example one Megabyte is 2^20 Bytes. So enter "MB=2^20". Now you can use it in your calculations. If you want to know what 5 Megabytes is in Bytes, enter "=5*MB", the result is "5242880". Please note that Lua is case sensitive. That means for example that "MB" and "mb" are two different variables.

Starting lines with the equal sign is a special feature of the interactive shell. It can not be used in scripts.

Your normal prompt is a ">". But when you enter an incomplete command, then you’ll get a different prompt that looks like this ">>". Then you can continue to complete your entry. If you end up on the secondary prompt by accident, then simply press <Enter>. This cancels the previous entry.

You can define your own functions. For example:

  > function circle_area(radius)
  >> return radius^2 * math.pi
  >> end
  > =3 * circle_area(5)
  235.61944901923

You can use any Lua command, including the AKFAvatar commands. For example you can set a name for the avatar. Try this:

  > avt.set_avatar_name("Hugo")

Or if you don’t want to have an avatar at all use

  > avt.avatar_image("none")

To get a female avatar use

  > avt.avatar_image_file(avt.search("female_user.xpm"))

You can do a lot more... Just experiment with it...