/* vrepFfi.h -- exposing functions to V-REP * Copyright (C) 2013 Galois, Inc. * * This library is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this library. If not, see . * * To contact Galois, complete the Web form at * or write to Galois, Inc., 421 Southwest 6th Avenue, Suite 300, Portland, * Oregon, 97204-1622. */ #ifndef PPAML_VREP_AUTOMOBILE_PLUGIN_VREPFFI_H_ #define PPAML_VREP_AUTOMOBILE_PLUGIN_VREPFFI_H_ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include #include #include "vrep.h" namespace vrep { namespace { // C-Lua type equivalences // template struct LuaTypeWrapper { static const int id = idVal; static inline T isNextArg(const SLuaCallBack *); }; template struct LuaType; template<> struct LuaType : public LuaTypeWrapper { }; template<> struct LuaType : public LuaTypeWrapper { typedef simBool LuaT; }; template<> struct LuaType : public LuaTypeWrapper { typedef simInt LuaT; }; template<> struct LuaType : public LuaTypeWrapper { typedef simFloat LuaT; }; template<> struct LuaType : public LuaTypeWrapper { typedef simChar LuaT; }; template struct LuaType> : public LuaTypeWrapper, sim_lua_arg_table | LuaType::id> { typedef typename LuaType::LuaT LuaT; }; // Converting a variadic template type to a Lua type list // std::forward_list toLuaTypes(); template std::forward_list toLuaTypes(); template std::forward_list toLuaTypes(); } // Exposing C++ functions to Lua // template void exposeFunction(const std::string name, const std::string callTips, simVoid (*const f)(SLuaCallBack *)); // Extracting Lua arguments from the callback structure // /* A class layered on 'SLuaCallBack' for handling calls from Lua into C++. * Watch out--interacting with this class at all outside of a C++ function * exposed to Lua will almost certainly cause undefined behavior! */ class LuaCall { public: LuaCall(SLuaCallBack *); template T expectAtom(); template std::vector expectTable(); private: void ensureNextArgType(const int expected); template T unsafeGetAtom(); template std::vector unsafeGetTable(); SLuaCallBack *const simCall; size_t argIdx; simBool *cursorBool; simInt *cursorInt; simFloat *cursorFloat; simChar *cursorChar; }; template<> inline bool LuaCall::unsafeGetAtom(); template<> inline int LuaCall::unsafeGetAtom(); template<> inline float LuaCall::unsafeGetAtom(); template<> std::string LuaCall::unsafeGetAtom(); // Error handling // // An error signaling a failed marshal from Lua to C++. class MarshalingError : public Error { public: explicit inline MarshalingError(const std::string &whatArg); explicit inline MarshalingError(const char *whatArg); }; } #include "vrepFfi-inl.h" #endif