GemaLuaCoreLib
The GeMA Lua Core library
Functions
GmLuaUtils Namespace Reference

Groups utilitary routines for working with Lua. More...

Functions

void fillVectorFromLua (lua_State *L, int stackPos, QString fname, GmVector &v)
 Resizes and fills the vector v to receive the data stored in a lua table.
 
void checkAndLoadIntOption (LuaTable &optionsTable, const char *fieldName, int *option)
 An auxiliary function used to check the existance and validity of an integer option. If the field doesn't exists, does nothing (keep default value). Otherwise, if the field is an integer, fills option with its value. Otherwise (invalid value), raises an error.
 
void checkAndLoadUnsignedOption (LuaTable &optionsTable, const char *fieldName, unsigned *option)
 An auxiliary function used to check the existance and validity of a unsigned integer option. If the field doesn't exists, does nothing (keep default value). Otherwise, if the field is an unsigned, fills option with its value. Otherwise (invalid value), raises an error.
 
void checkAndLoadDoubleOption (LuaTable &optionsTable, const char *fieldName, double *option)
 An auxiliary function used to check the existance and validity of a double option. If the field doesn't exists, does nothing (keep default value). Otherwise, if the field is a number, fills option with its value. Otherwise (invalid value), raises an error.
 
void checkAndLoadTaskOptions (LuaTable &optionsTable, int *nworkers, int *ntasks, GmTaskManager::NodePartitionStrategy *nodeStrategy, GmTaskManager::CellPartitionStrategy *cellStrategy)
 An auxiliary function used to load task manager options from optionsTable, filling nworkers, ntasks, nodeStrategy and cellStrategy. If any of the parameters is NULL, the option will be ignored. More...
 
int stringOptionIndex (QString value, const char **optionNames, lua_State *L, const char *fieldName)
 Looks for value in optionNames. If found returns the index. If not found raises a lua error for field fieldName.
 
template<class T , class M >
void checkAndLoadStringOption (LuaTable &optionsTable, const char *fieldName, const char **optionNames, T *optionsObj, M method)
 An auxiliary function to check the existance and validity of a string option. If the field given by "fieldName" doesn't exists in optionsTable, does nothing (keep default value). Otherwise, if the field is a known string (exists in the NULL terminated array pointed by optionNames), fills option with its value by calling the given method from optionsObj. The method must be a function that receives as parameter the index of the option on optionNames and sets it on the object (possibly converting the index into an enumerated value). If the value is not known, raises an error (including information about the avialable options).
 
template<class T , class P >
T * parseMesh (lua_State *L, int index, const GmModelData *mdata, QString fname)
 Auxiliary routine to help processes that can accept from the Lua stack either a mesh object or a mesh name as a parameter to grab the corresponding mesh object. More...
 
template<class T , class P >
void parseMeshOrGroup (lua_State *L, int index, const GmModelData *mdata, QString fname, T **mesh, GmCellGroupSet **group)
 Auxiliary routine to help processes that can accept from the Lua stack either a mesh object, a mesh name or a cell group objecct as a parameter to grab the corresponding mesh and group objects. More...
 
template<const char * typeName>
void pushGroupDumpItemProxy (lua_State *L, GmGroupDumpItem *ptr)
 Pushes a pointer inheriting from GmGroupDumpItem as a Lua proxy. The pointer will be deleted when the returned Lua proxy is GCed. More...
 
template<class T >
T * getGroupDumpItemPtr (lua_State *L, int pos, QString tmsg, QString fmsg)
 Returns the parameter at Lua stack position 'pos' as a T*. More...
 

Detailed Description

Groups utilitary routines for working with Lua.

Function Documentation

◆ checkAndLoadTaskOptions()

GML_API_EXPORT void GmLuaUtils::checkAndLoadTaskOptions ( LuaTable optionsTable,
int *  nworkers,
int *  ntasks,
GmTaskManager::NodePartitionStrategy nodeStrategy,
GmTaskManager::CellPartitionStrategy cellStrategy 
)

An auxiliary function used to load task manager options from optionsTable, filling nworkers, ntasks, nodeStrategy and cellStrategy. If any of the parameters is NULL, the option will be ignored.

Checked fields are "numThreads", "numTasks", "nodePartitionStrategy" and "cellPartitionStrategy". If the field doesn't exists, does nothing (keeps original value). Otherwise, if the field is a valid value, fills the corresponding parameter. On invalid values, raises a Lua error.

The value to be channged

◆ getGroupDumpItemPtr()

template<class T >
T* GmLuaUtils::getGroupDumpItemPtr ( lua_State *  L,
int  pos,
QString  tmsg,
QString  fmsg 
)

Returns the parameter at Lua stack position 'pos' as a T*.

If the parameter is NOT a full user data, storing a value of type LuaSimplePtrProxy<GmGroupDumpItem>, whose pointer can be converted to T*, raises a Lua error including tmsg and fmsg in the error following message: "Invalid tmsg parameter in call to fmsg()"

◆ parseMesh()

template<class T , class P >
T* GmLuaUtils::parseMesh ( lua_State *  L,
int  index,
const GmModelData mdata,
QString  fname 
)

Auxiliary routine to help processes that can accept from the Lua stack either a mesh object or a mesh name as a parameter to grab the corresponding mesh object.

Returns the mesh found as the parameter in the given Lua stack index. Template parameters are the requested mesh type (GmCellMesh, for example) and its Lua proxy type (GmLuaCellMesh).

Accepts as parameter a mesh name or an mesh proxy object. On error (the given index does not specifies a valid Mesh of type T), this function will raise an error by calling luaL_error().

◆ parseMeshOrGroup()

template<class T , class P >
void GmLuaUtils::parseMeshOrGroup ( lua_State *  L,
int  index,
const GmModelData mdata,
QString  fname,
T **  mesh,
GmCellGroupSet **  group 
)

Auxiliary routine to help processes that can accept from the Lua stack either a mesh object, a mesh name or a cell group objecct as a parameter to grab the corresponding mesh and group objects.

Fills mesh and group parameters. If the object in the given Lua stack index is a mesh name or mesh object, fills the mesh parameter and sets the group to NULL. Otherwise, fills both mesh (with the group mesh) and group.

Template parameters are the requested mesh type (GmCellMesh, for example) and its Lua proxy type (GmLuaCellMesh).

On error (the given index does not specifies a valid Mesh of type T or a cell group), this function will raise an error by calling luaL_error().

◆ pushGroupDumpItemProxy()

template<const char * typeName>
void GmLuaUtils::pushGroupDumpItemProxy ( lua_State *  L,
GmGroupDumpItem ptr 
)

Pushes a pointer inheriting from GmGroupDumpItem as a Lua proxy. The pointer will be deleted when the returned Lua proxy is GCed.

Storing in the proxy a GmGroupDumpItem instead of a derived class is necessary for it to be correctly handled by StateDump Lua objects in GmLuaStateDump::addStateItem()

Since non-type template parameters must have external linkage, this template function must be called with a string stored in an external variable. See https://stackoverflow.com/questions/5547852/string-literals-not-allowed-as-non-type-template-parameters.

Example: extern const char dummy[]; const char dummy[] = "DumpItem"; ... pushGroupDumpItemProxy<dummy>(L, ptr)