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:

  1. -- Lines starting with two '-' signs are comments
  2.  
  3. -- Next lines define a table called my_ip
  4. my_ip = {
  5.    my_param1 = 10, my_param2 = 20,
  6.    other_param = "testing"
  7. }
  8.  
  9. -- Tables can be nested
  10. cpu = { cache={type="2-way",size=524288} }
  11.  
  12. -- Tables can be extended
  13. cpu.bus_size=32          –- equivalent to cpu["bus_size"] = 32
  14.  
  15. -- An alias
  16. my_systemc_processor = cpu
  17.  
  18. -- An array
  19. numbers = {132, 6, 45}   -- equivalent to { [1] = 132, [2] = 6, [3] = 45}
  20.  
  21. -- Note that Lua starts an array at index 1. Be carefull when using with C code (that starts with index 0)
  22.  
  23. -- Another equivalent array
  24. numbers2 = {}
  25. numbers2[1] = 132
  26. numbers2[2] =   6
  27. numbers2[3] =  45
  28.  
  29. -- Tables can have both array and struct part
  30. 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.