LuaParser
Lua config file parser
GreenConfig can load configuration from text files in two formats. One is a proprietary format described in ConfigFile, other is a script written in Lua language. This page is about this last format.
Note that you must have Lua installed in order to read this file format in GreenConfig. Lua is a scripting language that was chosen because it has an interesting syntax with the concept of tables, as in the example bellow:
- -- Lines starting with two '-' signs are comments
- -- Next lines define a table called my_ip
- my_ip = {
- my_param1 = 10, my_param2 = 20,
- other_param = "testing"
- }
- -- Tables can be nested
- cpu = { cache={type="2-way",size=524288} }
- -- Tables can be extended
- cpu.bus_size=32 –- equivalent to cpu["bus_size"] = 32
- -- An alias
- my_systemc_processor = cpu
- -- An array
- numbers = {132, 6, 45} -- equivalent to { [1] = 132, [2] = 6, [3] = 45}
- -- Note that Lua starts an array at index 1. Be carefull when using with C code (that starts with index 0)
- -- Another equivalent array
- numbers2 = {}
- numbers2[1] = 132
- numbers2[2] = 6
- numbers2[3] = 45
- -- Tables can have both array and struct part
- T = { 1, 2, 3, 4 ; v = 1, v2 = 2 }
All the above variables are pushed to the DB as strings. The GreenConfig Framework is smart enough to set the parameters values if they exist at this point or to save the values as defaults to set the parameters when they first appear in an IP.
The tables can represent an IP block with parameters inside, an Extended Array (that represent a group of parameters with different types), a simple array of parameters (with same type), or a mix of both as the last example in the script above.
Posted January 8th, 2008 by ChristianSchroeder