2011-08-28 15:17:58 +02:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-08-28 15:17:58 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#ifndef LUAVALUECASTS_H
|
|
|
|
#define LUAVALUECASTS_H
|
|
|
|
|
|
|
|
// this file is and must be included only from luainterface.h
|
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
#include "declarations.h"
|
|
|
|
#include <framework/otml/declarations.h>
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-07-05 14:38:48 +02:00
|
|
|
template<typename T>
|
|
|
|
int push_internal_luavalue(T v);
|
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// bool
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(bool b);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, bool& b);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// int
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(int i);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, int& i);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// double
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(double d);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, double& d);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
// float
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(float f) { push_luavalue((double)f); return 1; }
|
2012-01-10 23:13:40 +01:00
|
|
|
inline bool luavalue_cast(int index, float& f) { double d; bool r = luavalue_cast(index, d); f = d; return r; }
|
|
|
|
|
2012-01-06 21:42:28 +01:00
|
|
|
// int8
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(int8 v) { push_luavalue((int)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, int8& v) { int i; bool r = luavalue_cast(index, i); v = i; return r; }
|
|
|
|
// uint8
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(uint8 v) { push_luavalue((int)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, uint8& v){ int i; bool r = luavalue_cast(index, i); v = i; return r; }
|
|
|
|
// int16
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(int16 v) { push_luavalue((int)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, int16& v){ int i; bool r = luavalue_cast(index, i); v = i; return r; }
|
|
|
|
// uint16
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(uint16 v) { push_luavalue((int)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, uint16& v){ int i; bool r = luavalue_cast(index, i); v = i; return r; }
|
|
|
|
// uint32
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(uint32 v) { push_luavalue((double)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, uint32& v) { double d; bool r = luavalue_cast(index, d); v = d; return r; }
|
|
|
|
// int64
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(int64 v) { push_luavalue((double)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, int64& v) { double d; bool r = luavalue_cast(index, d); v = d; return r; }
|
|
|
|
// uint64
|
2012-07-05 14:38:48 +02:00
|
|
|
inline int push_luavalue(uint64 v) { push_luavalue((double)v); return 1; }
|
2012-01-06 21:42:28 +01:00
|
|
|
inline bool luavalue_cast(int index, uint64& v) { double d; bool r = luavalue_cast(index, d); v = d; return r; }
|
2011-08-20 22:30:41 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// string
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const char* cstr);
|
|
|
|
int push_luavalue(const std::string& str);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, std::string& str);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// lua cpp function
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const LuaCppFunction& func);
|
2011-08-19 20:53:23 +02:00
|
|
|
|
|
|
|
// color
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Color& color);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, Color& color);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// rect
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Rect& rect);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, Rect& rect);
|
|
|
|
|
|
|
|
// point
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Point& point);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, Point& point);
|
|
|
|
|
|
|
|
// size
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const Size& size);
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, Size& size);
|
|
|
|
|
|
|
|
// otml nodes
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const OTMLNodePtr& node);
|
2011-11-13 05:13:07 +01:00
|
|
|
bool luavalue_cast(int index, OTMLNodePtr& node);
|
2011-08-19 20:53:23 +02:00
|
|
|
|
|
|
|
// enum
|
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_enum<T>::value, bool>::type
|
|
|
|
luavalue_cast(int index, T& myenum);
|
|
|
|
|
|
|
|
// LuaObject pointers
|
2011-08-14 04:09:11 +02:00
|
|
|
template<class T>
|
2012-07-05 14:38:48 +02:00
|
|
|
typename std::enable_if<std::is_base_of<LuaObject, typename T::element_type>::value, int>::type
|
2011-08-19 20:53:23 +02:00
|
|
|
push_luavalue(const T& obj);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, LuaObjectPtr& obj);
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_base_of<LuaObject, T>::value, bool>::type
|
|
|
|
luavalue_cast(int index, std::shared_ptr<T>& ptr);
|
|
|
|
|
|
|
|
// std::function
|
2011-08-14 04:09:11 +02:00
|
|
|
template<typename Ret, typename... Args>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::function<Ret(Args...)>& func);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
template<typename... Args>
|
|
|
|
bool luavalue_cast(int index, std::function<void(Args...)>& func);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
template<typename Ret, typename... Args>
|
|
|
|
typename std::enable_if<!std::is_void<Ret>::value, bool>::type
|
|
|
|
luavalue_cast(int index, std::function<Ret(Args...)>& func);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
// vector
|
|
|
|
template<typename T>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::vector<T>& vec);
|
2011-08-26 20:00:22 +02:00
|
|
|
|
2012-01-15 16:13:22 +01:00
|
|
|
template<typename T>
|
|
|
|
bool luavalue_cast(int index, std::vector<T>& vec);
|
|
|
|
|
2011-09-02 06:21:18 +02:00
|
|
|
// deque
|
|
|
|
template<class T>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::deque<T>& vec);
|
2011-09-02 06:21:18 +02:00
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
template<typename T>
|
|
|
|
bool luavalue_cast(int index, std::deque<T>& vec);
|
|
|
|
|
2012-04-03 01:09:47 +02:00
|
|
|
// map
|
|
|
|
template<class K, class V>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::map<K, V>& map);
|
2012-04-03 01:09:47 +02:00
|
|
|
|
|
|
|
template<class K, class V>
|
|
|
|
bool luavalue_cast(int index, std::map<K, V>& map);
|
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
// tuple
|
|
|
|
template<typename... Args>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::tuple<Args...>& tuple);
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
int push_internal_luavalue(const std::tuple<Args...>& tuple);
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
// start definitions
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2011-08-19 20:53:23 +02:00
|
|
|
#include "luaexception.h"
|
|
|
|
#include "luainterface.h"
|
2011-08-14 04:09:11 +02:00
|
|
|
|
2012-07-05 14:38:48 +02:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
int push_internal_luavalue(T v) {
|
|
|
|
return push_luavalue(v);
|
|
|
|
}
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_enum<T>::value, bool>::type
|
2011-08-19 20:53:23 +02:00
|
|
|
luavalue_cast(int index, T& myenum) {
|
|
|
|
return luavalue_cast(index, (int&)myenum);
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2012-07-05 14:38:48 +02:00
|
|
|
typename std::enable_if<std::is_base_of<LuaObject, typename T::element_type>::value, int>::type
|
2011-08-19 20:53:23 +02:00
|
|
|
push_luavalue(const T& obj) {
|
|
|
|
if(obj)
|
2012-07-05 14:38:48 +02:00
|
|
|
g_lua.pushObject(obj);
|
|
|
|
else
|
|
|
|
g_lua.pushNil();
|
|
|
|
return 1;
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2011-08-19 20:53:23 +02:00
|
|
|
typename std::enable_if<std::is_base_of<LuaObject, T>::value, bool>::type
|
|
|
|
luavalue_cast(int index, std::shared_ptr<T>& ptr) {
|
2011-08-14 04:09:11 +02:00
|
|
|
LuaObjectPtr obj;
|
|
|
|
if(!luavalue_cast(index, obj))
|
|
|
|
return false;
|
2011-08-19 20:53:23 +02:00
|
|
|
ptr = std::dynamic_pointer_cast<T>(obj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Ret, typename... Args>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::function<Ret(Args...)>& func) {
|
2011-08-19 20:53:23 +02:00
|
|
|
if(func) {
|
|
|
|
LuaCppFunction f = luabinder::bind_fun(func);
|
|
|
|
g_lua.pushCppFunction(f);
|
|
|
|
} else
|
|
|
|
g_lua.pushNil();
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args>
|
2011-08-19 20:53:23 +02:00
|
|
|
bool luavalue_cast(int index, std::function<void(Args...)>& func) {
|
2011-08-14 04:09:11 +02:00
|
|
|
if(g_lua.isFunction(index)) {
|
|
|
|
g_lua.pushValue(index);
|
|
|
|
// weak references are used here, this means that the script must hold another reference
|
|
|
|
// to this function, otherwise it will expire
|
|
|
|
int funcWeakRef = g_lua.weakRef();
|
2011-10-29 01:56:45 +02:00
|
|
|
func = [=](Args... args) {
|
2011-08-14 04:09:11 +02:00
|
|
|
// note that we must catch exceptions, because this lambda can be called from anywhere
|
|
|
|
// and most of them won't catch exceptions (e.g. dispatcher)
|
|
|
|
g_lua.getWeakRef(funcWeakRef);
|
|
|
|
try {
|
|
|
|
if(g_lua.isFunction()) {
|
2012-07-05 14:38:48 +02:00
|
|
|
int numArgs = g_lua.polymorphicPush(args...);
|
|
|
|
int rets = g_lua.safeCall(numArgs);
|
2012-02-20 03:27:08 +01:00
|
|
|
g_lua.pop(rets);
|
2011-08-14 04:09:11 +02:00
|
|
|
} else {
|
|
|
|
throw LuaException("attempt to call an expired lua function from C++,"
|
|
|
|
"did you forget to hold a reference for that function?", 0);
|
|
|
|
}
|
2011-12-01 23:25:32 +01:00
|
|
|
} catch(LuaException& e) {
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.error(stdext::format("lua function callback failed: %s", e.what()));
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
} else if(g_lua.isNil(index)) {
|
2011-08-19 20:53:23 +02:00
|
|
|
func = std::function<void(Args...)>();
|
2011-08-14 04:09:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Ret, typename... Args>
|
|
|
|
typename std::enable_if<!std::is_void<Ret>::value, bool>::type
|
2011-08-19 20:53:23 +02:00
|
|
|
luavalue_cast(int index, std::function<Ret(Args...)>& func) {
|
2011-08-14 04:09:11 +02:00
|
|
|
if(g_lua.isFunction(index)) {
|
|
|
|
g_lua.pushValue(index);
|
|
|
|
// weak references are used here, this means that the script must hold another reference
|
|
|
|
// to this function, otherwise it will expire
|
|
|
|
int funcWeakRef = g_lua.weakRef();
|
2011-10-29 01:56:45 +02:00
|
|
|
func = [=](Args... args) -> Ret {
|
2011-08-14 04:09:11 +02:00
|
|
|
// note that we must catch exceptions, because this lambda can be called from anywhere
|
|
|
|
// and most of them won't catch exceptions (e.g. dispatcher)
|
|
|
|
try {
|
|
|
|
g_lua.getWeakRef(funcWeakRef);
|
|
|
|
if(g_lua.isFunction()) {
|
2012-07-05 14:38:48 +02:00
|
|
|
int numArgs = g_lua.polymorphicPush(args...);
|
|
|
|
if(g_lua.safeCall(numArgs) != 1)
|
2011-08-14 04:09:11 +02:00
|
|
|
throw LuaException("a function from lua didn't retrieve the expected number of results", 0);
|
|
|
|
return g_lua.polymorphicPop<Ret>();
|
|
|
|
} else {
|
|
|
|
throw LuaException("attempt to call an expired lua function from C++,"
|
|
|
|
"did you forget to hold a reference for that function?", 0);
|
|
|
|
}
|
2011-12-01 23:25:32 +01:00
|
|
|
} catch(LuaException& e) {
|
2012-06-01 22:39:23 +02:00
|
|
|
g_logger.error(stdext::format("lua function callback failed: %s", e.what()));
|
2011-08-14 04:09:11 +02:00
|
|
|
}
|
|
|
|
return Ret();
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
} else if(g_lua.isNil(index)) {
|
2011-08-19 20:53:23 +02:00
|
|
|
func = std::function<Ret(Args...)>();
|
2011-08-14 04:09:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
|
|
|
|
template<typename T>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::vector<T>& vec) {
|
2011-08-26 20:00:22 +02:00
|
|
|
g_lua.newTable();
|
|
|
|
int i = 1;
|
|
|
|
for(const T& v : vec) {
|
2012-07-05 14:38:48 +02:00
|
|
|
push_internal_luavalue(v);
|
2011-08-26 20:00:22 +02:00
|
|
|
g_lua.rawSeti(i);
|
|
|
|
i++;
|
|
|
|
}
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2011-08-26 20:00:22 +02:00
|
|
|
}
|
|
|
|
|
2012-01-15 16:13:22 +01:00
|
|
|
template<typename T>
|
|
|
|
bool luavalue_cast(int index, std::vector<T>& vec)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.pushNil();
|
|
|
|
while(g_lua.next(index < 0 ? index-1 : index)) {
|
|
|
|
T value;
|
|
|
|
if(luavalue_cast(-1, value))
|
|
|
|
vec.push_back(value);
|
|
|
|
g_lua.pop();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-02 06:21:18 +02:00
|
|
|
template<typename T>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::deque<T>& vec) {
|
2011-09-02 06:21:18 +02:00
|
|
|
g_lua.newTable();
|
|
|
|
int i = 1;
|
|
|
|
for(const T& v : vec) {
|
2012-07-05 14:38:48 +02:00
|
|
|
push_internal_luavalue(v);
|
2011-09-02 06:21:18 +02:00
|
|
|
g_lua.rawSeti(i);
|
|
|
|
i++;
|
|
|
|
}
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2011-09-02 06:21:18 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
template<typename T>
|
|
|
|
bool luavalue_cast(int index, std::deque<T>& vec)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.pushNil();
|
|
|
|
while(g_lua.next(index < 0 ? index-1 : index)) {
|
|
|
|
T value;
|
|
|
|
if(luavalue_cast(-1, value))
|
|
|
|
vec.push_back(value);
|
|
|
|
g_lua.pop();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 01:09:47 +02:00
|
|
|
template<class K, class V>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::map<K, V>& map)
|
2012-04-03 01:09:47 +02:00
|
|
|
{
|
|
|
|
g_lua.newTable();
|
|
|
|
for(auto& it : map) {
|
2012-07-05 14:38:48 +02:00
|
|
|
push_internal_luavalue(it.first);
|
|
|
|
push_internal_luavalue(it.second);
|
2012-04-03 01:09:47 +02:00
|
|
|
g_lua.rawSet();
|
|
|
|
}
|
2012-07-05 14:38:48 +02:00
|
|
|
return 1;
|
2012-04-03 01:09:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class K, class V>
|
|
|
|
bool luavalue_cast(int index, std::map<K, V>& map)
|
|
|
|
{
|
|
|
|
if(g_lua.isTable(index)) {
|
|
|
|
g_lua.pushNil();
|
|
|
|
while(g_lua.next(index < 0 ? index-1 : index)) {
|
|
|
|
K key;
|
|
|
|
V value;
|
|
|
|
if(luavalue_cast(-1, value) && luavalue_cast(-2, key))
|
|
|
|
map[key] = value;
|
|
|
|
g_lua.pop();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-05 14:38:48 +02:00
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
template<int N>
|
2012-07-05 14:38:48 +02:00
|
|
|
struct push_tuple_internal_luavalue {
|
2011-08-26 20:00:22 +02:00
|
|
|
template<typename Tuple>
|
|
|
|
static void call(const Tuple& tuple) {
|
2012-07-05 14:38:48 +02:00
|
|
|
push_internal_luavalue(std::get<N-1>(tuple));
|
2011-08-26 20:00:22 +02:00
|
|
|
g_lua.rawSeti(N);
|
2012-07-05 14:38:48 +02:00
|
|
|
push_tuple_internal_luavalue<N-1>::call(tuple);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct push_tuple_internal_luavalue<0> {
|
|
|
|
template<typename Tuple>
|
|
|
|
static void call(const Tuple& tuple) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
int push_internal_luavalue(const std::tuple<Args...>& tuple) {
|
|
|
|
g_lua.newTable();
|
|
|
|
push_tuple_internal_luavalue<sizeof...(Args)>::call(tuple);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
struct push_tuple_luavalue {
|
|
|
|
template<typename Tuple>
|
|
|
|
static void call(const Tuple& tuple) {
|
|
|
|
push_internal_luavalue(std::get<std::tuple_size<Tuple>::value - N>(tuple));
|
2011-08-26 20:00:22 +02:00
|
|
|
push_tuple_luavalue<N-1>::call(tuple);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct push_tuple_luavalue<0> {
|
|
|
|
template<typename Tuple>
|
|
|
|
static void call(const Tuple& tuple) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename... Args>
|
2012-07-05 14:38:48 +02:00
|
|
|
int push_luavalue(const std::tuple<Args...>& tuple) {
|
2011-08-26 20:00:22 +02:00
|
|
|
push_tuple_luavalue<sizeof...(Args)>::call(tuple);
|
2012-07-05 14:38:48 +02:00
|
|
|
return sizeof...(Args);
|
2011-08-26 20:00:22 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#endif
|