Lua_icxx  1.02 (Aug 2011)
LuaFuncRef.cpp
00001 /*
00002 This file is part of the Lua_icxx library. 
00003 Copyright 2010 (c) by Oliver Schoenborn. 
00004 License terms in LICENSE.txt.
00005 */
00006 
00007 
00008 #include "LuaFuncRef.h"
00009 #include "LuaTableRef.h"
00010 #include "LuaStackCleaner.h"
00011 
00012 
00013 bool
00014 LuaFuncRef::setEnv( const LuaTableRef& envTable )
00015 {
00016     LuaStackCleaner s(mLua);
00017     pushObj();
00018     envTable.pushObj();
00019     const bool ok = ( lua_setfenv(mLua, -2) == 0 ? false : true );
00020     assert( s.willPop(1) );
00021     return ok;
00022 }
00023 
00024 
00025 LuaTempResult
00026 LuaFuncRef::getEnv()
00027 const 
00028 {
00029     const int preStack = lua_gettop(mLua);
00030     pushObj();
00031     assert( lua_checkstack(mLua, 1) ); 
00032     lua_getfenv(mLua, -1);
00033     return LuaTempResult(mLua, preStack);
00034 }
00035 
00036 
00037 void 
00038 LuaBoundMethRef::resetRef( const LuaObjRef & obj, const LuaFuncRef & fn )
00039 {
00040     mObjRef = obj;
00041     mMethRef = fn; 
00042 }
00043 
00044 
00045 LuaBoundMethRef 
00046 LuaClassObjRef::getBoundMethod( const std::string& name ) const
00047 {
00048     const int prevStackTop = lua_gettop(mLua);
00049     pushObj(); // push "table" (the object)
00050     assert( lua_checkstack(mLua, 1) ); 
00051     lua_getfield(mLua, -1, name.c_str());
00052     return LuaTempResult(mLua, prevStackTop);
00053 }
00054 
00055