Exemple #1
0
		static lua_CFunction from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_iscfunction(state, index) != 0, LUA_TFUNCTION, index);

			auto func = ::lua_tocfunction(state, index);
			return func;
		}
Exemple #2
0
		static std::basic_string<CharT, CharTraitsT, AllocatorT> from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isstring(state, index) != 0, LUA_TSTRING, index);
			std::size_t len = 0;
			auto p = ::lua_tolstring(state, index, &len);
			return std::basic_string<CharT, CharTraitsT, AllocatorT>(p, len);
		}
Exemple #3
0
		static std::pair<const char *, std::uint32_t> from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isstring(state, index) != 0, LUA_TSTRING, index);

			std::size_t len = 0;
			const char *p = ::lua_tolstring(state, index, &len);

			return { p, (std::uint32_t)len };
		}
Exemple #4
0
		static vector_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);

			vector_t vec;
			const int len = ::lua_rawlen(state, index);
			vec.reserve(len);

			for(auto i = 1; i <= len; ++i) 
			{
				::lua_rawgeti(state, index, i);
				vec.emplace_back(std::move(static_cast<T>(convertion_t<T>::from(state, -1))));
				lua_pop(state, 1);
			}

			return vec;
		}
Exemple #5
0
		static pair_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);

			const std::uint32_t len = (std::uint32_t)::lua_rawlen(state, index);
			assert(len == 2);

			::lua_rawgeti(state, index, 1);
			FirstT first_val = convertion_t<FirstT>::from(state, -1);
			lua_pop(state, 1);

			::lua_rawgeti(state, index, 2);
			SecondT second_val = convertion_t<SecondT>::from(state, -1);
			lua_pop(state, 1);

			return { std::move(first_val), std::move(second_val) };
		}
Exemple #6
0
		static pair_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);

			const int len = ::lua_objlen(state, index);
			assert(len == 2);

			::lua_rawgeti(state, index, 1);
			FirstT first_val = convertion_t<FirstT>::from(state, -1);
			lua_pop(state, 1);

			::lua_rawgeti(state, index, 2);
			SecondT second_val = convertion_t<SecondT>::from(state, -1);
			lua_pop(state, 1);

			return std::make_pair(first_val, second_val);
		}
Exemple #7
0
		static map_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);

			map_t map_val;
			const int len = ::lua_objlen(state, index);

			for(auto i = 1; i <= len; ++i) 
			{
				::lua_rawgeti(state, index, i);

				typedef typename map_t::value_type value_t;
				value_t val = convertion_t<value_t>::from(state, -1);
				map_val.insert(std::move(val));

				lua_pop(state, 1);
			}
			return map_val;
		}
Exemple #8
0
		static map_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);

			map_t map_val;
			::lua_pushvalue(state, index);
			::lua_pushnil(state);

			while( ::lua_next(state, -2) )
			{
				::lua_pushvalue(state, -2);

				auto key = convertion_t<KeyT>::from(state, -1);
				auto value = convertion_t<ValueT>::from(state, -2);
				//map_val.emplace(std::move(key), std::move(value));
				map_val.insert(std::make_pair(key, value));

				lua_pop(state, 2);
			}

			lua_pop(state, 1);

			return map_val;
		}
Exemple #9
0
		static T * from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isuserdata(state, index) != 0, LUA_TUSERDATA, index);

			return static_cast<T *>(::lua_touserdata(state, index));
		}
Exemple #10
0
		static void * from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_islightuserdata(state, index) != 0, LUA_TLIGHTUSERDATA, index);

			return ::lua_touserdata(state, index);
		}
Exemple #11
0
		static string_ref_t from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isstring(state, index) != 0, LUA_TSTRING, index);
			::lua_pushvalue(state, index);
			return string_ref_t(state);
		}
Exemple #12
0
		static table_ref_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_istable(state, index) != 0, LUA_TTABLE, index);
			::lua_pushvalue(state, index);
			return table_ref_t(state);
		}
Exemple #13
0
		static function_ref_t from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_isfunction(state, index) != 0, LUA_TFUNCTION, index);
			::lua_pushvalue(state, index);
			return function_ref_t(state);
		}
Exemple #14
0
		static std::string from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isstring(state, index) != 0, LUA_TSTRING, index);
			return ::lua_tostring(state, index);
		}
Exemple #15
0
		static bool from(state_t &state, int index)
		{
			LUAREG_ERROR(lua_isboolean(state, index) != 0, LUA_TBOOLEAN, index);
			int n = ::lua_toboolean(state, index);
			return n != 0;
		}
Exemple #16
0
		static T from(state_t &state, int index)
		{
			LUAREG_ERROR(::lua_isnumber(state, index) != 0, LUA_TNUMBER, index);

			return static_cast<T>(::lua_tonumber(state, index));
		}