Using Lua for Celestia Data Definition
Posted: 01.06.2006, 18:58
On another thread, I mentioned the possibility of using Lua for data definition in Celestia. This suggestion was prompted by Paolo's proposal for a revision of the existing data definition file format:
The syntax changes are fairly minor. Attributes and their values are separated by an equals sign, attribute value pairs are separated by semicolons, square brackets are replaced by curly braces (and the items within separated by commas), and double hyphens are used for comments. (I also used strings for the GUIDs, but that is optional.)
This is a valid chunk of Lua code. Each construct (Asteroid, Galaxy, Location) is a Lua function call, consisting of the function name followed by a table constructor. The table constructor is just a list of key value pairs enclosed in braces.
This approach makes it easy to add new constructs, simply by adding new Lua functions. Thus, another of Paolo's examples:
With the Lua approach, this feature could be added simply by implementing a Lua function named "File". And this would not require a change to the compiled code.
Because of the power of Lua programming, the possibilities are endless.
- Hank
Using Lua, Paolo's example might look like this:Paolo wrote:Going further the new object model should be implemented through a new data format.
I would like to discard the XML. It is powerful but too verbose. I would like that the current data format should change slightly the syntax.
So instead than:Code: Select all
"Ceres" "Sol"
{
Class "asteroid"
Texture "asteroid.jpg"
Radius 487.5
Oblateness 0.068
...
}
...
Galaxy "NGC 1:UGC 57:MCG 4-1-25:ZWG 477.54"
{
Type "Sb"
RA 0.1208
Dec 27.7089
Distance 2.073e+08 # method: T-F
...
}
...
Location "Aix" "Sol/Gaspra"
{
LongLat [ -156 47 0 ]
Size 0.6
Type "AA"
}
...
That requirese different file formats and different file extensions I would like to see something like:Code: Select all
Asteroid
{
GUID [ 1236 6585 546a c00a ]
ParentGUID [ 1256 8474 1565 aa45 ] #"Sol"
Name "Ceres"
Texture "asteroid.jpg"
Radius 487.5
Oblateness 0.068
...
}
...
Galaxy
{
GUID [ 1325 135c 1325 dd23 ]
ParentGUID [0000 0000 0000 0000] # "Universe"
Name "NGC 1:UGC 57:MCG 4-1-25:ZWG 477.54"
Type "Sb"
RA 0.1208
Dec 27.7089
Distance 2.073e+08
...
}
...
Location
{
GUID [ 1356 1258 4785 aae2]
ParentGUID [ 1256 1588 4589 1556 ] # "Sol/Gaspra"
Name "Aix"
LongLat [ -156 47 0 ]
Size 0.6
Type "AA"
}
Code: Select all
Asteroid
{
GUID = "1236 6585 546a c00a" ;
ParentGUID = "1256 8474 1565 aa45" ; -- "Sol"
Name = "Ceres" ;
Texture = "asteroid.jpg" ;
Radius = 487.5 ;
Oblateness = 0.068 ;
...
}
...
Galaxy
{
GUID = "1325 135c 1325 dd23" ;
ParentGUID = "0000 0000 0000 0000" ; -- "Universe"
Name = "NGC 1:UGC 57:MCG 4-1-25:ZWG 477.54" ;
Type = "Sb" ;
RA = 0.1208 ;
Dec = 27.7089 ;
Distance = 2.073e+08 ;
...
}
...
Location
{
GUID = "1356 1258 4785 aae2" ;
ParentGUID = "1256 1588 4589 1556" ; -- "Sol/Gaspra"
Name = "Aix" ;
LongLat = { -156, 47, 0 } ;
Size = 0.6 ;
Type = "AA" ;
}
The syntax changes are fairly minor. Attributes and their values are separated by an equals sign, attribute value pairs are separated by semicolons, square brackets are replaced by curly braces (and the items within separated by commas), and double hyphens are used for comments. (I also used strings for the GUIDs, but that is optional.)
This is a valid chunk of Lua code. Each construct (Asteroid, Galaxy, Location) is a Lua function call, consisting of the function name followed by a table constructor. The table constructor is just a list of key value pairs enclosed in braces.
This approach makes it easy to add new constructs, simply by adding new Lua functions. Thus, another of Paolo's examples:
Paolo wrote:Try to imagine what you should do using a unified data format with something like this:Code: Select all
File
{
...
}
It is the end of the proliferation of different folders and different Celestia installations for the management of the add-ons!
With the Lua approach, this feature could be added simply by implementing a Lua function named "File". And this would not require a change to the compiled code.
Because of the power of Lua programming, the possibilities are endless.
- Hank