diff --git a/Common/LuaBindings.cpp b/Common/LuaBindings.cpp index ba60955d368cd1b4f80c662b06fc33bfab16cd14..887f4e9249ce52c752ae5d9cb2cdb7beef361dd0 100644 --- a/Common/LuaBindings.cpp +++ b/Common/LuaBindings.cpp @@ -21,6 +21,7 @@ #include "dgRungeKutta.h" #include "dgSystemOfEquations.h" #include "dgLimiter.h" +#include "bindings.h" extern "C" { #include "lua.h" @@ -33,6 +34,61 @@ extern "C" { #include "history.h" #endif +//trivial class to bind options +class gmshOptions { + public: + gmshOptions(){}; + void colorSet(std::string category, int index, std::string name, int value) { + GmshSetOption(category,name,(unsigned int)(value), index); + } + int colorGet(std::string category, int index, std::string name) { + unsigned int value; + GmshGetOption(category, name, value, index); + return value; + } + double numberGet(std::string category, int index, std::string name) { + double value; + GmshGetOption(category, name, value, index); + return value; + } + void numberSet(std::string category, int index, std::string name, double value) { + GmshSetOption(category, name, value, index); + } + std::string stringGet(std::string category, int index, std::string name) { + std::string value; + GmshGetOption(category, name, value, index); + return value; + } + void stringSet(std::string category, int index, std::string name, double value) { + GmshSetOption(category, name, value, index); + } + static void registerBindings(binding *b) { + classBinding *cb = b->addClass<gmshOptions>("gmshOptions"); + cb->setDescription("access the gmsh option database"); + methodBinding *mb; + mb = cb->addMethod("colorSet", &gmshOptions::colorSet); + mb->setDescription("set the value of a color (unsigned int) option. This is equivalent to category[index].name = value"); + mb->setArgNames("category","index","name","value",NULL); + mb = cb->addMethod("colorGet", &gmshOptions::colorGet); + mb->setDescription("return the value of a color (unsigned int) option. This is equivalent to category[index].name"); + mb->setArgNames("category","index","name",NULL); + mb = cb->addMethod("numberSet", &gmshOptions::numberSet); + mb->setDescription("set the value of a number option. This is equivalent to category[index].name = value"); + mb->setArgNames("category","index","name","value",NULL); + mb = cb->addMethod("numberGet", &gmshOptions::numberGet); + mb->setDescription("return the value of a number option. This is equivalent to category[index].name"); + mb->setArgNames("category","index","name",NULL); + mb = cb->addMethod("srtingSet", &gmshOptions::stringSet); + mb->setDescription("set the value of a string option. This is equivalent to category[index].name = \"value\""); + mb->setArgNames("category","index","name","value",NULL); + mb = cb->addMethod("srtingGet", &gmshOptions::stringGet); + mb->setDescription("return the value of a string option. This is equivalent to category[index].name"); + mb->setArgNames("category","index","name",NULL); + mb = cb->setConstructor<gmshOptions>(); + mb->setDescription("an instance of gmshOptions is needed to access the database"); + } +}; + static void reportErrors(lua_State *L, int status) { if ( status!=0 ) { @@ -288,6 +344,7 @@ binding::binding(){ DocRecord::registerBindings(this); GEntity::registerBindings(this); GFace::registerBindings(this); + gmshOptions::registerBindings(this); } binding *binding::_instance=NULL; #endif diff --git a/Common/LuaBindings.h b/Common/LuaBindings.h index 866a5058cac269e68367d3187b2ea3dbcd15f123..22c476fd609ca531d8638f438bdae374e926c936 100644 --- a/Common/LuaBindings.h +++ b/Common/LuaBindings.h @@ -119,6 +119,21 @@ class luaStack<int>{ } }; +template<> +class luaStack<unsigned int>{ + public: + static int get(lua_State *L, unsigned int ia){ + unsigned int a= (unsigned int)luaL_checkint(L,ia); + return a; + } + static void push(lua_State *L, unsigned int i){ + lua_pushinteger(L,i); + } + static std::string getName(){ + return "unsigned int"; + } +}; + template<class type> class luaStack<std::vector<type > >{ public: