Diluculum  1.0
LuaState.hpp
Go to the documentation of this file.
00001 /******************************************************************************\
00002 * LuaState                                                                     *
00003 * A pleasant way to use a Lua state in C++.                                    *
00004 *                                                                              *
00005 *                                                                              *
00006 * Copyright (C) 2005-2013 by Leandro Motta Barros.                             *
00007 *                                                                              *
00008 * Permission is hereby granted, free of charge, to any person obtaining a copy *
00009 * of this software and associated documentation files (the "Software"), to     *
00010 * deal in the Software without restriction, including without limitation the   *
00011 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  *
00012 * sell copies of the Software, and to permit persons to whom the Software is   *
00013 * furnished to do so, subject to the following conditions:                     *
00014 *                                                                              *
00015 * The above copyright notice and this permission notice shall be included in   *
00016 * all copies or substantial portions of the Software.                          *
00017 *                                                                              *
00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR   *
00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,     *
00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE *
00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER       *
00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      *
00023 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS *
00024 * IN THE SOFTWARE.                                                             *
00025 \******************************************************************************/
00026 
00027 
00028 #ifndef _DILUCULUM_LUA_STATE_HPP_
00029 #define _DILUCULUM_LUA_STATE_HPP_
00030 
00031 #include <lua.hpp>
00032 #include <string>
00033 #include <vector>
00034 #include <Diluculum/LuaExceptions.hpp>
00035 #include <Diluculum/LuaValue.hpp>
00036 #include <Diluculum/LuaVariable.hpp>
00037 #include <Diluculum/Types.hpp>
00038 
00039 
00040 namespace Diluculum
00041 {
00042 
00050    class LuaState
00051    {
00052       public:
00060          explicit LuaState (bool loadStdLib = true);
00061 
00073          explicit LuaState (lua_State* state, bool loadStdLib = false);
00074 
00080          virtual ~LuaState();
00081 
00093          LuaValueList doFile (const std::string& fileName)
00094          { return doStringOrFile (false, fileName); }
00095 
00107          LuaValueList doString (const std::string& what)
00108          { return doStringOrFile (true, what); }
00109 
00119          LuaValueList call (LuaFunction& func,
00120                             const LuaValueList& params,
00121                             const std::string& chunkName = "Diluculum chunk");
00122 
00136          LuaVariable operator[] (const std::string& variable);
00137 
00147          LuaValueMap globals();
00148 
00150          lua_State* getState() { return state_; }
00151 
00152       private:
00167          LuaValueList doStringOrFile (bool isString, const std::string& str);
00168 
00170          lua_State* state_;
00171 
00175          const bool ownsState_;
00176    };
00177 
00178 } // namespace Diluculum
00179 
00180 #endif // #ifndef _DILUCULUM_LUA_STATE_HPP_