Celx menu Ctrl
Description
This script does the same as the "celx menu" script; it provides a simple 1-level menu without a submmenu. The one difference is that this script dóes support [Ctrl]+[Key] combinations.
Initially I contemplated going the object oriented way (sort of); translating the eventdata into a correct key event packet before processing it further. But then I decided against that because a.o.:
- the script would become more complicated
- - it would take more code to decide what key(-combination) had been received
- it would consume unnecessary cpu cycles
- - the extra translation and decision code would have to be executed for every key event received from Celestia
In an interpreted environment like celx/lua it is always a good idea to keep the size of the code as small as possible; at least that part of the code that has to be executed in response to something like a key event. So I kept the same set-up and decided to only replace the keys string by a keys array and then got into trouble with some lua peculiarities described here. The basic problem here was that the [Ctrl]+{Key] combinations, as passed on by celestia, did not count as valid lua identifiers and therefore could not be used in the syntax structure I had used for the script. I needed an alternative syntax to specify the menu table/structure but that again got me into trouble with lua. This time with the way it resolves function adresses. So I ended up changing more than I had anticipated and specifically the fact that I had to break up the menu structure table into two separate parts touches on a sore spot.
For details about the celx key event see: Key event
Downloads
History
Version 1, 6 Feb 2011
Initial version