2013-11-25 17:56:27 +08:00
|
|
|
// The MIT License (MIT)
|
|
|
|
|
|
|
|
// Copyright (c) 2013 Danny Y., Rapptz
|
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
|
|
// the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
// subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef SOL_STACK_HPP
|
|
|
|
#define SOL_STACK_HPP
|
|
|
|
|
2014-01-23 01:51:09 +08:00
|
|
|
#include "error.hpp"
|
2013-11-25 17:56:27 +08:00
|
|
|
#include "reference.hpp"
|
2013-12-03 03:22:51 +08:00
|
|
|
#include "tuple.hpp"
|
2013-12-13 07:35:42 +08:00
|
|
|
#include "traits.hpp"
|
2014-06-07 10:54:45 +08:00
|
|
|
#include "userdata_traits.hpp"
|
2013-11-25 17:56:27 +08:00
|
|
|
#include <utility>
|
2013-12-09 12:05:03 +08:00
|
|
|
#include <array>
|
2013-12-10 06:01:52 +08:00
|
|
|
#include <cstring>
|
2014-06-01 02:29:14 +08:00
|
|
|
#include <functional>
|
2013-11-25 17:56:27 +08:00
|
|
|
|
|
|
|
namespace sol {
|
|
|
|
namespace detail {
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T>
|
|
|
|
T* get_ptr(T& val) {
|
|
|
|
return std::addressof(val);
|
2014-05-09 22:48:55 +08:00
|
|
|
}
|
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T>
|
|
|
|
T* get_ptr(T* val) {
|
|
|
|
return val;
|
2014-05-09 22:48:55 +08:00
|
|
|
}
|
2014-06-07 10:54:45 +08:00
|
|
|
} // detail
|
2014-05-09 22:48:55 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
namespace stack {
|
|
|
|
namespace detail {
|
|
|
|
template<typename T, typename Key>
|
|
|
|
inline void push_userdata(lua_State* L, T&& userdata, Key&& metatablekey) {
|
|
|
|
T* pdatum = static_cast<T*>(lua_newuserdata(L, sizeof(T)));
|
|
|
|
T& datum = *pdatum;
|
|
|
|
datum = std::forward<T>(userdata);
|
|
|
|
luaL_getmetatable(L, std::addressof(metatablekey[0]));
|
|
|
|
lua_setmetatable(L, -2);
|
2014-05-31 07:58:47 +08:00
|
|
|
}
|
2014-06-07 10:54:45 +08:00
|
|
|
} // detail
|
|
|
|
template <typename T, typename X = void>
|
|
|
|
struct getter;
|
|
|
|
template <typename T, typename X = void>
|
|
|
|
struct pusher;
|
2014-05-31 07:58:47 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <typename T, typename>
|
|
|
|
struct getter {
|
|
|
|
template<typename U = T, EnableIf<std::is_floating_point<U>> = 0>
|
|
|
|
static U get(lua_State* L, int index = -1) {
|
|
|
|
return lua_tonumber(L, index);
|
|
|
|
}
|
2014-05-09 22:48:55 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_integral<U>, std::is_signed<U>> = 0>
|
|
|
|
static U get(lua_State* L, int index = -1) {
|
|
|
|
return lua_tounsigned(L, index);
|
|
|
|
}
|
2014-05-09 22:48:55 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_integral<U>, std::is_unsigned<U>> = 0>
|
|
|
|
static U get(lua_State* L, int index = -1) {
|
|
|
|
return static_cast<T>(lua_tointeger(L, index));
|
|
|
|
}
|
2014-06-01 02:29:14 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_base_of<reference, U>> = 0>
|
|
|
|
static U get(lua_State* L, int index = -1) {
|
|
|
|
return T(L, index);
|
|
|
|
}
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>
|
|
|
|
static U& get(lua_State* L, int index = -1) {
|
|
|
|
void* udata = lua_touserdata(L, index);
|
|
|
|
T* obj = static_cast<T*>(udata);
|
|
|
|
return *obj;
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <typename T>
|
|
|
|
struct getter<T*> {
|
|
|
|
static T* get(lua_State* L, int index = -1) {
|
|
|
|
void* udata = lua_touserdata(L, index);
|
|
|
|
T** obj = static_cast<T**>(udata);
|
|
|
|
return *obj;
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<type> {
|
|
|
|
type get(lua_State *L, int index){
|
|
|
|
return static_cast<type>(lua_type(L, index));
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<bool> {
|
|
|
|
static bool get(lua_State* L, int index) {
|
|
|
|
return lua_toboolean(L, index) != 0;
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<std::string> {
|
|
|
|
static std::string get(lua_State* L, int index = -1) {
|
|
|
|
std::string::size_type len;
|
|
|
|
auto str = lua_tolstring(L, index, &len);
|
|
|
|
return{ str, len };
|
|
|
|
}
|
|
|
|
};
|
2013-12-12 00:56:34 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<const char*> {
|
|
|
|
const char* get(lua_State* L, int index = -1) {
|
|
|
|
return lua_tostring(L, index);
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<nil_t> {
|
|
|
|
nil_t get(lua_State* L, int index = -1) {
|
|
|
|
if (lua_isnil(L, index) == 0)
|
|
|
|
throw sol::error("not nil");
|
|
|
|
return nil_t{ };
|
|
|
|
}
|
|
|
|
};
|
2014-04-27 06:23:56 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<userdata_t> {
|
|
|
|
userdata_t get(lua_State* L, int index = -1) {
|
|
|
|
return{ lua_touserdata(L, index) };
|
2014-04-26 08:20:35 +08:00
|
|
|
}
|
2014-06-07 10:54:45 +08:00
|
|
|
};
|
2014-04-26 08:20:35 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<lightuserdata_t> {
|
|
|
|
lightuserdata_t get(lua_State* L, int index = 1) {
|
|
|
|
return{ lua_touserdata(L, lua_upvalueindex(index)) };
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template <>
|
|
|
|
struct getter<void*> {
|
|
|
|
void* get(lua_State* L, int index = 1) {
|
|
|
|
return lua_touserdata(L, index);
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T, typename>
|
2014-06-01 13:03:27 +08:00
|
|
|
struct pusher {
|
|
|
|
template<typename U = T, EnableIf<std::is_floating_point<U>> = 0>
|
|
|
|
static void push(lua_State* L, const T& value) {
|
|
|
|
lua_pushnumber(L, value);
|
2014-06-01 08:02:54 +08:00
|
|
|
}
|
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_integral<U>, std::is_signed<U>> = 0>
|
|
|
|
static void push(lua_State* L, const T& value) {
|
|
|
|
lua_pushinteger(L, value);
|
|
|
|
}
|
2013-11-26 17:05:04 +08:00
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_integral<U>, std::is_unsigned<U>> = 0>
|
|
|
|
static void push(lua_State* L, const T& value) {
|
|
|
|
lua_pushunsigned(L, value);
|
|
|
|
}
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<std::is_base_of<reference, U>> = 0>
|
|
|
|
static void push(lua_State*, T& ref) {
|
|
|
|
ref.push();
|
2014-06-01 13:03:27 +08:00
|
|
|
}
|
2014-06-01 13:07:26 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>
|
|
|
|
static void push(lua_State* L, T& t) {
|
|
|
|
pusher<T*>{}.push(L, std::addressof(t));
|
2014-06-01 13:07:26 +08:00
|
|
|
}
|
2014-06-01 14:10:36 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename U = T, EnableIf<Not<std::is_base_of<reference, U>>, Not<std::is_integral<U>>, Not<std::is_floating_point<U>>> = 0>
|
|
|
|
static void push(lua_State* L, T&& t) {
|
|
|
|
detail::push_userdata(L, std::move(t), userdata_traits<T*>::metatable);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct pusher<T*> {
|
|
|
|
static void push(lua_State* L, T* obj) {
|
|
|
|
detail::push_userdata(L, obj, userdata_traits<T*>::metatable);
|
2014-06-01 14:10:36 +08:00
|
|
|
}
|
2014-06-01 13:03:27 +08:00
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<>
|
|
|
|
struct pusher<bool> {
|
|
|
|
static void push(lua_State* L, const bool& b) {
|
|
|
|
lua_pushboolean(L, b);
|
|
|
|
}
|
|
|
|
};
|
2013-12-08 10:16:23 +08:00
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<>
|
|
|
|
struct pusher<nil_t> {
|
|
|
|
static void push(lua_State* L, const nil_t&) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct pusher<lua_CFunction> {
|
|
|
|
static void push(lua_State* L, lua_CFunction func) {
|
|
|
|
lua_pushcfunction(L, func);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct pusher<void*> {
|
|
|
|
static void push(lua_State* L, void* userdata) {
|
|
|
|
lua_pushlightuserdata(L, userdata);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<>
|
|
|
|
struct pusher<lightuserdata_t> {
|
|
|
|
static void push(lua_State* L, lightuserdata_t userdata) {
|
|
|
|
lua_pushlightuserdata(L, userdata);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<>
|
|
|
|
struct pusher<const char*> {
|
|
|
|
static void push(lua_State* L, const char* str) {
|
|
|
|
lua_pushlstring(L, str, std::char_traits<char>::length(str));
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
|
|
|
template<size_t N>
|
2014-06-01 13:03:27 +08:00
|
|
|
struct pusher<char[N]> {
|
|
|
|
static void push(lua_State* L, const char (&str)[N]) {
|
|
|
|
lua_pushlstring(L, str, N - 1);
|
|
|
|
}
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
template<>
|
|
|
|
struct pusher<std::string> {
|
|
|
|
static void push(lua_State* L, const std::string& str) {
|
|
|
|
lua_pushlstring(L, str.c_str(), str.size());
|
|
|
|
}
|
|
|
|
};
|
2013-12-09 12:05:03 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
inline void push(lua_State*) {
|
|
|
|
|
2013-11-25 17:56:27 +08:00
|
|
|
}
|
2013-12-03 03:22:51 +08:00
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T, typename... Args>
|
|
|
|
inline void push(lua_State* L, T&& t, Args&&... args) {
|
|
|
|
using swallow = char[];
|
|
|
|
pusher<Unqualified<T>>{}.push(L, std::forward<T>(t));
|
|
|
|
void(swallow{'\0', (pusher<Unqualified<T>>{}.push(L, std::forward<Args>(args)), '\0')... });
|
2013-12-10 03:12:38 +08:00
|
|
|
}
|
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T, typename U = Unqualified<T>>
|
|
|
|
inline auto get(lua_State* L, int index = -1) -> decltype(getter<U>{}.get(L, index)) {
|
|
|
|
return getter<U>{}.get(L, index);
|
2013-12-09 12:05:03 +08:00
|
|
|
}
|
|
|
|
|
2013-12-12 00:18:13 +08:00
|
|
|
template<typename T>
|
2014-06-07 10:54:45 +08:00
|
|
|
auto pop(lua_State* L) -> decltype(get<T>(L)) {
|
|
|
|
typedef decltype(get<T>(L)) ret_t;
|
|
|
|
ret_t r = get<T>(L);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
inline int push_as_upvalues(lua_State* L, T& item) {
|
2013-12-12 00:18:13 +08:00
|
|
|
typedef typename std::decay<T>::type TValue;
|
|
|
|
const static std::size_t itemsize = sizeof(TValue);
|
|
|
|
const static std::size_t voidsize = sizeof(void*);
|
|
|
|
const static std::size_t voidsizem1 = voidsize - 1;
|
|
|
|
const static std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize;
|
|
|
|
typedef std::array<void*, data_t_count> data_t;
|
2013-12-10 06:01:52 +08:00
|
|
|
|
2013-12-12 00:18:13 +08:00
|
|
|
data_t data{{}};
|
2013-12-12 18:07:58 +08:00
|
|
|
std::memcpy(std::addressof(data[0]), std::addressof(item), itemsize);
|
2014-06-07 10:54:45 +08:00
|
|
|
for (auto&& v : data) {
|
|
|
|
push(L, v);
|
|
|
|
}
|
2013-12-12 00:18:13 +08:00
|
|
|
return data_t_count;
|
2013-12-10 06:01:52 +08:00
|
|
|
}
|
|
|
|
|
2014-06-07 10:54:45 +08:00
|
|
|
template<typename T>
|
|
|
|
inline std::pair<T, int> get_as_upvalues(lua_State* L, int index = 1) {
|
|
|
|
const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*);
|
|
|
|
typedef std::array<void*, data_t_count> data_t;
|
|
|
|
data_t voiddata{ {} };
|
|
|
|
for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) {
|
|
|
|
voiddata[ i ] = get<lightuserdata_t>(L, index++);
|
|
|
|
}
|
|
|
|
return std::pair<T, int>(*reinterpret_cast<T*>(static_cast<void*>(voiddata.data())), index);
|
|
|
|
}
|
|
|
|
|
2013-12-03 03:22:51 +08:00
|
|
|
template<typename T, std::size_t... I>
|
2013-12-15 12:25:44 +08:00
|
|
|
inline void push_tuple(lua_State* L, indices<I...>, T&& tuplen) {
|
2013-12-22 11:11:20 +08:00
|
|
|
using swallow = char[1 + sizeof...(I)];
|
2013-12-14 12:26:59 +08:00
|
|
|
swallow {'\0', (sol::stack::push(L, std::get<I>(tuplen)), '\0')... };
|
2013-12-03 03:22:51 +08:00
|
|
|
}
|
2013-12-03 08:34:10 +08:00
|
|
|
|
2014-04-27 06:23:56 +08:00
|
|
|
template<typename F, typename... Vs, typename... Args>
|
2014-04-27 12:53:57 +08:00
|
|
|
inline auto ltr_get(lua_State*, int, F&& f, types<Args...>, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
2014-04-27 06:23:56 +08:00
|
|
|
return f(std::forward<Vs>(vs)...);
|
|
|
|
}
|
|
|
|
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>
|
|
|
|
inline auto ltr_get(lua_State* L, int index, F&& f, types<Args...> t, types<Head, Tail...>, Vs&&... vs) -> decltype(f(std::declval<Args>()...)) {
|
2014-05-09 22:48:55 +08:00
|
|
|
return ltr_get(L, index + 1, std::forward<F>(f), t, types<Tail...>(), std::forward<Vs>(vs)..., stack::get<Head>(L, index));
|
2014-04-27 06:23:56 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 06:09:23 +08:00
|
|
|
template<typename F, typename... Vs, typename... Args>
|
2014-04-24 20:15:12 +08:00
|
|
|
inline auto ltr_pop(lua_State*, F&& f, types<Args...>, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
2013-12-09 12:09:07 +08:00
|
|
|
return f(std::forward<Vs>(vs)...);
|
2013-12-03 10:39:21 +08:00
|
|
|
}
|
2013-12-16 06:09:23 +08:00
|
|
|
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>
|
2014-04-24 20:15:12 +08:00
|
|
|
inline auto ltr_pop(lua_State* L, F&& f, types<Args...> t, types<Head, Tail...>, Vs&&... vs) -> decltype(f(std::declval<Args>()...)) {
|
2014-05-09 22:48:55 +08:00
|
|
|
return ltr_pop(L, std::forward<F>(f), t, types<Tail...>(), std::forward<Vs>(vs)..., stack::pop<Head>(L));
|
2013-12-03 08:34:10 +08:00
|
|
|
}
|
2013-12-16 05:27:20 +08:00
|
|
|
|
2013-12-16 05:52:01 +08:00
|
|
|
template<typename F, typename... Vs, typename... Args>
|
2014-04-24 20:15:12 +08:00
|
|
|
inline auto rtl_pop(lua_State*, F&& f, types<Args...>, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
2013-12-16 05:27:20 +08:00
|
|
|
return f(std::forward<Vs>(vs)...);
|
|
|
|
}
|
2013-12-16 05:45:40 +08:00
|
|
|
template<typename F, typename Head, typename... Tail, typename... Vs, typename... Args>
|
2014-04-24 20:15:12 +08:00
|
|
|
inline auto rtl_pop(lua_State* L, F&& f, types<Args...> t, types<Head, Tail...>, Vs&&... vs) -> decltype(f(std::declval<Args>()...)) {
|
2014-05-09 22:48:55 +08:00
|
|
|
return rtl_pop(L, std::forward<F>(f), t, types<Tail...>(), stack::pop<Head>(L), std::forward<Vs>(vs)...);
|
2013-12-16 05:27:20 +08:00
|
|
|
}
|
2013-12-03 03:22:51 +08:00
|
|
|
} // detail
|
|
|
|
|
|
|
|
template<typename... Args>
|
2014-06-01 13:03:27 +08:00
|
|
|
struct pusher<std::tuple<Args...>> {
|
|
|
|
static void push(lua_State* L, const std::tuple<Args...>& tuplen) {
|
|
|
|
detail::push_tuple(L, build_indices<sizeof...(Args)>(), tuplen);
|
|
|
|
}
|
2013-12-15 12:25:44 +08:00
|
|
|
|
2014-06-01 13:03:27 +08:00
|
|
|
static void push(lua_State* L, std::tuple<Args...>&& tuplen) {
|
|
|
|
detail::push_tuple(L, build_indices<sizeof...(Args)>(), std::move(tuplen));
|
|
|
|
}
|
|
|
|
};
|
2013-12-16 05:27:20 +08:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline void push_reverse(lua_State* L, T&& item) {
|
|
|
|
push(L, std::forward<T>(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
inline void push_reverse(lua_State* L, const std::tuple<Args...>& tuplen) {
|
|
|
|
detail::push_tuple(L, build_reverse_indices<sizeof...(Args)>(), tuplen);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
inline void push_reverse(lua_State* L, std::tuple<Args...>&& tuplen) {
|
2013-12-15 12:25:44 +08:00
|
|
|
detail::push_tuple(L, build_reverse_indices<sizeof...(Args)>(), std::move(tuplen));
|
2013-12-03 03:22:51 +08:00
|
|
|
}
|
|
|
|
|
2014-04-27 06:23:56 +08:00
|
|
|
template<typename... Args, typename TFx>
|
|
|
|
inline auto get_call(lua_State* L, int index, TFx&& fx, types<Args...> t) -> decltype(detail::ltr_get(L, index, std::forward<TFx>(fx), t, t)) {
|
|
|
|
return detail::ltr_get(L, index, std::forward<TFx>(fx), t, t);
|
|
|
|
}
|
|
|
|
|
2014-05-31 06:21:19 +08:00
|
|
|
template<typename... Args, typename TFx>
|
2014-06-07 10:54:45 +08:00
|
|
|
inline auto get_call(lua_State* L, TFx&& fx, types<Args...> t) -> decltype(get_call(L, 1, std::forward<TFx>(fx), t)) {
|
|
|
|
return get_call(L, 1, std::forward<TFx>(fx), t);
|
2014-05-31 06:21:19 +08:00
|
|
|
}
|
|
|
|
|
2013-12-03 03:22:51 +08:00
|
|
|
template<typename... Args, typename TFx>
|
2013-12-16 06:09:23 +08:00
|
|
|
inline auto pop_call(lua_State* L, TFx&& fx, types<Args...> t) -> decltype(detail::ltr_pop(L, std::forward<TFx>(fx), t, t)) {
|
|
|
|
return detail::ltr_pop(L, std::forward<TFx>(fx), t, t);
|
2013-12-03 03:22:51 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 05:27:20 +08:00
|
|
|
template<typename... Args, typename TFx>
|
2013-12-16 06:09:23 +08:00
|
|
|
inline auto pop_reverse_call(lua_State* L, TFx&& fx, types<Args...> t) -> decltype(detail::rtl_pop(L, std::forward<TFx>(fx), t, reversed<Args...>())) {
|
|
|
|
return detail::rtl_pop(L, std::forward<TFx>(fx), t, reversed<Args...>());
|
2013-12-16 05:27:20 +08:00
|
|
|
}
|
|
|
|
|
2014-04-27 06:23:56 +08:00
|
|
|
inline call_syntax get_call_syntax(lua_State* L, const std::string& meta) {
|
|
|
|
if (get<type>(L, 1) == type::table) {
|
|
|
|
if (luaL_newmetatable(L, meta.c_str()) == 0) {
|
|
|
|
lua_settop(L, -2);
|
|
|
|
return call_syntax::colon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return call_syntax::dot;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string dump_types(lua_State* L) {
|
|
|
|
std::string visual;
|
|
|
|
std::size_t size = lua_gettop(L) + 1;
|
|
|
|
for (std::size_t i = 1; i < size; ++i) {
|
|
|
|
if (i != 1)
|
|
|
|
visual += " | ";
|
|
|
|
visual += type_name(L, stack::get<type>(L, i));
|
|
|
|
}
|
|
|
|
return visual;
|
|
|
|
}
|
2014-05-09 22:48:55 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct get_return {
|
|
|
|
typedef decltype(get<T>(nullptr)) type;
|
|
|
|
};
|
2013-11-25 17:56:27 +08:00
|
|
|
} // stack
|
|
|
|
} // sol
|
|
|
|
|
2014-05-29 14:38:02 +08:00
|
|
|
#endif // SOL_STACK_HPP
|