24#ifndef _GEMALUA_UTILS_H_
25#define _GEMALUA_UTILS_H_
70 template<
class T,
class M>
100 if(lua_type(L, index) == LUA_TSTRING)
102 QString meshName = lua_tostring(L, index);
106 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' not found in call to %2").arg(meshName, fname)));
108 T* tmesh =
dynamic_cast<T*
>(mesh);
110 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' has an invalid type in call to %2").arg(meshName, fname)));
116 P* proxy = LuaProxy::toObjectOfClass<P>(L, index);
118 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Error: Parameter %1 in call to %2 should be a valid mesh object (or a mesh name). Check mesh type.")
119 .arg(index).arg(fname)));
121 return dynamic_cast<T*
>(proxy->mesh());
143 assert(mesh && group);
148 if(lua_type(L, index) == LUA_TSTRING)
150 QString meshName = lua_tostring(L, index);
154 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' not found in call to %2").arg(meshName, fname)));
156 T* tmesh =
dynamic_cast<T*
>(m);
158 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' has an invalid type in call to %2").arg(meshName, fname)));
165 P* proxy = LuaProxy::toObjectOfClass<P>(L, index);
168 *mesh =
dynamic_cast<T*
>(proxy->mesh());
173 GmLuaCellGroupSet* gproxy = LuaProxy::toObjectOfClass<GmLuaCellGroupSet>(L, index);
175 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Error: Parameter %1 in call to %2 should be a valid mesh object, a mesh name or a cell group set object. Check parameter type.")
176 .arg(index).arg(fname)));
179 *mesh =
dynamic_cast<T*
>((*group)->mesh());
181 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Cell group mesh has an invalid type in call to %1").arg(fname)));
216 T* ptr = proxy ?
dynamic_cast<T*
>(proxy->
get()) : NULL;
219 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Invalid %1 parameter in call to %2()").arg(tmsg, fmsg)));
A proxy class to export GmCellGroupSet methods to the Lua environment.
Definition gmLuaCellGroupSet.h:34
const GmCellGroupSet * cellGroupSet() const
Returns the wrapped cell.
Definition gmLuaCellGroupSet.h:51
const QMap< QString, GmMesh * > & meshes() const
QVariant getField(const char *name, LuaEnv::StackOption opt=LuaEnv::STACK_AUTO)
Declaration of the GmLuaCellGroupCell class.
Declaration of the function used to prepare an environment with the core Lua functions.
Groups utilitary routines for working with Lua.
Definition gmLuaUtils.cpp:34
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.
Definition gmLuaUtils.cpp:37
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...
Definition gmLuaUtils.h:94
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,...
Definition gmLuaUtils.cpp:131
T * getGroupDumpItemPtr(lua_State *L, int pos, QString tmsg, QString fmsg)
Returns the parameter at Lua stack position 'pos' as a T*.
Definition gmLuaUtils.h:213
void checkAndLoadUnsignedOption(LuaTable &optionsTable, const char *fieldName, unsigned *option)
An auxiliary function used to check the existance and validity of a unsigned integer option....
Definition gmLuaUtils.cpp:91
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 "...
Definition gmLuaUtils.h:71
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...
Definition gmLuaUtils.cpp:188
void pushGroupDumpItemProxy(lua_State *L, GmGroupDumpItem *ptr)
Pushes a pointer inheriting from GmGroupDumpItem as a Lua proxy. The pointer will be deleted when the...
Definition gmLuaUtils.h:200
void checkAndLoadDoubleOption(LuaTable &optionsTable, const char *fieldName, double *option)
An auxiliary function used to check the existance and validity of a double option....
Definition gmLuaUtils.cpp:109
void parseMeshOrGroup(lua_State *L, int index, const GmModelData *mdata, QString fname, T **mesh, const GmCellGroupSet **group)
Auxiliary routine to help processes that can accept from the Lua stack either a mesh object,...
Definition gmLuaUtils.h:138
void checkAndLoadIntOption(LuaTable &optionsTable, const char *fieldName, int *option)
An auxiliary function used to check the existance and validity of an integer option....
Definition gmLuaUtils.cpp:73
const T value(const Key &key, const T &defaultValue) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const
QString toString() const const