From ea0ac7e79c65903c16e3f3ddddbb25c535b5e3cf Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Thu, 18 Feb 2010 09:39:46 +0000 Subject: [PATCH] lua bindings of gmsh options --- Common/LuaBindings.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ Common/LuaBindings.h | 15 +++++++++++ 2 files changed, 72 insertions(+) diff --git a/Common/LuaBindings.cpp b/Common/LuaBindings.cpp index ba60955d36..887f4e9249 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 866a5058ca..22c476fd60 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: -- GitLab