diff --git a/Common/LuaBindings.cpp b/Common/LuaBindings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bb7a495898e64a588217d48ad2747e65a66d4c1 --- /dev/null +++ b/Common/LuaBindings.cpp @@ -0,0 +1,64 @@ +#include "GmshConfig.h" +#ifdef HAVE_LUA +#include <iostream> +#include "Gmsh.h" +#include "Bindings.h" +#include "dgSystemOfEquations.h" +#include "luaFunction.h" +#include "function.h" +#include "dgGroupOfElements.h" +#include "dgConservationLawShallowWater2d.h" +#include "dgConservationLawAdvection.h" +#include "dgConservationLawPerfectGas.h" +#include "dgConservationLawWaveEquation.h" +extern "C" { + #include "lua.h" + #include "lualib.h" + #include "lauxlib.h" +} +void report_errors(lua_State *L, int status) +{ + if ( status!=0 ) { + std::cerr << "-- " << lua_tostring(L, -1) << std::endl; + lua_pop(L, 1); // remove error message + } +} + +int read_lua(const char *filename) +{ + lua_State *L = lua_open(); + luaopen_base(L); + luaopen_table(L); + luaopen_os(L); + //luaopen_io(L); + luaopen_string(L); + luaopen_math(L); + luaopen_debug(L); + + // Register Lua bindings + classBinding<GModel>::Register(L); + classBinding<dgSystemOfEquations>::Register(L); + classBinding<dgBoundaryCondition>::Register(L); + classBinding<dgConservationLaw>::Register(L); + classBinding<dgConservationLawShallowWater2d>::Register(L); + classBinding<dgConservationLawAdvection>::Register(L); + classBinding<dgConservationLawWaveEquation>::Register(L); + classBinding<dgPerfectGasLaw2d>::Register(L); + classBinding<fullMatrix<double> >::Register(L); + classBinding<function>::Register(L); + classBinding<functionLua>::Register(L); + classBinding<functionConstant>::Register(L); + function::registerDefaultFunctions(); + + int s = luaL_loadfile(L, filename); + + if ( s==0 ) { + printf("lua executes %s\n",filename); + s = lua_pcall(L, 0, LUA_MULTRET, 0); + } + report_errors(L, s); + + lua_close(L); + return s; +} +#endif diff --git a/Common/LuaBindings.h b/Common/LuaBindings.h new file mode 100644 index 0000000000000000000000000000000000000000..f70c09cef3dba27ee43430b1d21f0c8c920eecde --- /dev/null +++ b/Common/LuaBindings.h @@ -0,0 +1,6 @@ +#ifndef _LUA_BINDINGS_H_ +#define _LUA_BINDINGS_H_ +#ifdef HAVE_LUA +int read_lua(const char *filename); +#endif +#endif