Features specific to a version of celestia are marked by these colors:
1.3.1 Celestia 1.3.1
1.3.2 Celestia 1.3.2
1.4.0 Celestia 1.4.0
Celestia works roughly(!) by repeating this:
If a CELX-script has been started, it is executed just before rendering begins. Then Celestia gives control to the Lua-interpreter, which continues to execute the script where he stopped the last time. When you call a CELX-method in a script, e.g. celestia:print(), the Lua-interpreter calls in fact a little C++ function which converts the arguments from Lua-types to C++-types, calls the right Celestia-methods to perform the action, and if necessary converts the C++ return value back to a Lua-value. Note that the Lua-interpreter called this C++ function, so when it returns the script continues, there is never a chance to return control back to the Celestia loop. To do this, the script has to call the "wait()" command, which makes the Lua-interpreter return control.
Forgetting to call wait() in Celestia 1.3.1 meant that Celestia never gained control again, and thus couldn't even handle the command to stop the script, or quit - it was completely blocked. 1.3.2 Celestia v1.3.2 periodically checks if the scripts has exceeded the maximum allowed time to execute (5s), and if it has it terminates the script.
It should have become obvious that most actions don't really change anything immediately, instead they change a setting which is used later on during rendering, which from the point of view of the script happens while calling wait(). So if you change the position of the observer ten times without calling wait() in between, this will have no effect - only the last position will actually be used in rendering.
For a complete description of the syntax of Lua, please read http://www.lua.org/manual/5.0/
Some examples and quick notes:
You don't need anything like ";" to complete a line, simply write line after line. Blocks are enclosed by "begin ... end", short comments start with a "--", long (multiline) comments use "--[[ comment ]]".
celestia:requestsystemaccess()
wait(0)You can manipulate vectors, positions and rotations using normal operators like "+" or "-". Following operations are defined (s is a number):
The callback for keyboard input must have the name "celestia_keyboard_callback". After a script activates the handling keyboard-input by calling celestia:requestkeyboard(true), any keypress will result in a call to a method with this name.
The method should accept one parameter, a string, which holds the char of the key which has been pressed. Accented characters like ä or é will be passed as UTF-8 sequences, i.e. as a multibyte sequence - if you only want to handle ASCII you can safely ignore this. Keys like CTRL-A are passed as strings containing a char with ASCII-codes < 32, as are Enter (13) or Backspace (8). Some special keys like cursor-keys or ESC won't activate the callback.
The callback can return either true or false, indicating that it either has handled the keypress or that celestia should continue normal processing for this key. Not returning any value is the same as returning true. If an error occurs while processing the callback, the error message will be written to the console (visible with "~") and an implicit false is returned, i.e. celestia will continue processing for this key.
Whenever a Lua script terminates (because it ended, the user terminated it or an error occured), Celestia will try to execute a function with the name "celestia_cleanup_callback". This function can be used to perform any cleanup actions, notably restoring settings to the values in use before the script started. Errors will only be reported in the console.