24 #ifndef _GEMALUA_UTILS_H_ 25 #define _GEMALUA_UTILS_H_ 69 template<
class T,
class M>
99 if(lua_type(L, index) == LUA_TSTRING)
101 QString meshName = lua_tostring(L, index);
105 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' not found in call to %2").arg(meshName, fname)));
107 T* tmesh = dynamic_cast<T*>(mesh);
109 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' has an invalid type in call to %2").arg(meshName, fname)));
115 P* proxy = LuaProxy::toObjectOfClass<P>(L, index);
117 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.")
118 .arg(index).arg(fname)));
120 return dynamic_cast<T*>(proxy->mesh());
142 assert(mesh && group);
147 if(lua_type(L, index) == LUA_TSTRING)
149 QString meshName = lua_tostring(L, index);
153 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' not found in call to %2").arg(meshName, fname)));
155 T* tmesh = dynamic_cast<T*>(m);
157 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Mesh '%1' has an invalid type in call to %2").arg(meshName, fname)));
164 P* proxy = LuaProxy::toObjectOfClass<P>(L, index);
167 *mesh = dynamic_cast<T*>(proxy->mesh());
172 GmLuaCellGroupSet* gproxy = LuaProxy::toObjectOfClass<GmLuaCellGroupSet>(L, index);
174 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.")
175 .arg(index).arg(fname)));
178 *mesh = dynamic_cast<T*>((*group)->mesh());
180 luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Cell group mesh has an invalid type in call to %1").arg(fname)));
215 T* ptr = proxy ? dynamic_cast<T*>(proxy->
get()) : NULL;
218 return luaL_error(L,
"%s", luaPrintable(
QObject::tr(
"Invalid %1 parameter in call to %2()").arg(tmsg, fmsg))), NULL;
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:70
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,...
Definition: gmLuaUtils.h:137
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:212
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:108
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:72
Declaration of the GmLuaCellGroupCell class.
QString tr(const char *sourceText, const char *disambiguation, int n)
Declaration of the function used to prepare an environment with the core Lua functions.
GmCellGroupSet * cellGroupSet() const
Returns the wrapped cell.
Definition: gmLuaCellGroupSet.h:51
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:130
A proxy class to export GmCellGroupSet methods to the Lua environment.
Definition: gmLuaCellGroupSet.h:33
bool isEmpty() const const
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:93
Groups utilitary routines for working with Lua.
Definition: gmLuaUtils.cpp:32
static void pushObject(lua_State *L, Base *obj)
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:90
QVariant getField(const char *name, LuaEnv::StackOption opt=LuaEnv::STACK_AUTO)
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 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:36
QString toString() const const
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:199
const QMap< QString, GmMesh * > & meshes() const
const T value(const Key &key, const T &defaultValue) const const