lua Namespace Reference

Utility functions related to lua configuration file parsing. More...

Detailed Description

Utility functions related to lua configuration file parsing.

The lua configuration file specify a set of modules to execute.

Todo:
describe how the configuration file is parsed and what it structure is

Classes

class  invalid_array_error
 
class  invalid_configuration_file
 < Thrown if the configuration file is not valid More...
 
struct  Lazy
 Lazy value in lua (delayed evaluation) More...
 
struct  LazyFunction
 Lazy function in lua (delayed function evaluation) More...
 
class  LazyTable
 A specialization of ParameterSet for lazy loading of lua tables. More...
 
struct  LazyTableField
 Lazy table field in lua (delayed table access) More...
 
class  unsupported_type_error
 

Enumerations

enum  Type {
  NOT_SUPPORTED, BOOLEAN, STRING, INTEGER,
  REAL, INPUT_TAG, PARAMETER_SET
}
 List of all supported lua types. More...
 

Functions

void path_register (lua_State *L, void *ptr)
 Register Path into lua runtime.
 
int path_new (lua_State *L)
 Create a new instance of Path.
 
int path_free (lua_State *L)
 Free an instance of Path.
 
ExecutionPathpath_get (lua_State *L, int index)
 Retrieve an instance of Path from the lua stack.
 
Type type (lua_State *L, int index)
 Extract the type of a lua value. More...
 
size_t get_index (lua_State *L, int index)
 Convert a negative lua stack index to an absolute index. More...
 
int lua_is_array (lua_State *L, int index)
 Check if a lua table is an array. More...
 
std::pair< momemta::any, bool > to_any (lua_State *L, int index)
 Convert a lua type to momemta::any. More...
 
void push_any (lua_State *L, const momemta::any &value)
 Convert a momemta::any to a lua type, and push it to the top of the stack. More...
 
template<typename T >
special_any_cast (const momemta::any &value)
 
template<typename T >
momemta::any to_vectorT (lua_State *L, int index)
 Convert a lua array to a typed vector, encapsulated into a momemta::any. More...
 
momemta::any to_vector (lua_State *L, int index, Type type)
 Convert a lua array to a typed vector, encapsulated into a momemta::any. More...
 
void setup_hooks (lua_State *L, void *ptr)
 Register all C function in the lua userspace. More...
 
int module_table_newindex (lua_State *L)
 Hook for the metatable __newindex of the module's table. More...
 
void register_modules (lua_State *L, void *ptr)
 Register modules in lua userspace. More...
 
int load_modules (lua_State *L)
 Hook for the load_modules lua function. The stack must have one element: More...
 
int parameter (lua_State *L)
 Hook for the parameter lua function. This function accepts one argument: More...
 
std::shared_ptr< lua_State > init_runtime (ILuaCallback *callback)
 Initialize the lua runtime. More...
 
int generate_cuba_inputtag (lua_State *L)
 Define Lua function to generate Cuba phase-space point input-tags. More...
 
void inject_parameters (lua_State *L, const ParameterSet &parameters)
 Inject parameters into the current lua state. More...
 
Type lua_array_unique_type (lua_State *L, int index)
 Check if a lua table contains only value from the same type. More...
 
template<>
double special_any_cast (const momemta::any &value)
 Specialization for double type, with implicit conversion from integer.
 
int set_final_module (lua_State *L)
 
int add_integration_dimension (lua_State *L)
 
int declare_input (lua_State *L)
 The configuration file declared a new input. More...
 

Enumeration Type Documentation

◆ Type

enum lua::Type

List of all supported lua types.

Enumerator
NOT_SUPPORTED 

Type not supported

BOOLEAN 

Map to bool

STRING 

Map to std::string

INTEGER 

Map to int64_t

REAL 

Map to double

INPUT_TAG 

Map to InputTag

PARAMETER_SET 

Map to ParameterSet

Definition at line 39 of file utils.h.

Function Documentation

◆ declare_input()

int lua::declare_input ( lua_State *  L)

The configuration file declared a new input.

One argument is expected on the stack:

  • name (string): the name of the input
Parameters
LThe lua state

Definition at line 508 of file utils.cc.

Referenced by setup_hooks().

◆ generate_cuba_inputtag()

int lua::generate_cuba_inputtag ( lua_State *  L)

Define Lua function to generate Cuba phase-space point input-tags.

Parameters
LThe current lua state

The Lua function returns an input tag of type cuba::ps_points/i where i gets incremented each time the function is called (starting from 0). This way, the user is sure to always define the correct input tag fothe phase-space points.

Returns
always 1

Referenced by to_vectorT().

◆ get_index()

size_t lua::get_index ( lua_State *  L,
int  index 
)

Convert a negative lua stack index to an absolute index.

Parameters
LThe current lua state
indexThe index to convert
Returns
index if it's positive, otherwise the absolute index obtained by lua_gettop(L) + index + 1

Definition at line 116 of file utils.cc.

Referenced by lua::LazyFunction::LazyFunction(), lua_array_unique_type(), lua_is_array(), ParameterSetParser::parse(), to_any(), and to_vectorT().

◆ init_runtime()

std::shared_ptr< lua_State > lua::init_runtime ( ILuaCallback callback)

Initialize the lua runtime.

Parameters
callbackA pointer to an instance of ILuaCallback. This callback is used for communication between lua and C++
Returns
A pointer to the global lua state. Once out-of-scope, the pointer will be released using the lua_close function.

