# Aros/Developer/Docs/LUA

* Navbar for the Aros wikibook
* Aros User
* Aros User Docs
* Aros User FAQs
* Aros User Applications
* Aros User DOS Shell
* Aros/User/AmigaLegacy
* Aros Dev Docs
* Aros Developer Docs
* Porting Software from AmigaOS/SDL
* For Zune Beginners
* Zune .MUI Classes
* For SDL Beginners
* Aros Developer BuildSystem
* Specific platforms
* Aros x86 Complete System HCL
* Aros x86 Audio/Video Support
* Aros x86 Network Support
* Aros Intel AMD x86 Installing
* Aros Storage Support IDE SATA etc
* Aros Poseidon USB Support
* x86-64 Support
* Motorola 68k Amiga Support
* Linux and FreeBSD Support
* Windows Mingw and MacOSX Support
* Android Support
* Arm Raspberry Pi Support
* PPC Power Architecture
* misc
* Aros Public License

## Lua

Lua is already install for use in Icaros Desktop but other distributions may not have it so
The Lua directory can be place anywhere but some assigns need to be added
e.g. assign lua: sys:dev/Lua
Write you lua code and save as filename.lua
see next section for AROS specific features and amilua
Lua consists part
* Functional
* Object-orientated
There are other aspects of Lua programming than functions, but functions are easy to understand, an example...
As you see, it's easy to declare a function, you might use this function elsewhere by calling:
Within a function, you can declare local values. Local values have a scope which is limited to the function where they are declared. Any function may return a value, here's an example:
As you may have guessed, this function performs an addition, you can call:
and the value of "c" will be 3.
Lua has some common controls like "if...then" or "while...do". Here is a short example:
And another one:
To compare numeric values, you can use the operators:
Starters Tutorial
Another Tutorial
Learn how to use userdata and what custom classes are (use calling methods and do not use reference indexes).

## AmiLua

AmiLua extends Lua with some functions for handling intuition windows, gadgets, menus and graphics functions.
There are 3 Lua tables:
* Siamiga: Windows, creating of gadgets and menues, message handling, drawing functions
* Sigadget: setting and getting of gadget parameters
* Sipicture: loading, grabbing and blitting of bitmaps.
.alua is the specific "dialect" of lua that includes zulu and siamiga. If you are going to write some zulu or siamiga stuff you need to use the .alua extension and to point to amilua.

### Sipicture

A complex drawing utility, should be written it in C, as you will soon reach the limits of what LUA offers.

### Zulu

Zulu allows you to create MUI applications from Lua scripts.
You'll find it in the current nightly build in the directory "Extras/Development/Lua". You need an assign named "lua" to this directory. The binary Amilua is build with the MUI binding. Some examples are in the subdir "test-mui.Documentation is in "doc/zulu.txt". If you haven't programmed MUI before you should download mui38dev from Aminet and study the documentation.
Groups are MUI/Zune classes, too. Of course, you have to look in the documentation what attributes are possible. The Group class is a subclass of the Area class, this makes it possible to use its attributes like MUIA_Disabled.

### ASL requesters

To get multiple files from an ASL requester through Zulu function mui.filerequest, you have to call the function within curly brackets in order to get multiple results
Below there's a snipped of my Lua code (based on Mazze's example)
Lua supports currently only static libraries. zulu and siamiga a static libraries. So you have to create a static library and then re-link AmiLua with that library. IIRC there is needed a header file for the connection between Lua and the library.

## Libraries

LUA.Filesystem (not implemented yet)
LUA.Socket
lua.sqlite3
LuaSQL frontend docs.
Lua use of first-class functions allow the employment of many powerful techniques from functional programming;
and full lexical scoping allows fine-grained information hiding to enforce the principle of least privilege.
Lua allows programmers to implement namespaces, classes, and other related features using its single table implementation;
Lua does not contain explicit support for inheritance, but allows it to be implemented relatively easily with metatables.

## Examples

Sample Code
Shell variables are files which are stored in ENV:.
So you can either use output redirection:
Or you can use the file handling functions of Lua to write to ENV:myvariable.
This example lets you enable/disable the group with the two text fields.
How to declare variable located in external file? I need config text file with some variables. How to declare them in main file?
loadfile is what you need.

## Issues

Floattext.mui class & Lua Is it possible use this class in Zulu? How to use it to read and show text in window? Could not get it working nicely for WHD_Menu. Ended up using a list object. You can download WHD_Menu from Aros Archive to have a look on how it was achieved. This object is used to display the readme file (variable is CurrentReadMe).
Is it possible to use in this class a function to search requested word in readme file to get line number as result? Each line is an entry in the list. Just parse all entries and search for the string in the field. You'll get directly the line number this way.
This thread multiple file selection isn't working out of the box, you have to create your own class and this is not possible with Lua/Zulu, you have to do it in C.
If you download to other location having space in name still will be problem. How to fix it? Ensure that the path is enclosed in double quotes. From the AROS Exec Download Tool:
Here I have the double quotes only for readme_target because the path to MultiView doesn't have spaces.
changed line to:
Examples here and here.
How to internationalize Lua script? There is no interface to locale.library in Lua. Just create tables with strings.
So I need to add "choose language" gadget or is there any function to check locale used in system? Could I use external files deutsch.lang, polski.lang etc. or these strings must be in main file? Which way is easier and which is better for these small Lua scripts?
There is an environment variable named "language" and Lua has a function to query environment variables:
In MUI/ZUNE to read a string value from a ListObject the following code applies.
Bear in mind that MUIM_List_GetEntry returns a pointer to a generic entry. A string pointer is only a special case for single column lists.
How does ZULU handle this in Lua, as according to zulu.txt none of the accessor methods (getstr, dostr, etc) appear to match this patten of passing a string pointer as an argument? I'm using local current = listobject:getint(mui.MUIA_List_Active) to query the index of the selected entry. So you could assign a StrArray to mui.MUIA_List_SourceArray then use the mui.MUIA_List_Active result as the index for that array.

## References

HTML-page based reference
Download programming guide
Short Reference - PDF download
Cut down single page reference
Programmmers Wiki
Tutorial Directory
Official FAQ
Unofficial FAQ
http://www.andreas-rozek.de/Lua/index_en_old.html
Lua Filesystem
http://luaforge.net/
http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/

## LOVE nLOVE

http://love2d.org/
Wiki, IDE,
Getting Started
* love.load
* love.update
* love.draw
* love.mousepressed
* love.mousereleased
* love.keypressed
* love.keyreleased
* love.focus
* love.quit
Debugging, Debug,
require("debug")
"scripts.library.enemy" instead of "scripts/library/enemy"
make a silly error that you didn't notice, like calling newImage, newImageData, newFont, etc. in love.update or love.draw?