/* SLB - Simple Lua Binder Copyright (C) 2007 Jose L. Hidalgo ValiƱo (PpluX) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Jose L. Hidalgo (www.pplux.com) pplux@pplux.com */ #ifndef __SLB_PUSH_GET__ #define __SLB_PUSH_GET__ #include "lua.hpp" #include "Debug.hpp" // Fix Apple problems #ifdef check #undef check #endif namespace SLB { //---------------------------------------------------------------------------- //-- Push/Get/Check functions ------------------------------------------------ //---------------------------------------------------------------------------- template void push(lua_State *L, T v); template T get(lua_State *L, int pos); template bool check(lua_State *L, int pos); template void setGlobal(lua_State *L, T v, const char *name); template T getGlobal(lua_State *L, const char *name); //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- namespace Private { template struct Type; } template inline void push(lua_State *L, T v) { SLB_DEBUG_CALL; Private::Type::push(L,v); } // get function based on Private::Type template inline T get(lua_State *L, int pos) { SLB_DEBUG_CALL; return Private::Type::get(L,pos); } template inline bool check(lua_State *L, int pos) { SLB_DEBUG_CALL; return Private::Type::check(L,pos); } template inline void setGlobal(lua_State *L, T v, const char *name) { SLB_DEBUG_CALL; SLB::push(L,v); lua_setglobal(L,name); } template inline T getGlobal(lua_State *L, const char *name) { SLB_DEBUG_CALL; lua_getglobal(L,name); T value = SLB::get(L, -1); lua_pop(L,1); // remove the value return value; } } // end of SLB namespace #endif