Definition at line 554 of file utils.cc.

Referenced by to_vectorT().

◆ inject_parameters()

void lua::inject_parameters ( lua_State *  L,
const ParameterSet parameters 
)

Inject parameters into the current lua state.

For each parameter inside parameters, a global variable is created inside the lua state.

Parameters
LThe lua state
parametersParameters to inject into the lua state

Definition at line 572 of file utils.cc.

Referenced by to_vectorT().

◆ load_modules()

int lua::load_modules ( lua_State *  L)

Hook for the load_modules lua function. The stack must have one element:

  1. (string) The filename of the library to load

The library will be loaded, and for each new module, a new global variable will be declared, accessible from the lua configuration

Returns
always 0

Definition at line 422 of file utils.cc.

Referenced by setup_hooks(), and to_vectorT().

◆ lua_array_unique_type()

Type lua::lua_array_unique_type ( lua_State *  L,
int  index 
)

Check if a lua table contains only value from the same type.

Returns
-1 if not, or the type of the data in the table

Definition at line 158 of file utils.cc.

Referenced by to_any().

◆ lua_is_array()

int lua::lua_is_array ( lua_State *  L,
int  index 
)

Check if a lua table is an array.

Returns
-1 if it's not an array, or the size of the array

Check if a lua table is an array

Return -1 if it's not an array, or the size of the array

Definition at line 125 of file utils.cc.

Referenced by to_any(), and type().

◆ module_table_newindex()

int lua::module_table_newindex ( lua_State *  L)

Hook for the metatable __newindex of the module's table.

This function is called as soon as a new entry is added to a module's table, which means that the user defines a new module from the configuration.

The stack contains 3 elements:

  1. the module type table
  2. the module name (the key in the table)
  3. the module definition (the value associated with the key)
Returns
always 0

Definition at line 332 of file utils.cc.

Referenced by register_modules(), and to_vectorT().

◆ parameter()

int lua::parameter ( lua_State *  L)

Hook for the parameter lua function. This function accepts one argument:

  1. (string) The name of the parameter

Internaly, this function creates an anonymous lua function, which returns the value of the parameter from the configuration global table.

Returns
always 1

Definition at line 438 of file utils.cc.

Referenced by inject_parameters(), setup_hooks(), and to_vectorT().

◆ push_any()

void lua::push_any ( lua_State *  L,
const momemta::any value 
)

Convert a momemta::any to a lua type, and push it to the top of the stack.

This method does the opposite of lua::to_any: convert a momemta::any to the corresponding lua type, and pushing it to the top of the stack.

Parameters
Lthe current lua state
valueThe value to convert
Warning
Vectors are currently not supported

Definition at line 271 of file utils.cc.

Referenced by inject_parameters(), parameter(), and lua::LazyTableField::set().

◆ register_modules()

void lua::register_modules ( lua_State *  L,
void *  ptr 
)

Register modules in lua userspace.

For each type of module existing, a global table named as the module's type is declared.

Each entry in this table declare a new module of a given type. The key of the entry is the module's name, and the name of the table is the module's type.

The value is itself a table, defining the configuration of the module

Parameters
LThe current lua state
ptrA pointer to an instance of ConfigurationReader
See also
module_table_newindex()

Definition at line 376 of file utils.cc.

Referenced by init_runtime(), load_modules(), and to_vectorT().

◆ setup_hooks()

void lua::setup_hooks ( lua_State *  L,
void *  ptr 
)

Register all C function in the lua userspace.

Available functions:

Definition at line 524 of file utils.cc.

Referenced by init_runtime(), and to_vectorT().

◆ to_any()

std::pair< momemta::any, bool > lua::to_any ( lua_State *  L,
int  index 
)

Convert a lua type to momemta::any.

Returns
A std::pair containing :
  • a new momemta::any encapsulating the lua type and a boolean. If the lua type is not supported, an exception is thrown.
  • a boolean. If true, it means the encapsulated type is a Lazy value, which must be evaluated later on.

Definition at line 191 of file utils.cc.

Referenced by lua::LazyTableField::operator()(), lua::LazyFunction::operator()(), ParameterSetParser::parse(), and to_vectorT().

◆ to_vector()

momemta::any lua::to_vector ( lua_State *  L,
int  index,
Type  type 
)

Convert a lua array to a typed vector, encapsulated into a momemta::any.

Returns
A new momemta::any encapsulating the lua array. If the lua type is not supported, an exception is thrown

Definition at line 297 of file utils.cc.

Referenced by to_any(), and to_vectorT().

◆ to_vectorT()

template<typename T >
momemta::any lua::to_vectorT ( lua_State *  L,
int  index 
)

Convert a lua array to a typed vector, encapsulated into a momemta::any.

Returns
A new momemta::any encapsulating the lua array. If the lua type is not supported, an exception is thrown

Definition at line 150 of file utils.h.

◆ type()

Type lua::type ( lua_State *  L,
int  index 
)

Extract the type of a lua value.

Parameters
LThe current lua state
indexThe index of the value
Returns
The type of the lua value (can be NOT_SUPPORTED if the framework can't handle such value)

Definition at line 81 of file utils.cc.

Referenced by lua::LazyTableField::ensure_created(), lua_array_unique_type(), register_modules(), to_any(), and to_vectorT().