Mercurial > code
view C++/LuaeVariant.h @ 231:2f1d820e6e33
Merge with OptionParser
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 22 Jun 2014 16:19:31 +0200 |
parents | e01ee0c72c43 |
children |
line wrap: on
line source
/* * LuaeVariant.h -- Lua variant helper * * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _LUAE_VARIANT_H_ #define _LUAE_VARIANT_H_ #include <lua.hpp> /** * @class LuaeVariant * @brief A fake variant for Lua values * * This class is primarly used for copying Lua values without checking * the types, useful to pass data. */ class LuaeVariant { private: union { lua_Number number; bool boolean; }; int type; std::string str; std::vector<std::pair<LuaeVariant, LuaeVariant>> table; public: /** * Dump a value at the specific index. * * @param L the Lua state * @param index the value * @return a tree of values */ static LuaeVariant copy(lua_State *L, int index); /** * Push a value to a state. * * @param L the Lua state * @param value the value to push */ static void push(lua_State *L, const LuaeVariant &value); /** * Default constructor (type nil) */ LuaeVariant(); }; #endif // !_LUAE_VARIANT_H_