Hints and Tipps for the programming language Lua
Lua is a small and compact Script langauge. Lua is attached to C-Hosts-Programms and is often used for computer games.
There are plans to include Lua to pdfLaTeX.
Using Lua as Stand-Alone-Interpreter
You can use Lua also as a stand alone scripting language.
lua [options] [script [args]]
Options are:
- -
- Executes stdin al a script
- -e stat
- Execute the string stat
- -l file
- Loads the file file
- -i
- interactive mode after executing your script
- -v
- Version informationen
- --
- Stop the following options
Scite
To use Lua in Scite, you must adapt the lua.properties. By default there is the following Definition:
command.go.*.lua=Lua-5.0.exe "$(FileNameExt)"
There you can replace Lua-5.0.exe with the interpreter (and path) you installed on your PC.
DOS
Create a file lua.bat and add the following code:
@echo off rem Adapt for your path Lua.exe %1 %2 %3
Coding Examples
With my first steps, I made some testing scripts. You will find them in the section First steps with Lua.
The exampls are not made for beginners, you should know the basic principles of programming. The examples show, how it is made with Lua, it shows some principles of coding.
You can see small scripts and the resulting output. If you prefer to print the examples, please use the PDF-Document Lua - First Steps in Programming (Actually only German, translation in process). You find the coding examples in the file lua_sources.zip . 1
Some generell remarks on programming in Lua:
- comments are made with leading --
- comments on multiple lines can be made with -- [[ The end of the comment is made with ]]
Conventionen of Names in Lua
- normal variables start with small letters
- functions start with capital letters
- parameter of functions start with an underscore.
Lua and TeX
LuaTeX
There is a pdfTeX -Version, with Lua as an embedded Scriptlanguage:
Target is to have TeX-Input like
\lua{a = 1.5 ; b = 1.8 ; c = a*b ; tex.print(c) ;}
\startlua
a = 1
b = 2
c = a*b
tex.print(c)
\stoplua
With the result
2.7 2
Listings.sty
The TeX-Package listings.sty enables TeX to typeset programm code.
Lua is not supported up to now (7. März 2007), but it is in process. In lua_texsources.zip you find a temporary defininition for listings.sty.
Lua in the net Internet
- Weitere Links zum Thema Lua (english) im Open Directory Project
- Weitere Links zum Thema Lua (German) im Open Directory Project
- Lua bei Wikipedia
- Lua-Forum
1In
lua_texsources.zip
you get the sourcecode of the TeX-files to create the PDF.