From f7043fc0cb8bcb5b7cc2eedb8214e3d54fce2f79 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Sun, 30 Dec 2018 23:36:53 +0100 Subject: [PATCH] added camera implementation and plenty of other rendering related stuff - splitted out the initialization of the render context --- share/doc/pixwerx.xmind | Bin 58468 -> 114739 bytes src/CMakeLists.txt | 7 +- src/core/CMakeLists.txt | 1 + src/core/include/pw/core/globals.hpp | 3 + src/core/include/pw/core/image.hpp | 3 +- src/core/include/pw/core/matrix.hpp | 647 +- src/core/include/pw/core/size.hpp | 50 + src/deps/sol/sol.hpp | 14494 ---------- src/deps/sol2-2.20.6/sol/sol.hpp | 22180 ++++++++++++++++ src/engine/CMakeLists.txt | 2 +- src/scene/CMakeLists.txt | 4 +- src/scene/include/pw/scene/camera.hpp | 48 + src/scene/include/pw/scene/component.hpp | 6 +- src/scene/include/pw/scene/node.hpp | 77 +- src/scene/include/pw/scene/transform.hpp | 4 +- src/scene/include/pw/scene/traverser.hpp | 29 +- src/scene/src/camera.cpp | 25 + src/scene/src/component.cpp | 31 +- src/scene/src/node.cpp | 84 +- src/scene/src/transform.cpp | 4 +- src/scene/src/traverser.cpp | 56 +- src/scene/tests/pwscene_test_node.cpp | 4 +- src/scene/tests/pwscene_test_traverser.cpp | 29 +- src/scripting/CMakeLists.txt | 19 +- .../include/pw/scripting/scripting.hpp | 2 +- src/scripting/src/script.cpp | 89 +- src/scripting/src/script_core.cpp | 59 + src/scripting/src/script_core.hpp | 17 + src/scripting/src/script_scene.cpp | 23 + src/scripting/src/script_scene.hpp | 17 + src/scripting/src/script_system.cpp | 16 + src/scripting/src/script_system.hpp | 17 + src/scripts/demos/simple_000.lua | 6 +- src/system/CMakeLists.txt | 24 + src/system/include/pw/system/window.hpp | 33 + src/system/src/window.cpp | 143 + src/ui/include/pw/ui/window.hpp | 43 - src/ui/src/window.cpp | 66 - src/visual/CMakeLists.txt | 26 + src/visual/include/pw/visual/context.hpp | 25 + src/visual/include/pw/visual/renderer.hpp | 19 + src/visual/src/context.cpp | 0 src/visual/src/renderer.cpp | 9 + 43 files changed, 23280 insertions(+), 15161 deletions(-) create mode 100644 src/core/include/pw/core/size.hpp delete mode 100644 src/deps/sol/sol.hpp create mode 100644 src/deps/sol2-2.20.6/sol/sol.hpp create mode 100644 src/scene/include/pw/scene/camera.hpp create mode 100644 src/scene/src/camera.cpp create mode 100644 src/scripting/src/script_core.cpp create mode 100644 src/scripting/src/script_core.hpp create mode 100644 src/scripting/src/script_scene.cpp create mode 100644 src/scripting/src/script_scene.hpp create mode 100644 src/scripting/src/script_system.cpp create mode 100644 src/scripting/src/script_system.hpp create mode 100644 src/system/CMakeLists.txt create mode 100644 src/system/include/pw/system/window.hpp create mode 100644 src/system/src/window.cpp delete mode 100644 src/ui/include/pw/ui/window.hpp delete mode 100644 src/ui/src/window.cpp create mode 100644 src/visual/CMakeLists.txt create mode 100644 src/visual/include/pw/visual/context.hpp create mode 100644 src/visual/include/pw/visual/renderer.hpp create mode 100644 src/visual/src/context.cpp create mode 100644 src/visual/src/renderer.cpp diff --git a/share/doc/pixwerx.xmind b/share/doc/pixwerx.xmind index 34f14389870ed34bc5cb09311279d363aad26d6b..439924713697a23ac5eea7c386a82ab93e6e54f6 100644 GIT binary patch literal 114739 zcmeEv2|N^9`~PTHp_EpYE!r^qBFn9$EGcV6mNA$>N93LbIxhSxl0i3X`Q`psy>cLkawn$yW+WghJdfDEq1rYKyp(#7l7#As&u8msYrDIIy#pd2ipgJ)4W6y8r8aV0UpqCsFuST2)IL(+t<2n>r2K=exN=aTqk3!X!{xKWmxC=L!gX0hgpnpyPR9 znSyx%i~`nymVl}SW?W0abivc{Oah7cJrQUu3W3F7L<^Qr<cIR7N zf-99y`Oe_g-eDC$V|KooIvNZ@mwJS&S25WWc<&F z|7uL&a0~*6f+ArUL=QOx7MJw*Xn|spcpjTZ#|U^FJe=>wXCvWsDBhJba9WUX7!C^S zp#?CwYY#2j;^FAqdjyfdMl+~Fii;b?O+a9x2uwT~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=~=Q~18+n>5_4duY!#%ro7;hjWs_A(md zra2Z3wZ7^ah)(Xa@Kz_|#8D~f=psIb+TJ>)Qdq65H>Y(_9~B)%m|`+})T7x+TR8== zfIQ+5j_rAS{%B_*=3*N980#-#M7O3(LkAy9spP_ZIfLdlpXF$cdye$v6^s-QPpPg$ zRxT#*G@3 z!|`_7!t2y21&3#E(CJ$I%ukKpu6K}eiY2S@&&p(slB-6n*{8_4@i4QED8(Ll$tSEKyTVMWR|L7e2{Y49J*RobYOnSsRC=Tn1_Yk)dBKMzQSk)!_^{m z?L71-t}HiXRk)%^->v)WTun=cFYz#s6Jz*3DQ0Mt(XcY@9Ube2;Vn=S76BaG$EZvNndJJe*)V5jnJpQ8nx5U1la3A#?&~8 zu<3zr$Ni6AJH{RjrxdmZ?h*LaLTfC9Rz)-)@d@Lsz%KKibfE2HIu0iG{!8G8e*m1? z`~JUwfc`Vh{I{(@|Kaiedq)8O?f*s38~mc=w+UQH;zt3cFq7t0J++)Gw;wPF*A=QU z)%+GrOh-ZaE8#k$=AVDum?Q6)d3Ou#{jyqk?j3XZu2}YDuELK*=JZ{dmO|#i<5`ce zc#*w;9sm>rZRTA^nEuH`&!C*gv=lK*b1>-O|4A8-VJ~Ku_({QzQ7UHUgLfTbV)FFz zN7{Kx`=OBkF6CdD;m`lsub=<9kH>yV5@+;-P4eIGI%v|6pR$LE2@A@_zueU!3ht7K zO*zMfks>p*A7}K4kr`=I-&dA%>la2@T3$YZ|NmlnY4fG2emQ9UX0y zfflbD{Je6%lIy<=wKD4Kv=!jtHwERd;@(*OY#4Cd3-5?(DF>pEsGp)<(77<;6~8+F zudCrFoBTgi2G}VoE0{%3GSu|1lg<5)8jKJ7s7y>4nfJ`x7{N;BeH #include +#include namespace pw { using std::shared_ptr; +typedef float real_t; + } #endif diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index 0dba463..dbd64f9 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -2,11 +2,10 @@ #define PW_CORE_IMAGE_HPP #include -#include namespace pw { -class image : public referenced { +class image { }; diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 8f79039..dc0de20 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -37,95 +37,95 @@ namespace pw { template class matrix : public matrixbase { - T m[R*C]; + T m[R*C]; public: - using typename matrixbase::value_type; - using typename matrixbase::size_type; + using typename matrixbase::value_type; + using typename matrixbase::size_type; - matrix(); + matrix(); - matrix(const matrix& mtc); + matrix(const matrix& mtc); - matrix& operator = (const matrix& other); + matrix& operator = (const matrix& other); - matrix transposed() const; + matrix transposed() const; - inline matrix& operator *= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) *= b; return *this; } - inline matrix& operator /= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) /= b; return *this; } - inline matrix& operator += (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += b; return *this; } - inline matrix& operator -= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= b; return *this; } + inline matrix& operator *= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) *= b; return *this; } + inline matrix& operator /= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) /= b; return *this; } + inline matrix& operator += (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += b; return *this; } + inline matrix& operator -= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= b; return *this; } - inline matrix& operator += (const matrix& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += other.at(i); return *this; } - inline matrix& operator -= (const matrix& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= other.at(i); return *this; } + inline matrix& operator += (const matrix& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += other.at(i); return *this; } + inline matrix& operator -= (const matrix& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= other.at(i); return *this; } - inline const matrix normalized() const { - const T one_over_n = T(1) / this->norm(); - return *this * one_over_n; - } + inline const matrix normalized() const { + const T one_over_n = T(1) / this->norm(); + return *this * one_over_n; + } - inline const matrix - get_inverse() const - { - matrix resMat; + inline const matrix + get_inverse() const + { + matrix resMat; - for ( unsigned int r = 0; r < C; ++r) { - for ( unsigned int j = 0; j < R; ++j) { - short sgn = ( (r+j)%2) ? -1 : 1; - matrix minor; - this->get_minor(minor,r,j); - resMat.at(r,j) = minor.determinant() * sgn; - } - } + for ( unsigned int r = 0; r < C; ++r) { + for ( unsigned int j = 0; j < R; ++j) { + short sgn = ( (r+j)%2) ? -1 : 1; + matrix minor; + this->get_minor(minor,r,j); + resMat.at(r,j) = minor.determinant() * sgn; + } + } - resMat = resMat.transposed(); - resMat *= (static_cast(1)/this->determinant()); - return resMat; - } + resMat = resMat.transposed(); + resMat *= (static_cast(1)/this->determinant()); + return resMat; + } - inline - matrix& invert() { - *this = this->get_inverse(); - return *this; - } + inline + matrix& invert() { + *this = this->get_inverse(); + return *this; + } - void get_minor(matrix& res, unsigned int r0, unsigned int c0) const; + void get_minor(matrix& res, unsigned int r0, unsigned int c0) const; - T determinant() const; + T determinant() const; - T squared_norm() const; + T squared_norm() const; - T norm() const; + T norm() const; - matrix& operator *= (const matrix& rhs); + matrix& operator *= (const matrix& rhs); - matrix& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; } + matrix& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; } - matrix operator * (const matrix& rhs) const { - return mul(*this,rhs); - } + matrix operator * (const matrix& rhs) const { + return mul(*this,rhs); + } - const matrix reshape() const { - matrix m; - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - m(r,c) = (*this)(c,r); - return m; - } + const matrix reshape() const { + matrix m; + for (unsigned int r = 0; r < R; ++r) + for (unsigned int c = 0; c < C; ++c) + m(r,c) = (*this)(c,r); + return m; + } - const matrix get_column(unsigned int col) const { - matrix c; for (unsigned int r = 0; r < R; ++r) c(r,0) = (this)(r,col); - return c; - } + const matrix get_column(unsigned int col) const { + matrix c; for (unsigned int r = 0; r < R; ++r) c(r,0) = (this)(r,col); + return c; + } - const matrix<1,C,T> get_row(unsigned int row) const { - matrix<1,C,T> r; for (unsigned int c = 0; c < C; ++c) r(0,c) = (this)(row,c); - return r; - } + const matrix<1,C,T> get_row(unsigned int row) const { + matrix<1,C,T> r; for (unsigned int c = 0; c < C; ++c) r(0,c) = (this)(row,c); + return r; + } - void normalize(); + void normalize(); }; ///////////////////////////////////////////////////////////////////////////// @@ -133,49 +133,49 @@ public: template inline matrix operator * (const matrix& a, const T& b) { - matrix res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * b; - return res; + matrix res; + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * b; + return res; } template inline matrix operator / (const matrix& a, const T& b) { - matrix res; T oneOverB(1./b); - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * oneOverB; - return res; + matrix res; T oneOverB(1./b); + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * oneOverB; + return res; } template inline matrix operator + (const matrix& a, const T& b) { - matrix res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b; - return res; + matrix res; + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b; + return res; } template inline matrix operator - (const matrix& a, const T& b) { - matrix res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b; - return res; + matrix res; + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b; + return res; } template inline matrix operator + (const matrix& a, const matrix& b) { - matrix res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b.at(i); - return res; + matrix res; + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b.at(i); + return res; } template inline matrix operator - (const matrix& a, const matrix& b) { - matrix res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b.at(i); - return res; + matrix res; + for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b.at(i); + return res; } ///////////////////////////////////////////////////////////////////////////// @@ -184,21 +184,21 @@ template matrix static inline mul(const matrix& A, const matrix& B) { - // aC == bR - // set all null - matrix res; - res.fill(0); + // aC == bR + // set all null + matrix res; + res.fill(0); - // compute all resulting cells - for (unsigned int r = 0; r < aR; ++r) { - for (unsigned int c = 0; c < bC; ++c) { - // building inner product - for (unsigned int iI = 0; iI < aCbR;iI++) { - res.at(r,c) += A.at(r,iI) * B.at(iI,c); - } - } - } - return res; + // compute all resulting cells + for (unsigned int r = 0; r < aR; ++r) { + for (unsigned int c = 0; c < bC; ++c) { + // building inner product + for (unsigned int iI = 0; iI < aCbR;iI++) { + res.at(r,c) += A.at(r,iI) * B.at(iI,c); + } + } + } + return res; } @@ -208,108 +208,108 @@ mul(const matrix& A, const matrix& B) template matrix& matrix::operator *= (const matrix& rhs) { - *this = mul(*this,rhs); - return *this; + *this = mul(*this,rhs); + return *this; } ///////////////////////////////////////////////////////////////////////////// template matrix::matrix() - : matrixbase(R,C,&m[0],true) + : matrixbase(R,C,&m[0],true) { } template matrix::matrix(const matrix &mtc) : - matrixbase(R,C,&m[0],true) + matrixbase(R,C,&m[0],true) { - *this = mtc; + *this = mtc; } template matrix &matrix::operator = (const matrix &other) { - if (this != &other) - for (unsigned int r = 0; r < R;++r) - for (unsigned int c = 0; c < C;++c) - (*this).at(r,c) = other.at(r,c); - return *this; + if (this != &other) + for (unsigned int r = 0; r < R;++r) + for (unsigned int c = 0; c < C;++c) + (*this).at(r,c) = other.at(r,c); + return *this; } template matrix matrix::transposed() const { - matrix res; - for (unsigned int r = this->rows();r-->0;) - for (unsigned int c = this->cols();c-->0;) - res.at(c,r) = this->at(r,c); - return res; + matrix res; + for (unsigned int r = this->rows();r-->0;) + for (unsigned int c = this->cols();c-->0;) + res.at(c,r) = this->at(r,c); + return res; } template void matrix::get_minor(matrix& res,unsigned int r0, unsigned int c0) const { - unsigned int r = 0; - for (unsigned int ri = 0; ri < R; ri++) - { - unsigned int c = 0; - if (ri == r0) continue; - for (unsigned int ci = 0; ci < C; ci++) - { - if (ci == c0) continue; - res.data()[r*(C-1)+c] = this->data()[ri*C + ci];//(*this)(ri,ci); - c++; - } - r++; - } + unsigned int r = 0; + for (unsigned int ri = 0; ri < R; ri++) + { + unsigned int c = 0; + if (ri == r0) continue; + for (unsigned int ci = 0; ci < C; ci++) + { + if (ci == c0) continue; + res.data()[r*(C-1)+c] = this->data()[ri*C + ci];//(*this)(ri,ci); + c++; + } + r++; + } } template inline T matrix::determinant() const { - T res(0); + T res(0); - matrix minor; + matrix minor; - // using Laplace Expansion at compile time - for (unsigned int c = 0; c < C; c++) { - this->get_minor(minor,0,c); - res += ((c % 2 == 0) ? m[c] : -m[c]) * minor.determinant(); - } + // using Laplace Expansion at compile time + for (unsigned int c = 0; c < C; c++) { + this->get_minor(minor,0,c); + res += ((c % 2 == 0) ? m[c] : -m[c]) * minor.determinant(); + } - return res; + return res; } template inline T matrix::squared_norm() const { - T res(0); + T res(0); - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - res += ((*this).at(r,c) * (*this).at(r,c)); - return res; + for (unsigned int r = 0; r < R; ++r) + for (unsigned int c = 0; c < C; ++c) + res += ((*this).at(r,c) * (*this).at(r,c)); + return res; } template inline T matrix::norm() const { - using std::sqrt; + using std::sqrt; - return sqrt(this->squared_norm()); + return sqrt(this->squared_norm()); } template inline void matrix::normalize() { - T n = norm(); - if (n > 0) { - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - (*this)(r,c) /= n; - } + T n = norm(); + if (n > 0) { + for (unsigned int r = 0; r < R; ++r) + for (unsigned int c = 0; c < C; ++c) + (*this)(r,c) /= n; + } } ///////////////////////////////////////////////////////////////////////////// @@ -323,143 +323,166 @@ class matrix44 : public matrix<4,4,T> { public: - using matrix<4,4,T>::matrix; + using matrix<4,4,T>::matrix; - matrix44(const matrix<4,4,T>& i) - { - *this = i; - } + matrix44(const matrix<4,4,T>& i) + { + *this = i; + } - matrix44& operator = (const matrix<4,4,T>& rhs) { - if (this != &rhs){ - this->at(0,0) = rhs.at(0,0);this->at(0,1) = rhs.at(0,1);this->at(0,2) = rhs.at(0,2);this->at(0,3) = rhs.at(0,3); - this->at(1,0) = rhs.at(1,0);this->at(1,1) = rhs.at(1,1);this->at(1,2) = rhs.at(1,2);this->at(1,3) = rhs.at(1,3); - this->at(2,0) = rhs.at(2,0);this->at(2,1) = rhs.at(2,1);this->at(2,2) = rhs.at(2,2);this->at(2,3) = rhs.at(2,3); - this->at(3,0) = rhs.at(3,0);this->at(3,1) = rhs.at(3,1);this->at(3,2) = rhs.at(3,2);this->at(3,3) = rhs.at(3,3); - } + matrix44& operator = (const matrix<4,4,T>& rhs) { + if (this != &rhs){ + this->at(0,0) = rhs.at(0,0);this->at(0,1) = rhs.at(0,1);this->at(0,2) = rhs.at(0,2);this->at(0,3) = rhs.at(0,3); + this->at(1,0) = rhs.at(1,0);this->at(1,1) = rhs.at(1,1);this->at(1,2) = rhs.at(1,2);this->at(1,3) = rhs.at(1,3); + this->at(2,0) = rhs.at(2,0);this->at(2,1) = rhs.at(2,1);this->at(2,2) = rhs.at(2,2);this->at(2,3) = rhs.at(2,3); + this->at(3,0) = rhs.at(3,0);this->at(3,1) = rhs.at(3,1);this->at(3,2) = rhs.at(3,2);this->at(3,3) = rhs.at(3,3); + } - return *this; - } + return *this; + } + + inline static + matrix<4,4,T> projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) + { + matrix<4,4,T> frustum; + + frustum.fill(0); + + frustum.at(0,0) = 2 * zNear/(Right-Left); + frustum.at(1,1) = 2 * zNear/(Top-Bottom); + + frustum.at(0,2) = (Right+Left)/(Right-Left); //A + frustum.at(1,2) = (Top+Bottom)/(Top-Bottom); //B + frustum.at(2,2) = - (zFar+zNear)/(zFar-zNear); //C + frustum.at(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D + + frustum.at(2,3) = -1; + + return frustum; + } + + inline static + matrix<4,4,T> orthogonal_projection(T Left, T Right, + T Bottom,T Top, + T Near, T Far) + { + + matrix<4,4,T> ortho; + + ortho.fill(0); + ortho(0,0) = 2 / (Right-Left); + ortho(1,1) = 2 / (Top-Bottom); + ortho(2,2) = -2 / (Far-Near); + + ortho(0,3) = -(Right+Left)/(Right-Left); + ortho(1,3) = -(Top+Bottom)/(Top-Bottom); + ortho(2,3) = -(Far+Near)/(Far-Near); + + ortho(3,3) = 1; + + return ortho; + } + + + inline static + matrix<4,4,T> perspective_projection(T fovY, T aspectRatio, T zNear, T zFar) + { + const T height = zNear * tan(fovY/T(360) * pi()); // half height of near plane + const T width = height * aspectRatio; // half width of near plane + + return projection_from_frustum(-width, width, -height, height, zNear, zFar ); + } #if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE - matrix<4,4,T>& - translate(const T& v1,const T& v2,const T& v3) - { - this->at(12) += v1; - this->at(13) += v2; - this->at(14) += v3; - return *this; - } + matrix<4,4,T>& + translate(const T& v1,const T& v2,const T& v3) + { + this->at(12) += v1; + this->at(13) += v2; + this->at(14) += v3; + return *this; + } - matrix<4,4,T>& - setTranslation(const T& v1,const T& v2,const T& v3) - { - this->identity(); - this->at(12) = v1; - this->at(13) = v2; - this->at(14) = v3; - return *this; - } + matrix<4,4,T>& + setTranslation(const T& v1,const T& v2,const T& v3) + { + this->identity(); + this->at(12) = v1; + this->at(13) = v2; + this->at(14) = v3; + return *this; + } - matrix<4,4,T>& - setScale(const T& v1,const T& v2,const T& v3) - { - this->identity(); - (*this)(0,0) = v1; - (*this)(1,1) = v2; - (*this)(2,2) = v3; - return *this; - } + matrix<4,4,T>& + setScale(const T& v1,const T& v2,const T& v3) + { + this->identity(); + (*this)(0,0) = v1; + (*this)(1,1) = v2; + (*this)(2,2) = v3; + return *this; + } - matrix<4,4,T>& - scale(const T& v1,const T& v2,const T& v3) - { - (*this)(0,0) *= v1; - (*this)(1,1) *= v2; - (*this)(2,2) *= v3; - return *this; - } + matrix<4,4,T>& + scale(const T& v1,const T& v2,const T& v3) + { + (*this)(0,0) *= v1; + (*this)(1,1) *= v2; + (*this)(2,2) *= v3; + return *this; + } - static - matrix<4,4,T> - Translation(const T& v1,const T& v2,const T& v3) - { - matrix44 res = matrix44::Identity(); res.setTranslation(v1,v2,v3); - return res; - } + static + matrix<4,4,T> + Translation(const T& v1,const T& v2,const T& v3) + { + matrix44 res = matrix44::Identity(); res.setTranslation(v1,v2,v3); + return res; + } - inline static - matrix<4,4,T> - AngleAxis(const T& radianRotation,const matrix<3,1,T>& vec); - - inline static - matrix<4,4,T> OrthogonalProjection(T Left, T Right, - T Bottom,T Top, - T Near, T Far) - { - - matrix<4,4,T> ortho; - - ortho.fill(0); - ortho(0,0) = 2 / (Right-Left); - ortho(1,1) = 2 / (Top-Bottom); - ortho(2,2) = -2 / (Far-Near); - - ortho(0,3) = -(Right+Left)/(Right-Left); - ortho(1,3) = -(Top+Bottom)/(Top-Bottom); - ortho(2,3) = -(Far+Near)/(Far-Near); - - ortho(3,3) = 1; - - return ortho; - } - - inline static - matrix<4,4,T> Frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) - { - matrix<4,4,T> frustum; - - frustum.fill(0); - - frustum(0,0) = 2 * zNear/(Right-Left); - frustum(1,1) = 2 * zNear/(Top-Bottom); - - frustum(0,2) = (Right+Left)/(Right-Left); //A - frustum(1,2) = (Top+Bottom)/(Top-Bottom); //B - frustum(2,2) = - (zFar+zNear)/(zFar-zNear); //C - frustum(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D - - frustum(2,3) = -1; - - return frustum; - } + inline static + matrix<4,4,T> + AngleAxis(const T& radianRotation,const matrix<3,1,T>& vec); - inline static - matrix<4,4,T> PerspectiveProjection(T fovY, T aspectRatio, T zNear, T zFar) - { - T height = zNear * tan(fovY/T(360) * Pi); // half height of near plane - T width = height * aspectRatio; // half width of near plane - return Frustum(-width, width, -height, height, zNear, zFar ); - } + inline static + matrix<4,4,T> Frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) + { + matrix<4,4,T> frustum; - inline static - matrix<4,4,T> LookAt(const matrix<3,1,T>& eye, - const matrix<3,1,T>& target, - const matrix<3,1,T>& up); + frustum.fill(0); + + frustum(0,0) = 2 * zNear/(Right-Left); + frustum(1,1) = 2 * zNear/(Top-Bottom); + + frustum(0,2) = (Right+Left)/(Right-Left); //A + frustum(1,2) = (Top+Bottom)/(Top-Bottom); //B + frustum(2,2) = - (zFar+zNear)/(zFar-zNear); //C + frustum(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D + + frustum(2,3) = -1; + + return frustum; + } - matrix<4,4,T>& - rotate(const matrix<3,1,T>& vec, const T& rotation) - { - matrix44 rot = matrix44::AngleAxis(rotation,vec); *this *= rot; - return *this; - } + inline static + matrix<4,4,T> LookAt(const matrix<3,1,T>& eye, + const matrix<3,1,T>& target, + const matrix<3,1,T>& up); + + + matrix<4,4,T>& + rotate(const matrix<3,1,T>& vec, const T& rotation) + { + matrix44 rot = matrix44::AngleAxis(rotation,vec); *this *= rot; + return *this; + } #endif @@ -475,13 +498,13 @@ public: template <> inline float matrix<1,1,float>::determinant() const { - return this->at(0); + return this->at(0); } template <> inline double matrix<1,1,double>::determinant() const { - return this->at(0); + return this->at(0); } @@ -491,83 +514,83 @@ template class matrix31 : public matrix<3,1,T> { public: - using matrix<3,1,T>::operator =; + using matrix<3,1,T>::operator =; - inline static - matrix<3,1,T> Cross(const matrix<3,1,T>& vec1, const matrix<3,1,T>& vec2) - { - matrix<3,1,T> res; + inline static + matrix<3,1,T> Cross(const matrix<3,1,T>& vec1, const matrix<3,1,T>& vec2) + { + matrix<3,1,T> res; - res.at(0) = vec1.at(1) * vec2.at(2) - vec2.at(1) * vec1.at(2); - res.at(1) = vec1.at(2) * vec2.at(0) - vec2.at(2) * vec1.at(0); - res.at(2) = vec1.at(0) * vec2.at(1) - vec2.at(0) * vec1.at(1); + res.at(0) = vec1.at(1) * vec2.at(2) - vec2.at(1) * vec1.at(2); + res.at(1) = vec1.at(2) * vec2.at(0) - vec2.at(2) * vec1.at(0); + res.at(2) = vec1.at(0) * vec2.at(1) - vec2.at(0) * vec1.at(1); - return res; - } + return res; + } }; template matrix<4,4,T> matrix44::AngleAxis(const T &radianRotation, const matrix<3,1,T> &vec) { - matrix44 R = matrix44::Identity(); + matrix44 R = matrix44::Identity(); - if (vec.norm() < std::numeric_limits::epsilon()) return R; + if (vec.norm() < std::numeric_limits::epsilon()) return R; - T _fCos = (T) cos (radianRotation); + T _fCos = (T) cos (radianRotation); - matrix<3,1,T> _vCos(vec * (1 - _fCos)); - matrix<3,1,T> _vSin(vec * (T)sin(radianRotation)); + matrix<3,1,T> _vCos(vec * (1 - _fCos)); + matrix<3,1,T> _vSin(vec * (T)sin(radianRotation)); - R.at(0) = (T) ((vec(0,0) * _vCos(0,0)) + _fCos); - R.at(4) = (T) ((vec(0,0) * _vCos(1,0)) - _vSin(2,0)); - R.at(8) = (T) ((vec(0,0) * _vCos(2,0)) + _vSin(1,0)); + R.at(0) = (T) ((vec(0,0) * _vCos(0,0)) + _fCos); + R.at(4) = (T) ((vec(0,0) * _vCos(1,0)) - _vSin(2,0)); + R.at(8) = (T) ((vec(0,0) * _vCos(2,0)) + _vSin(1,0)); - R.at(1) = (T) ((vec(1,0) * _vCos(0,0)) + _vSin(2,0)); - R.at(5) = (T) ((vec(1,0) * _vCos(1,0)) + _fCos); - R.at(9) = (T) ((vec(1,0) * _vCos(2,0)) - _vSin(0,0)); + R.at(1) = (T) ((vec(1,0) * _vCos(0,0)) + _vSin(2,0)); + R.at(5) = (T) ((vec(1,0) * _vCos(1,0)) + _fCos); + R.at(9) = (T) ((vec(1,0) * _vCos(2,0)) - _vSin(0,0)); - R.at(2) = (T) ((vec(2,0) * _vCos(0,0)) - _vSin(1,0)); - R.at(6) = (T) ((vec(2,0) * _vCos(1,0)) + _vSin(0,0)); - R.at(10)= (T) ((vec(2,0) * _vCos(2,0)) + _fCos); + R.at(2) = (T) ((vec(2,0) * _vCos(0,0)) - _vSin(1,0)); + R.at(6) = (T) ((vec(2,0) * _vCos(1,0)) + _vSin(0,0)); + R.at(10)= (T) ((vec(2,0) * _vCos(2,0)) + _fCos); - return R; + return R; } template matrix<4,4,T> matrix44::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const matrix<3,1,T> &up) { - matrix<4,4,T> lookat = matrix<4,4,T>::Identity(); + matrix<4,4,T> lookat = matrix<4,4,T>::Identity(); - matrix<3,1,T> L; L = target - eye; - L.normalize(); - matrix<3,1,T> S = matrix31::Cross(L,up); - S.normalize(); - matrix<3,1,T> Ud = matrix31::Cross(S,L); - Ud.normalize(); + matrix<3,1,T> L; L = target - eye; + L.normalize(); + matrix<3,1,T> S = matrix31::Cross(L,up); + S.normalize(); + matrix<3,1,T> Ud = matrix31::Cross(S,L); + Ud.normalize(); - lookat(0,0) = S.at(0); - lookat(0,1) = S.at(1); - lookat(0,2) = S.at(2); - lookat(0,3) = T(0); + lookat(0,0) = S.at(0); + lookat(0,1) = S.at(1); + lookat(0,2) = S.at(2); + lookat(0,3) = T(0); - lookat(1,0) = Ud.at(0); - lookat(1,1) = Ud.at(1); - lookat(1,2) = Ud.at(2); - lookat(1,3) = T(0); + lookat(1,0) = Ud.at(0); + lookat(1,1) = Ud.at(1); + lookat(1,2) = Ud.at(2); + lookat(1,3) = T(0); - lookat(2,0) = -L.at(0); - lookat(2,1) = -L.at(1); - lookat(2,2) = -L.at(2); - lookat(3,2) = T(0); + lookat(2,0) = -L.at(0); + lookat(2,1) = -L.at(1); + lookat(2,2) = -L.at(2); + lookat(3,2) = T(0); - lookat(3,0) = eye.at(0); - lookat(3,1) = eye.at(1); - lookat(3,2) = eye.at(2); - lookat(3,3) = 1; + lookat(3,0) = eye.at(0); + lookat(3,1) = eye.at(1); + lookat(3,2) = eye.at(2); + lookat(3,3) = 1; - return lookat; + return lookat; } diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp new file mode 100644 index 0000000..cb26169 --- /dev/null +++ b/src/core/include/pw/core/size.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 1999-2017 Hartmut Seichter + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef PW_CORE_SIZE_HPP +#define PW_CORE_SIZE_HPP + +#include + +namespace pw { + +template +struct size { + + T_ dim[2] = { 0, 0}; + + size(T_ w,T_ h) : dim( { w, h }) {} + + const T_ width() { return dim[0]; } + const T_ height() { return dim[1]; } + +}; + +typedef size sizei; +typedef size sizef; + +} + +#endif diff --git a/src/deps/sol/sol.hpp b/src/deps/sol/sol.hpp deleted file mode 100644 index 6daac8c..0000000 --- a/src/deps/sol/sol.hpp +++ /dev/null @@ -1,14494 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2013-2017 Rapptz, ThePhD and contributors - -// 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. - -// This file was generated with a script. -// Generated 2017-06-13 20:34:08.313723 UTC -// This header was generated with sol v2.17.5 (revision 51a03b2) -// https://github.com/ThePhD/sol2 - -#ifndef SOL_SINGLE_INCLUDE_HPP -#define SOL_SINGLE_INCLUDE_HPP - -// beginning of sol.hpp - -#ifndef SOL_HPP -#define SOL_HPP - -#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL -#endif // Unreal Engine 4 bullshit - -#ifdef SOL_INSIDE_UNREAL -#ifdef check -#define SOL_INSIDE_UNREAL_REMOVED_CHECK -#undef check -#endif -#endif // Unreal Engine 4 Bullshit - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#pragma GCC diagnostic ignored "-Wconversion" -#if __GNUC__ > 6 -#pragma GCC diagnostic ignored "-Wnoexcept-type" -#endif -#elif defined _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4324 ) // structure was padded due to alignment specifier -#endif // g++ - -// beginning of sol/state.hpp - -// beginning of sol/state_view.hpp - -// beginning of sol/error.hpp - -#include -#include - -namespace sol { - namespace detail { - struct direct_error_tag {}; - const auto direct_error = direct_error_tag{}; - } // detail - - class error : public std::runtime_error { - private: - // Because VC++ is a fuccboi - std::string w; - public: - error(const std::string& str) : error(detail::direct_error, "lua: error: " + str) {} - error(std::string&& str) : error(detail::direct_error, "lua: error: " + std::move(str)) {} - error(detail::direct_error_tag, const std::string& str) : std::runtime_error(""), w(str) {} - error(detail::direct_error_tag, std::string&& str) : std::runtime_error(""), w(std::move(str)) {} - - error(const error& e) = default; - error(error&& e) = default; - error& operator=(const error& e) = default; - error& operator=(error&& e) = default; - - virtual const char* what() const noexcept override { - return w.c_str(); - } - }; - -} // sol - -// end of sol/error.hpp - -// beginning of sol/table.hpp - -// beginning of sol/table_core.hpp - -// beginning of sol/proxy.hpp - -// beginning of sol/traits.hpp - -// beginning of sol/tuple.hpp - -#include -#include - -namespace sol { - namespace detail { - using swallow = std::initializer_list; - } // detail - - template - struct types { typedef std::make_index_sequence indices; static constexpr std::size_t size() { return sizeof...(Args); } }; - namespace meta { - namespace detail { - template - struct tuple_types_ { typedef types type; }; - - template - struct tuple_types_> { typedef types type; }; - } // detail - - template - using unqualified = std::remove_cv>; - - template - using unqualified_t = typename unqualified::type; - - template - using tuple_types = typename detail::tuple_types_::type; - - template - struct pop_front_type; - - template - using pop_front_type_t = typename pop_front_type::type; - - template - struct pop_front_type> { typedef void front_type; typedef types type; }; - - template - struct pop_front_type> { typedef Arg front_type; typedef types type; }; - - template - using tuple_element = std::tuple_element>; - - template - using tuple_element_t = std::tuple_element_t>; - - template - using unqualified_tuple_element = unqualified>; - - template - using unqualified_tuple_element_t = unqualified_t>; - - } // meta -} // sol - -// end of sol/tuple.hpp - -// beginning of sol/bind_traits.hpp - -namespace sol { - namespace meta { - namespace meta_detail { - - template - struct check_deducible_signature { - struct nat {}; - template - static auto test(int) -> decltype(&G::operator(), void()); - template - static auto test(...)->nat; - - using type = std::is_void(0))>; - }; - } // meta_detail - - template - struct has_deducible_signature : meta_detail::check_deducible_signature::type { }; - - namespace meta_detail { - - template - struct void_tuple_element : meta::tuple_element {}; - - template - struct void_tuple_element> { typedef void type; }; - - template - using void_tuple_element_t = typename void_tuple_element::type; - - template - struct basic_traits { - private: - typedef std::conditional_t::value, int, T>& first_type; - - public: - static const bool is_member_function = std::is_void::value; - static const bool has_c_var_arg = has_c_variadic; - static const std::size_t arity = sizeof...(Args); - static const std::size_t free_arity = sizeof...(Args)+static_cast(!std::is_void::value); - typedef types args_list; - typedef std::tuple args_tuple; - typedef T object_type; - typedef R return_type; - typedef tuple_types returns_list; - typedef R(function_type)(Args...); - typedef std::conditional_t::value, args_list, types> free_args_list; - typedef std::conditional_t::value, R(Args...), R(first_type, Args...)> free_function_type; - typedef std::conditional_t::value, R(*)(Args...), R(*)(first_type, Args...)> free_function_pointer_type; - typedef std::remove_pointer_t signature_type; - template - using arg_at = void_tuple_element_t; - }; - - template::value> - struct fx_traits : basic_traits {}; - - // Free Functions - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args...); - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args...); - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args..., ...); - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args..., ...); - }; - - // Member Functions - /* C-Style Variadics */ - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...); - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...); - }; - - /* Const Volatile */ - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile; - }; - - /* Member Function Qualifiers */ - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile &; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) && ; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) && ; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const &&; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const &&; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile &&; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile &&; - }; - - template - struct fx_traits : fx_traits::function_type, false> {}; - - template::value> - struct callable_traits : fx_traits> { - - }; - - template - struct callable_traits { - typedef R Arg; - typedef T object_type; - using signature_type = R(T::*); - static const bool is_member_function = false; - static const std::size_t arity = 1; - static const std::size_t free_arity = 2; - typedef std::tuple args_tuple; - typedef R return_type; - typedef types args_list; - typedef types free_args_list; - typedef meta::tuple_types returns_list; - typedef R(function_type)(T&, R); - typedef R(*function_pointer_type)(T&, R); - typedef R(*free_function_pointer_type)(T&, R); - template - using arg_at = void_tuple_element_t; - }; - } // meta_detail - - template - struct bind_traits : meta_detail::callable_traits {}; - - template - using function_args_t = typename bind_traits::args_list; - - template - using function_signature_t = typename bind_traits::signature_type; - - template - using function_return_t = typename bind_traits::return_type; - - } // meta -} // sol - -// end of sol/bind_traits.hpp - -#include -#include -#include -#include - -namespace sol { - template - using index_value = std::integral_constant; - - namespace meta { - template - struct identity { typedef T type; }; - - template - using identity_t = typename identity::type; - - template - struct is_tuple : std::false_type { }; - - template - struct is_tuple> : std::true_type { }; - - template - struct is_builtin_type : std::integral_constant::value || std::is_pointer::value || std::is_array::value> {}; - - template - struct unwrapped { - typedef T type; - }; - - template - struct unwrapped> { - typedef T type; - }; - - template - using unwrapped_t = typename unwrapped::type; - - template - struct unwrap_unqualified : unwrapped> {}; - - template - using unwrap_unqualified_t = typename unwrap_unqualified::type; - - template - struct remove_member_pointer; - - template - struct remove_member_pointer { - typedef R type; - }; - - template - struct remove_member_pointer { - typedef R type; - }; - - template - using remove_member_pointer_t = remove_member_pointer; - - template class Templ, typename T> - struct is_specialization_of : std::false_type { }; - template class Templ> - struct is_specialization_of> : std::true_type { }; - - template - struct all_same : std::true_type { }; - - template - struct all_same : std::integral_constant ::value && all_same::value> { }; - - template - struct any_same : std::false_type { }; - - template - struct any_same : std::integral_constant ::value || any_same::value> { }; - - template - using invoke_t = typename T::type; - - template - using boolean = std::integral_constant; - - template - using neg = boolean; - - template - using condition = std::conditional_t; - - template - struct all : boolean {}; - - template - struct all : condition, boolean> {}; - - template - struct any : boolean {}; - - template - struct any : condition, any> {}; - - enum class enable_t { - _ - }; - - constexpr const auto enabler = enable_t::_; - - template - using disable_if_t = std::enable_if_t; - - template - using enable = std::enable_if_t::value, enable_t>; - - template - using disable = std::enable_if_t>::value, enable_t>; - - template - using disable_any = std::enable_if_t>::value, enable_t>; - - template - struct find_in_pack_v : boolean { }; - - template - struct find_in_pack_v : any, find_in_pack_v> { }; - - namespace meta_detail { - template - struct index_in_pack : std::integral_constant { }; - - template - struct index_in_pack : std::conditional_t::value, std::integral_constant, index_in_pack> { }; - } - - template - struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> { }; - - template - struct index_in : meta_detail::index_in_pack<0, T, List> { }; - - template - struct index_in> : meta_detail::index_in_pack<0, T, Args...> { }; - - template - struct at_in_pack {}; - - template - using at_in_pack_t = typename at_in_pack::type; - - template - struct at_in_pack : std::conditional> {}; - - template - struct at_in_pack<0, Arg, Args...> { typedef Arg type; }; - - namespace meta_detail { - template class Pred, typename... Ts> - struct count_for_pack : std::integral_constant {}; - template class Pred, typename T, typename... Ts> - struct count_for_pack : std::conditional_t < sizeof...(Ts) == 0 || Limit < 2, - std::integral_constant(Limit != 0 && Pred::value)>, - count_for_pack(Pred::value), Pred, Ts...> - > { }; - template class Pred, typename... Ts> - struct count_2_for_pack : std::integral_constant {}; - template class Pred, typename T, typename U, typename... Ts> - struct count_2_for_pack : std::conditional_t(Pred::value)>, - count_2_for_pack(Pred::value), Pred, Ts...> - > { }; - } // meta_detail - - template class Pred, typename... Ts> - struct count_for_pack : meta_detail::count_for_pack { }; - - template class Pred, typename List> - struct count_for; - - template class Pred, typename... Args> - struct count_for> : count_for_pack {}; - - template class Pred, typename... Ts> - struct count_for_to_pack : meta_detail::count_for_pack { }; - - template class Pred, typename... Ts> - struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> { }; - - template - struct return_type { - typedef std::tuple type; - }; - - template - struct return_type { - typedef T type; - }; - - template<> - struct return_type<> { - typedef void type; - }; - - template - using return_type_t = typename return_type::type; - - namespace meta_detail { - template struct always_true : std::true_type {}; - struct is_invokable_tester { - template - always_true()(std::declval()...))> static test(int); - template - std::false_type static test(...); - }; - } // meta_detail - - template - struct is_invokable; - template - struct is_invokable : decltype(meta_detail::is_invokable_tester::test(0)) {}; - - namespace meta_detail { - - template>::value> - struct is_callable : std::is_function> {}; - - template - struct is_callable { - using yes = char; - using no = struct { char s[2]; }; - - struct F { void operator()(); }; - struct Derived : T, F {}; - template struct Check; - - template - static no test(Check*); - - template - static yes test(...); - - static const bool value = sizeof(test(0)) == sizeof(yes); - }; - - struct has_begin_end_impl { - template, - typename B = decltype(std::declval().begin()), - typename E = decltype(std::declval().end())> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - struct has_key_value_pair_impl { - template, - typename V = typename U::value_type, - typename F = decltype(std::declval().first), - typename S = decltype(std::declval().second)> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - template () < std::declval())> - std::true_type supports_op_less_test(const T&); - std::false_type supports_op_less_test(...); - template () == std::declval())> - std::true_type supports_op_equal_test(const T&); - std::false_type supports_op_equal_test(...); - template () <= std::declval())> - std::true_type supports_op_less_equal_test(const T&); - std::false_type supports_op_less_equal_test(...); - - } // meta_detail - - template - using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval())); - template - using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval())); - template - using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval())); - - template - struct is_callable : boolean::value> {}; - - template - struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test(0)) {}; - - template - struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test(0)) {}; - - template - using is_string_constructible = any, const char*>, std::is_same, char>, std::is_same, std::string>, std::is_same, std::initializer_list>>; - - template - struct is_pair : std::false_type {}; - - template - struct is_pair> : std::true_type {}; - - template - using is_c_str = any< - std::is_same>, const char*>, - std::is_same>, char*>, - std::is_same, std::string> - >; - - template - struct is_move_only : all< - neg>, - neg>>, - std::is_move_constructible> - > {}; - - template - using is_not_move_only = neg>; - - namespace meta_detail { - template >> = meta::enabler> - decltype(auto) force_tuple(T&& x) { - return std::forward_as_tuple(std::forward(x)); - } - - template >> = meta::enabler> - decltype(auto) force_tuple(T&& x) { - return std::forward(x); - } - } // meta_detail - - template - decltype(auto) tuplefy(X&&... x) { - return std::tuple_cat(meta_detail::force_tuple(std::forward(x))...); - } - - template - struct iterator_tag { - using type = std::input_iterator_tag; - }; - - template - struct iterator_tag> { - using type = typename T::iterator_category; - }; - - } // meta - - namespace detail { - template - decltype(auto) forward_get(Tuple&& tuple) { - return std::forward>(std::get(tuple)); - } - - template - auto forward_tuple_impl(std::index_sequence, Tuple&& tuple) -> decltype(std::tuple(tuple))...>(forward_get(tuple)...)) { - return std::tuple(tuple))...>(std::move(std::get(tuple))...); - } - - template - auto forward_tuple(Tuple&& tuple) { - auto x = forward_tuple_impl(std::make_index_sequence>::value>(), std::forward(tuple)); - return x; - } - - template - auto unwrap(T&& item) -> decltype(std::forward(item)) { - return std::forward(item); - } - - template - T& unwrap(std::reference_wrapper arg) { - return arg.get(); - } - - template - auto deref(T&& item) -> decltype(std::forward(item)) { - return std::forward(item); - } - - template - inline T& deref(T* item) { - return *item; - } - - template - inline std::add_lvalue_reference_t deref(std::unique_ptr& item) { - return *item; - } - - template - inline std::add_lvalue_reference_t deref(std::shared_ptr& item) { - return *item; - } - - template - inline std::add_lvalue_reference_t deref(const std::unique_ptr& item) { - return *item; - } - - template - inline std::add_lvalue_reference_t deref(const std::shared_ptr& item) { - return *item; - } - - template - inline T* ptr(T& val) { - return std::addressof(val); - } - - template - inline T* ptr(std::reference_wrapper val) { - return std::addressof(val.get()); - } - - template - inline T* ptr(T* val) { - return val; - } - } // detail -} // sol - -// end of sol/traits.hpp - -// beginning of sol/object.hpp - -// beginning of sol/reference.hpp - -// beginning of sol/types.hpp - -// beginning of sol/optional.hpp - -// beginning of sol/compatibility.hpp - -// beginning of sol/compatibility/version.hpp - -#ifdef SOL_USING_CXX_LUA -#include -#include -#include -#else -#include -#endif // C++ Mangling for Lua - -#if defined(_WIN32) || defined(_MSC_VER) -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // sol codecvt support -#elif defined(__GNUC__) -#if __GNUC__ >= 5 -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // codecvt support -#endif // g++ 5.x.x (MinGW too) -#else -#endif // Windows/VC++ vs. g++ vs Others - -#ifdef LUAJIT_VERSION -#ifndef SOL_LUAJIT -#define SOL_LUAJIT -#define SOL_LUAJIT_VERSION LUAJIT_VERSION_NUM -#endif // sol luajit -#endif // luajit - -#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 -#define SOL_LUA_VERSION LUA_VERSION_NUM -#elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 -#define SOL_LUA_VERSION LUA_VERSION_NUM -#elif !defined(LUA_VERSION_NUM) -#define SOL_LUA_VERSION 500 -#else -#define SOL_LUA_VERSION 502 -#endif // Lua Version 502, 501 || luajit, 500 - -#ifdef _MSC_VER -#ifdef _DEBUG -#ifndef NDEBUG -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // NDEBUG -#endif // Debug - -#ifndef _CPPUNWIND -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // Automatic Exceptions - -#ifndef _CPPRTTI -#ifndef SOL_NO_RTTI -#define SOL_NO_RTTI 1 -#endif -#endif // Automatic RTTI - -#elif defined(__GNUC__) || defined(__clang__) - -#ifndef NDEBUG -#ifndef __OPTIMIZE__ -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // g++ optimizer flag -#endif // Not Debug - -#ifndef __EXCEPTIONS -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // No Exceptions - -#ifndef __GXX_RTTI -#ifndef SOL_NO_RTII -#define SOL_NO_RTTI 1 -#endif -#endif // No RTTI - -#endif // vc++ || clang++/g++ - -#ifndef SOL_SAFE_USERTYPE -#ifdef SOL_CHECK_ARGUMENTS -#define SOL_SAFE_USERTYPE -#endif // Turn on Safety for all -#endif // Safe Usertypes - -// end of sol/compatibility/version.hpp - -#ifndef SOL_NO_COMPAT - -#if defined(__cplusplus) && !defined(SOL_USING_CXX_LUA) -extern "C" { -#endif -// beginning of sol/compatibility/5.2.0.h - -#ifndef SOL_5_2_0_H -#define SOL_5_2_0_H - -#if SOL_LUA_VERSION < 503 - -inline int lua_isinteger(lua_State* L, int idx) { - if (lua_type(L, idx) != LUA_TNUMBER) - return 0; - // This is a very slipshod way to do the testing - // but lua_totingerx doesn't play ball nicely - // on older versions... - lua_Number n = lua_tonumber(L, idx); - lua_Integer i = lua_tointeger(L, idx); - if (i != n) - return 0; - // it's DEFINITELY an integer - return 1; -} - -#endif // SOL_LUA_VERSION == 502 -#endif // SOL_5_2_0_H -// end of sol/compatibility/5.2.0.h - -// beginning of sol/compatibility/5.1.0.h - -#ifndef SOL_5_1_0_H -#define SOL_5_1_0_H - -#if SOL_LUA_VERSION == 501 -/* Lua 5.1 */ - -#include -#include -#include - -/* LuaJIT doesn't define these unofficial macros ... */ -#if !defined(LUAI_INT32) -#include -#if INT_MAX-20 < 32760 -#define LUAI_INT32 long -#define LUAI_UINT32 unsigned long -#elif INT_MAX > 2147483640L -#define LUAI_INT32 int -#define LUAI_UINT32 unsigned int -#else -#error "could not detect suitable lua_Unsigned datatype" -#endif -#endif - -/* LuaJIT does not have the updated error codes for thread status/function returns */ -#ifndef LUA_ERRGCMM -#define LUA_ERRGCMM (LUA_ERRERR + 2) -#endif // LUA_ERRGCMM - -/* LuaJIT does not support continuation contexts / return error codes? */ -#ifndef LUA_KCONTEXT -#define LUA_KCONTEXT std::ptrdiff_t -typedef LUA_KCONTEXT lua_KContext; -typedef int(*lua_KFunction) (lua_State *L, int status, lua_KContext ctx); -#endif // LUA_KCONTEXT - -#define LUA_OPADD 0 -#define LUA_OPSUB 1 -#define LUA_OPMUL 2 -#define LUA_OPDIV 3 -#define LUA_OPMOD 4 -#define LUA_OPPOW 5 -#define LUA_OPUNM 6 -#define LUA_OPEQ 0 -#define LUA_OPLT 1 -#define LUA_OPLE 2 - -typedef LUAI_UINT32 lua_Unsigned; - -typedef struct luaL_Buffer_52 { - luaL_Buffer b; /* make incorrect code crash! */ - char *ptr; - size_t nelems; - size_t capacity; - lua_State *L2; -} luaL_Buffer_52; -#define luaL_Buffer luaL_Buffer_52 - -#define lua_tounsigned(L, i) lua_tounsignedx(L, i, NULL) - -#define lua_rawlen(L, i) lua_objlen(L, i) - -inline void lua_callk(lua_State *L, int nargs, int nresults, lua_KContext, lua_KFunction) { - // should probably warn the user of Lua 5.1 that continuation isn't supported... - lua_call(L, nargs, nresults); -} -inline int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, lua_KContext, lua_KFunction) { - // should probably warn the user of Lua 5.1 that continuation isn't supported... - return lua_pcall(L, nargs, nresults, errfunc); -} -void lua_arith(lua_State *L, int op); -int lua_compare(lua_State *L, int idx1, int idx2, int op); -void lua_pushunsigned(lua_State *L, lua_Unsigned n); -lua_Unsigned luaL_checkunsigned(lua_State *L, int i); -lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum); -lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def); -lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum); -void lua_len(lua_State *L, int i); -int luaL_len(lua_State *L, int i); -const char *luaL_tolstring(lua_State *L, int idx, size_t *len); -void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb); - -#define luaL_buffinit luaL_buffinit_52 -void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B); - -#define luaL_prepbuffsize luaL_prepbuffsize_52 -char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s); - -#define luaL_addlstring luaL_addlstring_52 -void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l); - -#define luaL_addvalue luaL_addvalue_52 -void luaL_addvalue(luaL_Buffer_52 *B); - -#define luaL_pushresult luaL_pushresult_52 -void luaL_pushresult(luaL_Buffer_52 *B); - -#undef luaL_buffinitsize -#define luaL_buffinitsize(L, B, s) \ - (luaL_buffinit(L, B), luaL_prepbuffsize(B, s)) - -#undef luaL_prepbuffer -#define luaL_prepbuffer(B) \ - luaL_prepbuffsize(B, LUAL_BUFFERSIZE) - -#undef luaL_addchar -#define luaL_addchar(B, c) \ - ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize(B, 1)), \ - ((B)->ptr[(B)->nelems++] = (c))) - -#undef luaL_addsize -#define luaL_addsize(B, s) \ - ((B)->nelems += (s)) - -#undef luaL_addstring -#define luaL_addstring(B, s) \ - luaL_addlstring(B, s, strlen(s)) - -#undef luaL_pushresultsize -#define luaL_pushresultsize(B, s) \ - (luaL_addsize(B, s), luaL_pushresult(B)) - -typedef struct kepler_lua_compat_get_string_view { - const char *s; - size_t size; -} kepler_lua_compat_get_string_view; - -inline const char* kepler_lua_compat_get_string(lua_State* L, void* ud, size_t* size) { - kepler_lua_compat_get_string_view* ls = (kepler_lua_compat_get_string_view*) ud; - (void)L; - if (ls->size == 0) return NULL; - *size = ls->size; - ls->size = 0; - return ls->s; -} - -#if !defined(SOL_LUAJIT) || (SOL_LUAJIT_VERSION < 20100) - -inline int luaL_loadbufferx(lua_State* L, const char* buff, size_t size, const char* name, const char*) { - kepler_lua_compat_get_string_view ls; - ls.s = buff; - ls.size = size; - return lua_load(L, kepler_lua_compat_get_string, &ls, name/*, mode*/); -} - -#endif // LuaJIT 2.1.x beta and beyond - -#endif /* Lua 5.1 */ - -#endif // SOL_5_1_0_H -// end of sol/compatibility/5.1.0.h - -// beginning of sol/compatibility/5.0.0.h - -#ifndef SOL_5_0_0_H -#define SOL_5_0_0_H - -#if SOL_LUA_VERSION < 501 -/* Lua 5.0 */ - -#define LUA_QL(x) "'" x "'" -#define LUA_QS LUA_QL("%s") - -#define luaL_Reg luaL_reg - -#define luaL_opt(L, f, n, d) \ - (lua_isnoneornil(L, n) ? (d) : f(L, n)) - -#define luaL_addchar(B,c) \ - ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ - (*(B)->p++ = (char)(c))) - -#endif // Lua 5.0 - -#endif // SOL_5_0_0_H -// end of sol/compatibility/5.0.0.h - -// beginning of sol/compatibility/5.x.x.h - -#ifndef SOL_5_X_X_H -#define SOL_5_X_X_H - -#if SOL_LUA_VERSION < 502 - -#define LUA_RIDX_GLOBALS LUA_GLOBALSINDEX - -#define LUA_OK 0 - -#define lua_pushglobaltable(L) \ - lua_pushvalue(L, LUA_GLOBALSINDEX) - -#ifndef SOL_LUAJIT -#define luaL_newlib(L, l) \ - (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) -#else -#if SOL_LUAJIT_VERSION < 20100 -#define luaL_newlib(L, l) \ - (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) -#endif // LuaJIT-2.1.0-beta3 added this in itself -#endif // LuaJIT Compatibility - -void luaL_checkversion(lua_State *L); - -int lua_absindex(lua_State *L, int i); -void lua_copy(lua_State *L, int from, int to); -void lua_rawgetp(lua_State *L, int i, const void *p); -void lua_rawsetp(lua_State *L, int i, const void *p); -void *luaL_testudata(lua_State *L, int i, const char *tname); -lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); -void lua_getuservalue(lua_State *L, int i); -void lua_setuservalue(lua_State *L, int i); -void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); -void luaL_setmetatable(lua_State *L, const char *tname); -int luaL_getsubtable(lua_State *L, int i, const char *name); -void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level); -int luaL_fileresult(lua_State *L, int stat, const char *fname); - -#endif // Lua 5.1 and below - -#endif // SOL_5_X_X_H -// end of sol/compatibility/5.x.x.h - -// beginning of sol/compatibility/5.x.x.inl - -#ifndef SOL_5_X_X_INL -#define SOL_5_X_X_INL - -#if SOL_LUA_VERSION < 502 - -#include - -#define PACKAGE_KEY "_sol.package" - -inline int lua_absindex(lua_State *L, int i) { - if (i < 0 && i > LUA_REGISTRYINDEX) - i += lua_gettop(L) + 1; - return i; -} - -inline void lua_copy(lua_State *L, int from, int to) { - int abs_to = lua_absindex(L, to); - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushvalue(L, from); - lua_replace(L, abs_to); -} - -inline void lua_rawgetp(lua_State *L, int i, const void *p) { - int abs_i = lua_absindex(L, i); - lua_pushlightuserdata(L, (void*)p); - lua_rawget(L, abs_i); -} - -inline void lua_rawsetp(lua_State *L, int i, const void *p) { - int abs_i = lua_absindex(L, i); - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushlightuserdata(L, (void*)p); - lua_insert(L, -2); - lua_rawset(L, abs_i); -} - -inline void *luaL_testudata(lua_State *L, int i, const char *tname) { - void *p = lua_touserdata(L, i); - luaL_checkstack(L, 2, "not enough stack slots"); - if (p == NULL || !lua_getmetatable(L, i)) - return NULL; - else { - int res = 0; - luaL_getmetatable(L, tname); - res = lua_rawequal(L, -1, -2); - lua_pop(L, 2); - if (!res) - p = NULL; - } - return p; -} - -inline lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) { - lua_Number n = lua_tonumber(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline static void push_package_table(lua_State *L) { - lua_pushliteral(L, PACKAGE_KEY); - lua_rawget(L, LUA_REGISTRYINDEX); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - /* try to get package table from globals */ - lua_pushliteral(L, "package"); - lua_rawget(L, LUA_GLOBALSINDEX); - if (lua_istable(L, -1)) { - lua_pushliteral(L, PACKAGE_KEY); - lua_pushvalue(L, -2); - lua_rawset(L, LUA_REGISTRYINDEX); - } - } -} - -inline void lua_getuservalue(lua_State *L, int i) { - luaL_checktype(L, i, LUA_TUSERDATA); - luaL_checkstack(L, 2, "not enough stack slots"); - lua_getfenv(L, i); - lua_pushvalue(L, LUA_GLOBALSINDEX); - if (lua_rawequal(L, -1, -2)) { - lua_pop(L, 1); - lua_pushnil(L); - lua_replace(L, -2); - } - else { - lua_pop(L, 1); - push_package_table(L); - if (lua_rawequal(L, -1, -2)) { - lua_pop(L, 1); - lua_pushnil(L); - lua_replace(L, -2); - } - else - lua_pop(L, 1); - } -} - -inline void lua_setuservalue(lua_State *L, int i) { - luaL_checktype(L, i, LUA_TUSERDATA); - if (lua_isnil(L, -1)) { - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushvalue(L, LUA_GLOBALSINDEX); - lua_replace(L, -2); - } - lua_setfenv(L, i); -} - -/* -** Adapted from Lua 5.2.0 -*/ -inline void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { - luaL_checkstack(L, nup + 1, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - int i; - lua_pushstring(L, l->name); - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -(nup + 1)); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ - lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ - } - lua_pop(L, nup); /* remove upvalues */ -} - -inline void luaL_setmetatable(lua_State *L, const char *tname) { - luaL_checkstack(L, 1, "not enough stack slots"); - luaL_getmetatable(L, tname); - lua_setmetatable(L, -2); -} - -inline int luaL_getsubtable(lua_State *L, int i, const char *name) { - int abs_i = lua_absindex(L, i); - luaL_checkstack(L, 3, "not enough stack slots"); - lua_pushstring(L, name); - lua_gettable(L, abs_i); - if (lua_istable(L, -1)) - return 1; - lua_pop(L, 1); - lua_newtable(L); - lua_pushstring(L, name); - lua_pushvalue(L, -2); - lua_settable(L, abs_i); - return 0; -} - -#ifndef SOL_LUAJIT -inline static int countlevels(lua_State *L) { - lua_Debug ar; - int li = 1, le = 1; - /* find an upper bound */ - while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } - /* do a binary search */ - while (li < le) { - int m = (li + le) / 2; - if (lua_getstack(L, m, &ar)) li = m + 1; - else le = m; - } - return le - 1; -} - -inline static int findfield(lua_State *L, int objidx, int level) { - if (level == 0 || !lua_istable(L, -1)) - return 0; /* not found */ - lua_pushnil(L); /* start 'next' loop */ - while (lua_next(L, -2)) { /* for each pair in table */ - if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ - if (lua_rawequal(L, objidx, -1)) { /* found object? */ - lua_pop(L, 1); /* remove value (but keep name) */ - return 1; - } - else if (findfield(L, objidx, level - 1)) { /* try recursively */ - lua_remove(L, -2); /* remove table (but keep name) */ - lua_pushliteral(L, "."); - lua_insert(L, -2); /* place '.' between the two names */ - lua_concat(L, 3); - return 1; - } - } - lua_pop(L, 1); /* remove value */ - } - return 0; /* not found */ -} - -inline static int pushglobalfuncname(lua_State *L, lua_Debug *ar) { - int top = lua_gettop(L); - lua_getinfo(L, "f", ar); /* push function */ - lua_pushvalue(L, LUA_GLOBALSINDEX); - if (findfield(L, top + 1, 2)) { - lua_copy(L, -1, top + 1); /* move name to proper place */ - lua_pop(L, 2); /* remove pushed values */ - return 1; - } - else { - lua_settop(L, top); /* remove function and global table */ - return 0; - } -} - -inline static void pushfuncname(lua_State *L, lua_Debug *ar) { - if (*ar->namewhat != '\0') /* is there a name? */ - lua_pushfstring(L, "function " LUA_QS, ar->name); - else if (*ar->what == 'm') /* main? */ - lua_pushliteral(L, "main chunk"); - else if (*ar->what == 'C') { - if (pushglobalfuncname(L, ar)) { - lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); - lua_remove(L, -2); /* remove name */ - } - else - lua_pushliteral(L, "?"); - } - else - lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); -} - -#define LEVELS1 12 /* size of the first part of the stack */ -#define LEVELS2 10 /* size of the second part of the stack */ - -inline void luaL_traceback(lua_State *L, lua_State *L1, - const char *msg, int level) { - lua_Debug ar; - int top = lua_gettop(L); - int numlevels = countlevels(L1); - int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0; - if (msg) lua_pushfstring(L, "%s\n", msg); - lua_pushliteral(L, "stack traceback:"); - while (lua_getstack(L1, level++, &ar)) { - if (level == mark) { /* too many levels? */ - lua_pushliteral(L, "\n\t..."); /* add a '...' */ - level = numlevels - LEVELS2; /* and skip to last ones */ - } - else { - lua_getinfo(L1, "Slnt", &ar); - lua_pushfstring(L, "\n\t%s:", ar.short_src); - if (ar.currentline > 0) - lua_pushfstring(L, "%d:", ar.currentline); - lua_pushliteral(L, " in "); - pushfuncname(L, &ar); - lua_concat(L, lua_gettop(L) - top); - } - } - lua_concat(L, lua_gettop(L) - top); -} -#endif - -inline const lua_Number *lua_version(lua_State *L) { - static const lua_Number version = LUA_VERSION_NUM; - if (L == NULL) return &version; - // TODO: wonky hacks to get at the inside of the incomplete type lua_State? - //else return L->l_G->version; - else return &version; -} - -inline static void luaL_checkversion_(lua_State *L, lua_Number ver) { - const lua_Number* v = lua_version(L); - if (v != lua_version(NULL)) - luaL_error(L, "multiple Lua VMs detected"); - else if (*v != ver) - luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", - ver, *v); - /* check conversions number -> integer types */ - lua_pushnumber(L, -(lua_Number)0x1234); - if (lua_tointeger(L, -1) != -0x1234 || - lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234) - luaL_error(L, "bad conversion number->int;" - " must recompile Lua with proper settings"); - lua_pop(L, 1); -} - -inline void luaL_checkversion(lua_State* L) { - luaL_checkversion_(L, LUA_VERSION_NUM); -} - -#ifndef SOL_LUAJIT -inline int luaL_fileresult(lua_State *L, int stat, const char *fname) { - int en = errno; /* calls to Lua API may change this value */ - if (stat) { - lua_pushboolean(L, 1); - return 1; - } - else { - char buf[1024]; -#if defined(__GLIBC__) || defined(_POSIX_VERSION) - strerror_r(en, buf, 1024); -#else - strerror_s(buf, 1024, en); -#endif - lua_pushnil(L); - if (fname) - lua_pushfstring(L, "%s: %s", fname, buf); - else - lua_pushstring(L, buf); - lua_pushnumber(L, (lua_Number)en); - return 3; - } -} -#endif // luajit -#endif // Lua 5.0 or Lua 5.1 - -#if SOL_LUA_VERSION == 501 - -typedef LUAI_INT32 LUA_INT32; - -/********************************************************************/ -/* extract of 5.2's luaconf.h */ -/* detects proper defines for faster unsigned<->number conversion */ -/* see copyright notice at the end of this file */ -/********************************************************************/ - -#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE) -#define LUA_WIN /* enable goodies for regular Windows platforms */ -#endif - -#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */ - -/* Microsoft compiler on a Pentium (32 bit) ? */ -#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */ - -#define LUA_MSASMTRICK -#define LUA_IEEEENDIAN 0 -#define LUA_NANTRICK - -/* pentium 32 bits? */ -#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEELL -#define LUA_IEEEENDIAN 0 -#define LUA_NANTRICK - -/* pentium 64 bits? */ -#elif defined(__x86_64) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEEENDIAN 0 - -#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEEENDIAN 1 - -#else /* }{ */ - -/* assume IEEE754 and a 32-bit integer type */ -#define LUA_IEEE754TRICK - -#endif /* } */ - -#endif /* } */ - -/********************************************************************/ -/* extract of 5.2's llimits.h */ -/* gives us lua_number2unsigned and lua_unsigned2number */ -/* see copyright notice just below this one here */ -/********************************************************************/ - -/********************************************************************* -* This file contains parts of Lua 5.2's source code: -* -* Copyright (C) 1994-2013 Lua.org, PUC-Rio. -* -* 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. -*********************************************************************/ - -#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */ -/* trick with Microsoft assembler for X86 */ - -#define lua_number2unsigned(i,n) \ - {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} - -#elif defined(LUA_IEEE754TRICK) /* }{ */ -/* the next trick should work on any machine using IEEE754 with -a 32-bit int type */ - -union compat52_luai_Cast { double l_d; LUA_INT32 l_p[2]; }; - -#if !defined(LUA_IEEEENDIAN) /* { */ -#define LUAI_EXTRAIEEE \ - static const union compat52_luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; -#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33) -#else -#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN -#define LUAI_EXTRAIEEE /* empty */ -#endif /* } */ - -#define lua_number2int32(i,n,t) \ - { LUAI_EXTRAIEEE \ - volatile union compat52_luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ - (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; } - -#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) - -#endif /* } */ - -/* the following definitions always work, but may be slow */ - -#if !defined(lua_number2unsigned) /* { */ -/* the following definition assures proper modulo behavior */ -#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT) -#include -#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1) -#define lua_number2unsigned(i,n) \ - ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED)) -#else -#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) -#endif -#endif /* } */ - -#if !defined(lua_unsigned2number) -/* on several machines, coercion from unsigned to double is slow, -so it may be worth to avoid */ -#define lua_unsigned2number(u) \ - (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) -#endif - -/********************************************************************/ - -inline static void compat52_call_lua(lua_State *L, char const code[], size_t len, - int nargs, int nret) { - lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code); - if (lua_type(L, -1) != LUA_TFUNCTION) { - lua_pop(L, 1); - if (luaL_loadbuffer(L, code, len, "=none")) - lua_error(L); - lua_pushvalue(L, -1); - lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code); - } - lua_insert(L, -nargs - 1); - lua_call(L, nargs, nret); -} - -static const char compat52_arith_code[] = { - "local op,a,b=...\n" - "if op==0 then return a+b\n" - "elseif op==1 then return a-b\n" - "elseif op==2 then return a*b\n" - "elseif op==3 then return a/b\n" - "elseif op==4 then return a%b\n" - "elseif op==5 then return a^b\n" - "elseif op==6 then return -a\n" - "end\n" -}; - -inline void lua_arith(lua_State *L, int op) { - if (op < LUA_OPADD || op > LUA_OPUNM) - luaL_error(L, "invalid 'op' argument for lua_arith"); - luaL_checkstack(L, 5, "not enough stack slots"); - if (op == LUA_OPUNM) - lua_pushvalue(L, -1); - lua_pushnumber(L, op); - lua_insert(L, -3); - compat52_call_lua(L, compat52_arith_code, - sizeof(compat52_arith_code) - 1, 3, 1); -} - -static const char compat52_compare_code[] = { - "local a,b=...\n" - "return a<=b\n" -}; - -inline int lua_compare(lua_State *L, int idx1, int idx2, int op) { - int result = 0; - switch (op) { - case LUA_OPEQ: - return lua_equal(L, idx1, idx2); - case LUA_OPLT: - return lua_lessthan(L, idx1, idx2); - case LUA_OPLE: - luaL_checkstack(L, 5, "not enough stack slots"); - idx1 = lua_absindex(L, idx1); - idx2 = lua_absindex(L, idx2); - lua_pushvalue(L, idx1); - lua_pushvalue(L, idx2); - compat52_call_lua(L, compat52_compare_code, - sizeof(compat52_compare_code) - 1, 2, 1); - result = lua_toboolean(L, -1); - lua_pop(L, 1); - return result; - default: - luaL_error(L, "invalid 'op' argument for lua_compare"); - } - return 0; -} - -inline void lua_pushunsigned(lua_State *L, lua_Unsigned n) { - lua_pushnumber(L, lua_unsigned2number(n)); -} - -inline lua_Unsigned luaL_checkunsigned(lua_State *L, int i) { - lua_Unsigned result; - lua_Number n = lua_tonumber(L, i); - if (n == 0 && !lua_isnumber(L, i)) - luaL_checktype(L, i, LUA_TNUMBER); - lua_number2unsigned(result, n); - return result; -} - -inline lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum) { - lua_Unsigned result; - lua_Number n = lua_tonumberx(L, i, isnum); - lua_number2unsigned(result, n); - return result; -} - -inline lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def) { - return luaL_opt(L, luaL_checkunsigned, i, def); -} - -inline lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) { - lua_Integer n = lua_tointeger(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline void lua_len(lua_State *L, int i) { - switch (lua_type(L, i)) { - case LUA_TSTRING: /* fall through */ - case LUA_TTABLE: - if (!luaL_callmeta(L, i, "__len")) - lua_pushnumber(L, (int)lua_objlen(L, i)); - break; - case LUA_TUSERDATA: - if (luaL_callmeta(L, i, "__len")) - break; - /* maybe fall through */ - default: - luaL_error(L, "attempt to get length of a %s value", - lua_typename(L, lua_type(L, i))); - } -} - -inline int luaL_len(lua_State *L, int i) { - int res = 0, isnum = 0; - luaL_checkstack(L, 1, "not enough stack slots"); - lua_len(L, i); - res = (int)lua_tointegerx(L, -1, &isnum); - lua_pop(L, 1); - if (!isnum) - luaL_error(L, "object length is not a number"); - return res; -} - -inline const char *luaL_tolstring(lua_State *L, int idx, size_t *len) { - if (!luaL_callmeta(L, idx, "__tostring")) { - int t = lua_type(L, idx); - switch (t) { - case LUA_TNIL: - lua_pushliteral(L, "nil"); - break; - case LUA_TSTRING: - case LUA_TNUMBER: - lua_pushvalue(L, idx); - break; - case LUA_TBOOLEAN: - if (lua_toboolean(L, idx)) - lua_pushliteral(L, "true"); - else - lua_pushliteral(L, "false"); - break; - default: - lua_pushfstring(L, "%s: %p", lua_typename(L, t), - lua_topointer(L, idx)); - break; - } - } - return lua_tolstring(L, -1, len); -} - -inline void luaL_requiref(lua_State *L, char const* modname, - lua_CFunction openf, int glb) { - luaL_checkstack(L, 3, "not enough stack slots"); - lua_pushcfunction(L, openf); - lua_pushstring(L, modname); - lua_call(L, 1, 1); - lua_getglobal(L, "package"); - if (lua_istable(L, -1) == 0) { - lua_pop(L, 1); - lua_createtable(L, 0, 16); - lua_setglobal(L, "package"); - lua_getglobal(L, "package"); - } - lua_getfield(L, -1, "loaded"); - if (lua_istable(L, -1) == 0) { - lua_pop(L, 1); - lua_createtable(L, 0, 1); - lua_setfield(L, -2, "loaded"); - lua_getfield(L, -1, "loaded"); - } - lua_replace(L, -2); - lua_pushvalue(L, -2); - lua_setfield(L, -2, modname); - lua_pop(L, 1); - if (glb) { - lua_pushvalue(L, -1); - lua_setglobal(L, modname); - } -} - -inline void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B) { - /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ - B->b.p = NULL; - B->b.L = NULL; - B->b.lvl = 0; - /* reuse the buffer from the 5.1-style luaL_Buffer though! */ - B->ptr = B->b.buffer; - B->capacity = LUAL_BUFFERSIZE; - B->nelems = 0; - B->L2 = L; -} - -inline char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s) { - if (B->capacity - B->nelems < s) { /* needs to grow */ - char* newptr = NULL; - size_t newcap = B->capacity * 2; - if (newcap - B->nelems < s) - newcap = B->nelems + s; - if (newcap < B->capacity) /* overflow */ - luaL_error(B->L2, "buffer too large"); - newptr = (char*)lua_newuserdata(B->L2, newcap); - memcpy(newptr, B->ptr, B->nelems); - if (B->ptr != B->b.buffer) - lua_replace(B->L2, -2); /* remove old buffer */ - B->ptr = newptr; - B->capacity = newcap; - } - return B->ptr + B->nelems; -} - -inline void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l) { - memcpy(luaL_prepbuffsize(B, l), s, l); - luaL_addsize(B, l); -} - -inline void luaL_addvalue(luaL_Buffer_52 *B) { - size_t len = 0; - const char *s = lua_tolstring(B->L2, -1, &len); - if (!s) - luaL_error(B->L2, "cannot convert value to string"); - if (B->ptr != B->b.buffer) - lua_insert(B->L2, -2); /* userdata buffer must be at stack top */ - luaL_addlstring(B, s, len); - lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1); -} - -inline void luaL_pushresult(luaL_Buffer_52 *B) { - lua_pushlstring(B->L2, B->ptr, B->nelems); - if (B->ptr != B->b.buffer) - lua_replace(B->L2, -2); /* remove userdata buffer */ -} - -#endif /* SOL_LUA_VERSION == 501 */ - -#endif // SOL_5_X_X_INL -// end of sol/compatibility/5.x.x.inl - -#if defined(__cplusplus) && !defined(SOL_USING_CXX_LUA) -} -#endif - -#endif // SOL_NO_COMPAT - -// end of sol/compatibility.hpp - -// beginning of sol/in_place.hpp - -namespace sol { - - namespace detail { - struct in_place_of {}; - template - struct in_place_of_i {}; - template - struct in_place_of_t {}; - } // detail - - struct in_place_tag { struct init {}; constexpr in_place_tag(init) {} in_place_tag() = delete; }; - constexpr inline in_place_tag in_place(detail::in_place_of) { return in_place_tag(in_place_tag::init()); } - template - constexpr inline in_place_tag in_place(detail::in_place_of_t) { return in_place_tag(in_place_tag::init()); } - template - constexpr inline in_place_tag in_place(detail::in_place_of_i) { return in_place_tag(in_place_tag::init()); } - - using in_place_t = in_place_tag(&)(detail::in_place_of); - template - using in_place_type_t = in_place_tag(&)(detail::in_place_of_t); - template - using in_place_index_t = in_place_tag(&)(detail::in_place_of_i); - -} // sol - -// end of sol/in_place.hpp - -#if defined(SOL_USE_BOOST) -#include -#else -// beginning of sol/optional_implementation.hpp - -# ifndef SOL_OPTIONAL_IMPLEMENTATION_HPP -# define SOL_OPTIONAL_IMPLEMENTATION_HPP - -# include -# include -# include -# include -# include -# include -# include -#ifdef SOL_NO_EXCEPTIONS -#include -#endif // Exceptions - -# define TR2_OPTIONAL_REQUIRES(...) typename ::std::enable_if<__VA_ARGS__::value, bool>::type = false - -# if defined __GNUC__ // NOTE: GNUC is also defined for Clang -# if (__GNUC__ >= 5) -# define TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# endif -# endif -# -# if defined __clang_major__ -# if (__clang_major__ == 3 && __clang_minor__ >= 5) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# elif (__clang_major__ > 3) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# endif -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# endif -# endif -# -# if defined _MSC_VER -# if (_MSC_VER >= 1900) -# define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# endif -# endif - -# if defined __clang__ -# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif -# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif - -# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 -# define OPTIONAL_CONSTEXPR_INIT_LIST constexpr -# else -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 -# define OPTIONAL_CONSTEXPR_INIT_LIST -# endif - -# if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || (defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L)) -# define OPTIONAL_HAS_MOVE_ACCESSORS 1 -# else -# define OPTIONAL_HAS_MOVE_ACCESSORS 0 -# endif - -# // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr -# if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || ((defined __cplusplus) && (__cplusplus == 201103L)) -# define OPTIONAL_MUTABLE_CONSTEXPR -# else -# define OPTIONAL_MUTABLE_CONSTEXPR constexpr -# endif - -# if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -#pragma warning( push ) -#pragma warning( disable : 4814 ) -#endif - -namespace sol { - - // BEGIN workaround for missing is_trivially_destructible -# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it: it is already there -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - template - using is_trivially_destructible = ::std::has_trivial_destructor; -# endif - // END workaround for missing is_trivially_destructible - -# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - - template - struct is_nothrow_move_constructible - { - constexpr static bool value = ::std::is_nothrow_constructible::value; - }; - - template - struct is_assignable - { - template - constexpr static bool has_assign(...) { return false; } - - template () = ::std::declval(), true)) > - // the comma operator is necessary for the cases where operator= returns void - constexpr static bool has_assign(bool) { return true; } - - constexpr static bool value = has_assign(true); - }; - - template - struct is_nothrow_move_assignable - { - template - struct has_nothrow_move_assign { - constexpr static bool value = false; - }; - - template - struct has_nothrow_move_assign { - constexpr static bool value = noexcept(::std::declval() = ::std::declval()); - }; - - constexpr static bool value = has_nothrow_move_assign::value>::value; - }; - // end workaround - -# endif - - template class optional; - - // 20.5.5, optional for lvalue reference types - template class optional; - - // workaround: std utility functions aren't constexpr yet - template inline constexpr T&& constexpr_forward(typename ::std::remove_reference::type& t) noexcept - { - return static_cast(t); - } - - template inline constexpr T&& constexpr_forward(typename ::std::remove_reference::type&& t) noexcept - { - static_assert(!::std::is_lvalue_reference::value, "!!"); - return static_cast(t); - } - - template inline constexpr typename ::std::remove_reference::type&& constexpr_move(T&& t) noexcept - { - return static_cast::type&&>(t); - } - -#if defined NDEBUG -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) -#else -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR))) -#endif - - namespace detail_ - { - - // static_addressof: a constexpr version of addressof - template - struct has_overloaded_addressof - { - template - constexpr static bool has_overload(...) { return false; } - - template ().operator&()) > - constexpr static bool has_overload(bool) { return true; } - - constexpr static bool value = has_overload(true); - }; - - template )> - constexpr T* static_addressof(T& ref) - { - return &ref; - } - - template )> - T* static_addressof(T& ref) - { - return ::std::addressof(ref); - } - - // the call to convert(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A - template - constexpr U convert(U v) { return v; } - - } // namespace detail_ - - constexpr struct trivial_init_t {} trivial_init{}; - - // 20.5.7, Disengaged state indicator - struct nullopt_t - { - struct init {}; - constexpr explicit nullopt_t(init) {} - }; - constexpr nullopt_t nullopt{ nullopt_t::init() }; - - // 20.5.8, class bad_optional_access - class bad_optional_access : public ::std::logic_error { - public: - explicit bad_optional_access(const ::std::string& what_arg) : ::std::logic_error{ what_arg } {} - explicit bad_optional_access(const char* what_arg) : ::std::logic_error{ what_arg } {} - }; - - template - struct alignas(T) optional_base { - char storage_[sizeof(T)]; - bool init_; - - constexpr optional_base() noexcept : storage_(), init_(false) {}; - - explicit optional_base(const T& v) : storage_(), init_(true) { - new (&storage())T(v); - } - - explicit optional_base(T&& v) : storage_(), init_(true) { - new (&storage())T(constexpr_move(v)); - } - - template explicit optional_base(in_place_t, Args&&... args) - : init_(true), storage_() { - new (&storage())T(constexpr_forward(args)...); - } - - template >)> - explicit optional_base(in_place_t, ::std::initializer_list il, Args&&... args) - : init_(true), storage_() { - new (&storage())T(il, constexpr_forward(args)...); - } -#if defined __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - T& storage() { - return *reinterpret_cast(&storage_[0]); - } - - constexpr const T& storage() const { - return *reinterpret_cast(&storage_[0]); - } -#if defined __GNUC__ -#pragma GCC diagnostic pop -#endif - - ~optional_base() { if (init_) { storage().T::~T(); } } - }; - -#if defined __GNUC__ && !defined TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ - // Sorry, GCC 4.x; you're just a piece of shit - template - using constexpr_optional_base = optional_base; -#else - template - struct alignas(T) constexpr_optional_base { - char storage_[sizeof(T)]; - bool init_; - constexpr constexpr_optional_base() noexcept : storage_(), init_(false) {} - - explicit constexpr constexpr_optional_base(const T& v) : storage_(), init_(true) { - new (&storage())T(v); - } - - explicit constexpr constexpr_optional_base(T&& v) : storage_(), init_(true) { - new (&storage())T(constexpr_move(v)); - } - - template explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) - : init_(true), storage_() { - new (&storage())T(constexpr_forward(args)...); - } - - template >)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, ::std::initializer_list il, Args&&... args) - : init_(true), storage_() { - new (&storage())T(il, constexpr_forward(args)...); - } - -#if defined __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - T& storage() { - return (*reinterpret_cast(&storage_[0])); - } - - constexpr const T& storage() const { - return (*reinterpret_cast(&storage_[0])); - } -#if defined __GNUC__ -#pragma GCC diagnostic pop -#endif - - ~constexpr_optional_base() = default; - }; -#endif - - template - using OptionalBase = typename ::std::conditional< - ::std::is_trivially_destructible::value, - constexpr_optional_base::type>, - optional_base::type> - >::type; - - template - class optional : private OptionalBase - { - static_assert(!::std::is_same::type, nullopt_t>::value, "bad T"); - static_assert(!::std::is_same::type, in_place_t>::value, "bad T"); - - constexpr bool initialized() const noexcept { return OptionalBase::init_; } - typename ::std::remove_const::type* dataptr() { return ::std::addressof(OptionalBase::storage()); } - constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase::storage()); } - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - constexpr const T& contained_val() const& { return OptionalBase::storage(); } -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return ::std::move(OptionalBase::storage()); } - OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase::storage(); } -# else - T& contained_val() & { return OptionalBase::storage(); } - T&& contained_val() && { return ::std::move(OptionalBase::storage()); } -# endif -# else - constexpr const T& contained_val() const { return OptionalBase::storage(); } - T& contained_val() { return OptionalBase::storage(); } -# endif - - void clear() noexcept { - if (initialized()) dataptr()->T::~T(); - OptionalBase::init_ = false; - } - - template - void initialize(Args&&... args) noexcept(noexcept(T(::std::forward(args)...))) - { - assert(!OptionalBase::init_); - ::new (static_cast(dataptr())) T(::std::forward(args)...); - OptionalBase::init_ = true; - } - - template - void initialize(::std::initializer_list il, Args&&... args) noexcept(noexcept(T(il, ::std::forward(args)...))) - { - assert(!OptionalBase::init_); - ::new (static_cast(dataptr())) T(il, ::std::forward(args)...); - OptionalBase::init_ = true; - } - - public: - typedef T value_type; - - // 20.5.5.1, constructors - constexpr optional() noexcept : OptionalBase() {}; - constexpr optional(nullopt_t) noexcept : OptionalBase() {}; - - optional(const optional& rhs) - : OptionalBase() - { - if (rhs.initialized()) { - ::new (static_cast(dataptr())) T(*rhs); - OptionalBase::init_ = true; - } - } - - optional(const optional& rhs) : optional() - { - if (rhs) { - ::new (static_cast(dataptr())) T(*rhs); - OptionalBase::init_ = true; - } - } - - optional(optional&& rhs) noexcept(::std::is_nothrow_move_constructible::value) - : OptionalBase() - { - if (rhs.initialized()) { - ::new (static_cast(dataptr())) T(::std::move(*rhs)); - OptionalBase::init_ = true; - } - } - - constexpr optional(const T& v) : OptionalBase(v) {} - - constexpr optional(T&& v) : OptionalBase(constexpr_move(v)) {} - - template - explicit constexpr optional(in_place_t, Args&&... args) - : OptionalBase(in_place, constexpr_forward(args)...) {} - - template >)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, ::std::initializer_list il, Args&&... args) - : OptionalBase(in_place, il, constexpr_forward(args)...) {} - - // 20.5.4.2, Destructor - ~optional() = default; - - // 20.5.4.3, assignment - optional& operator=(nullopt_t) noexcept - { - clear(); - return *this; - } - - optional& operator=(const optional& rhs) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); - else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; - return *this; - } - - optional& operator=(optional&& rhs) - noexcept(::std::is_nothrow_move_assignable::value && ::std::is_nothrow_move_constructible::value) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(::std::move(*rhs)); - else if (initialized() == true && rhs.initialized() == true) contained_val() = ::std::move(*rhs); - return *this; - } - - template - auto operator=(U&& v) - -> typename ::std::enable_if - < - ::std::is_same::type, T>::value, - optional& - >::type - { - if (initialized()) { contained_val() = ::std::forward(v); } - else { initialize(::std::forward(v)); } - return *this; - } - - template - void emplace(Args&&... args) - { - clear(); - initialize(::std::forward(args)...); - } - - template - void emplace(::std::initializer_list il, Args&&... args) - { - clear(); - initialize(il, ::std::forward(args)...); - } - - // 20.5.4.4, Swap - void swap(optional& rhs) noexcept(::std::is_nothrow_move_constructible::value && noexcept(swap(::std::declval(), ::std::declval()))) - { - if (initialized() == true && rhs.initialized() == false) { rhs.initialize(::std::move(**this)); clear(); } - else if (initialized() == false && rhs.initialized() == true) { initialize(::std::move(*rhs)); rhs.clear(); } - else if (initialized() == true && rhs.initialized() == true) { using ::std::swap; swap(**this, *rhs); } - } - - // 20.5.4.5, Observers - - explicit constexpr operator bool() const noexcept { return initialized(); } - - constexpr T const* operator ->() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); - } - -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - - OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() { - assert(initialized()); - return dataptr(); - } - - constexpr T const& operator *() const& { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - - OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & { - assert(initialized()); - return contained_val(); - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && { - assert(initialized()); - return constexpr_move(contained_val()); - } - - constexpr T const& value() const& { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can't abort here - // because there's no constexpr abort - : *(T*)nullptr; -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - - OPTIONAL_MUTABLE_CONSTEXPR T& value() & { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - : *(T*)nullptr; -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can't abort here - // because there's no constexpr abort - : std::move(*(T*)nullptr); -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - -# else - - T* operator ->() { - assert(initialized()); - return dataptr(); - } - - constexpr T const& operator *() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - - T& operator *() { - assert(initialized()); - return contained_val(); - } - - constexpr T const& value() const { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can't abort here - // because there's no constexpr abort - : *(T*)nullptr; -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - - T& value() { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can abort here - // but the others are constexpr, so we can't... - : (std::abort(), *(T*)nullptr); -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - -# endif - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - - template - constexpr T value_or(V&& v) const& - { - return *this ? **this : detail_::convert(constexpr_forward(v)); - } - -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - - template - OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && - { - return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); - } - -# else - - template - T value_or(V&& v) && - { - return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); - } - -# endif - -# else - - template - constexpr T value_or(V&& v) const - { - return *this ? **this : detail_::convert(constexpr_forward(v)); - } - -# endif - - }; - - template - class optional - { - static_assert(!::std::is_same::value, "bad T"); - static_assert(!::std::is_same::value, "bad T"); - T* ref; - - public: - - // 20.5.5.1, construction/destruction - constexpr optional() noexcept : ref(nullptr) {} - - constexpr optional(nullopt_t) noexcept : ref(nullptr) {} - - constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {} - - optional(T&&) = delete; - - constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {} - - explicit constexpr optional(in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) {} - - explicit optional(in_place_t, T&&) = delete; - - ~optional() = default; - - // 20.5.5.2, mutation - optional& operator=(nullopt_t) noexcept { - ref = nullptr; - return *this; - } - - // optional& operator=(const optional& rhs) noexcept { - // ref = rhs.ref; - // return *this; - // } - - // optional& operator=(optional&& rhs) noexcept { - // ref = rhs.ref; - // return *this; - // } - - template - auto operator=(U&& rhs) noexcept - -> typename ::std::enable_if - < - ::std::is_same::type, optional>::value, - optional& - >::type - { - ref = rhs.ref; - return *this; - } - - template - auto operator=(U&& rhs) noexcept - -> typename ::std::enable_if - < - !::std::is_same::type, optional>::value, - optional& - >::type - = delete; - - void emplace(T& v) noexcept { - ref = detail_::static_addressof(v); - } - - void emplace(T&&) = delete; - - void swap(optional& rhs) noexcept - { - ::std::swap(ref, rhs.ref); - } - - // 20.5.5.3, observers - constexpr T* operator->() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref); - } - - constexpr T& operator*() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref); - } - - constexpr T& value() const { -#ifdef SOL_NO_EXCEPTIONS - return *ref; -#else - return ref ? *ref - : (throw bad_optional_access("bad optional access"), *ref); -#endif // Exceptions - } - - explicit constexpr operator bool() const noexcept { - return ref != nullptr; - } - - template - constexpr T& value_or(V&& v) const - { - return *this ? **this : detail_::convert(constexpr_forward(v)); - } - }; - - template - class optional - { - static_assert(sizeof(T) == 0, "optional rvalue references disallowed"); - }; - - // 20.5.8, Relational operators - template constexpr bool operator==(const optional& x, const optional& y) - { - return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y; - } - - template constexpr bool operator!=(const optional& x, const optional& y) - { - return !(x == y); - } - - template constexpr bool operator<(const optional& x, const optional& y) - { - return (!y) ? false : (!x) ? true : *x < *y; - } - - template constexpr bool operator>(const optional& x, const optional& y) - { - return (y < x); - } - - template constexpr bool operator<=(const optional& x, const optional& y) - { - return !(y < x); - } - - template constexpr bool operator>=(const optional& x, const optional& y) - { - return !(x < y); - } - - // 20.5.9, Comparison with nullopt - template constexpr bool operator==(const optional& x, nullopt_t) noexcept - { - return (!x); - } - - template constexpr bool operator==(nullopt_t, const optional& x) noexcept - { - return (!x); - } - - template constexpr bool operator!=(const optional& x, nullopt_t) noexcept - { - return bool(x); - } - - template constexpr bool operator!=(nullopt_t, const optional& x) noexcept - { - return bool(x); - } - - template constexpr bool operator<(const optional&, nullopt_t) noexcept - { - return false; - } - - template constexpr bool operator<(nullopt_t, const optional& x) noexcept - { - return bool(x); - } - - template constexpr bool operator<=(const optional& x, nullopt_t) noexcept - { - return (!x); - } - - template constexpr bool operator<=(nullopt_t, const optional&) noexcept - { - return true; - } - - template constexpr bool operator>(const optional& x, nullopt_t) noexcept - { - return bool(x); - } - - template constexpr bool operator>(nullopt_t, const optional&) noexcept - { - return false; - } - - template constexpr bool operator>=(const optional&, nullopt_t) noexcept - { - return true; - } - - template constexpr bool operator>=(nullopt_t, const optional& x) noexcept - { - return (!x); - } - - // 20.5.10, Comparison with T - template constexpr bool operator==(const optional& x, const T& v) - { - return bool(x) ? *x == v : false; - } - - template constexpr bool operator==(const T& v, const optional& x) - { - return bool(x) ? v == *x : false; - } - - template constexpr bool operator!=(const optional& x, const T& v) - { - return bool(x) ? *x != v : true; - } - - template constexpr bool operator!=(const T& v, const optional& x) - { - return bool(x) ? v != *x : true; - } - - template constexpr bool operator<(const optional& x, const T& v) - { - return bool(x) ? *x < v : true; - } - - template constexpr bool operator>(const T& v, const optional& x) - { - return bool(x) ? v > *x : true; - } - - template constexpr bool operator>(const optional& x, const T& v) - { - return bool(x) ? *x > v : false; - } - - template constexpr bool operator<(const T& v, const optional& x) - { - return bool(x) ? v < *x : false; - } - - template constexpr bool operator>=(const optional& x, const T& v) - { - return bool(x) ? *x >= v : false; - } - - template constexpr bool operator<=(const T& v, const optional& x) - { - return bool(x) ? v <= *x : false; - } - - template constexpr bool operator<=(const optional& x, const T& v) - { - return bool(x) ? *x <= v : true; - } - - template constexpr bool operator>=(const T& v, const optional& x) - { - return bool(x) ? v >= *x : true; - } - - // Comparison of optional with T - template constexpr bool operator==(const optional& x, const T& v) - { - return bool(x) ? *x == v : false; - } - - template constexpr bool operator==(const T& v, const optional& x) - { - return bool(x) ? v == *x : false; - } - - template constexpr bool operator!=(const optional& x, const T& v) - { - return bool(x) ? *x != v : true; - } - - template constexpr bool operator!=(const T& v, const optional& x) - { - return bool(x) ? v != *x : true; - } - - template constexpr bool operator<(const optional& x, const T& v) - { - return bool(x) ? *x < v : true; - } - - template constexpr bool operator>(const T& v, const optional& x) - { - return bool(x) ? v > *x : true; - } - - template constexpr bool operator>(const optional& x, const T& v) - { - return bool(x) ? *x > v : false; - } - - template constexpr bool operator<(const T& v, const optional& x) - { - return bool(x) ? v < *x : false; - } - - template constexpr bool operator>=(const optional& x, const T& v) - { - return bool(x) ? *x >= v : false; - } - - template constexpr bool operator<=(const T& v, const optional& x) - { - return bool(x) ? v <= *x : false; - } - - template constexpr bool operator<=(const optional& x, const T& v) - { - return bool(x) ? *x <= v : true; - } - - template constexpr bool operator>=(const T& v, const optional& x) - { - return bool(x) ? v >= *x : true; - } - - // Comparison of optional with T - template constexpr bool operator==(const optional& x, const T& v) - { - return bool(x) ? *x == v : false; - } - - template constexpr bool operator==(const T& v, const optional& x) - { - return bool(x) ? v == *x : false; - } - - template constexpr bool operator!=(const optional& x, const T& v) - { - return bool(x) ? *x != v : true; - } - - template constexpr bool operator!=(const T& v, const optional& x) - { - return bool(x) ? v != *x : true; - } - - template constexpr bool operator<(const optional& x, const T& v) - { - return bool(x) ? *x < v : true; - } - - template constexpr bool operator>(const T& v, const optional& x) - { - return bool(x) ? v > *x : true; - } - - template constexpr bool operator>(const optional& x, const T& v) - { - return bool(x) ? *x > v : false; - } - - template constexpr bool operator<(const T& v, const optional& x) - { - return bool(x) ? v < *x : false; - } - - template constexpr bool operator>=(const optional& x, const T& v) - { - return bool(x) ? *x >= v : false; - } - - template constexpr bool operator<=(const T& v, const optional& x) - { - return bool(x) ? v <= *x : false; - } - - template constexpr bool operator<=(const optional& x, const T& v) - { - return bool(x) ? *x <= v : true; - } - - template constexpr bool operator>=(const T& v, const optional& x) - { - return bool(x) ? v >= *x : true; - } - - // 20.5.12, Specialized algorithms - template - void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))) { - x.swap(y); - } - - template - constexpr optional::type> make_optional(T&& v) { - return optional::type>(constexpr_forward(v)); - } - - template - constexpr optional make_optional(::std::reference_wrapper v) { - return optional(v.get()); - } - -} // namespace - -namespace std -{ - template - struct hash> { - typedef typename hash::result_type result_type; - typedef sol::optional argument_type; - - constexpr result_type operator()(argument_type const& arg) const { - return arg ? ::std::hash{}(*arg) : result_type{}; - } - }; - - template - struct hash> { - typedef typename hash::result_type result_type; - typedef sol::optional argument_type; - - constexpr result_type operator()(argument_type const& arg) const { - return arg ? ::std::hash{}(*arg) : result_type{}; - } - }; -} - -# if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -#pragma warning( pop ) -#endif - -# undef TR2_OPTIONAL_REQUIRES -# undef TR2_OPTIONAL_ASSERTED_EXPRESSION - -# endif // SOL_OPTIONAL_IMPLEMENTATION_HPP -// end of sol/optional_implementation.hpp - -#endif // Boost vs. Better optional - -namespace sol { - -#if defined(SOL_USE_BOOST) - template - using optional = boost::optional; - using nullopt_t = boost::none_t; - const nullopt_t nullopt = boost::none; -#endif // Boost vs. Better optional - - namespace meta { - template - struct is_optional : std::false_type {}; - template - struct is_optional> : std::true_type {}; - } // meta -} // sol - -// end of sol/optional.hpp - -// beginning of sol/string_shim.hpp - -namespace sol { - namespace string_detail { - struct string_shim { - std::size_t s; - const char* p; - - string_shim(const std::string& r) : string_shim(r.data(), r.size()) {} - string_shim(const char* ptr) : string_shim(ptr, std::char_traits::length(ptr)) {} - string_shim(const char* ptr, std::size_t sz) : s(sz), p(ptr) {} - - static int compare(const char* lhs_p, std::size_t lhs_sz, const char* rhs_p, std::size_t rhs_sz) { - int result = std::char_traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz); - if (result != 0) - return result; - if (lhs_sz < rhs_sz) - return -1; - if (lhs_sz > rhs_sz) - return 1; - return 0; - } - - const char* c_str() const { - return p; - } - - const char* data() const { - return p; - } - - std::size_t size() const { - return s; - } - - bool operator==(const string_shim& r) const { - return compare(p, s, r.data(), r.size()) == 0; - } - - bool operator==(const char* r) const { - return compare(r, std::char_traits::length(r), p, s) == 0; - } - - bool operator==(const std::string& r) const { - return compare(r.data(), r.size(), p, s) == 0; - } - - bool operator!=(const string_shim& r) const { - return !(*this == r); - } - - bool operator!=(const char* r) const { - return !(*this == r); - } - - bool operator!=(const std::string& r) const { - return !(*this == r); - } - }; - } -} - -// end of sol/string_shim.hpp - -#include - -namespace sol { - namespace detail { -#ifdef SOL_NO_EXCEPTIONS - template - int static_trampoline(lua_State* L) { - return f(L); - } - - template - int trampoline(lua_State* L, Fx&& f, Args&&... args) { - return f(L, std::forward(args)...); - } - - inline int c_trampoline(lua_State* L, lua_CFunction f) { - return trampoline(L, f); - } -#else - template - int static_trampoline(lua_State* L) { - try { - return f(L); - } - catch (const char *s) { - lua_pushstring(L, s); - } - catch (const std::exception& e) { - lua_pushstring(L, e.what()); - } -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) - catch (...) { - std::exception_ptr eptr = std::current_exception(); - lua_pushstring(L, "caught (...) exception"); - } -#endif - return lua_error(L); - } - - template - int trampoline(lua_State* L, Fx&& f, Args&&... args) { - try { - return f(L, std::forward(args)...); - } - catch (const char *s) { - lua_pushstring(L, s); - } - catch (const std::exception& e) { - lua_pushstring(L, e.what()); - } -#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) - catch (...) { - lua_pushstring(L, "caught (...) exception"); - } -#endif - return lua_error(L); - } - - inline int c_trampoline(lua_State* L, lua_CFunction f) { - return trampoline(L, f); - } -#endif // Exceptions vs. No Exceptions - - template - struct unique_usertype {}; - - template - struct implicit_wrapper { - T& item; - implicit_wrapper(T* item) : item(*item) {} - implicit_wrapper(T& item) : item(item) {} - operator T& () { - return item; - } - operator T* () { - return std::addressof(item); - } - }; - - struct unchecked_t {}; - const unchecked_t unchecked = unchecked_t{}; - } // detail - - struct lua_nil_t {}; - const lua_nil_t lua_nil{}; - inline bool operator==(lua_nil_t, lua_nil_t) { return true; } - inline bool operator!=(lua_nil_t, lua_nil_t) { return false; } -#ifndef __OBJC__ - typedef lua_nil_t nil_t; - const nil_t nil{}; -#endif - - struct metatable_t {}; - const metatable_t metatable_key = {}; - - struct env_t {}; - const env_t env_key = {}; - - struct no_metatable_t {}; - const no_metatable_t no_metatable = {}; - - typedef std::remove_pointer_t lua_r_CFunction; - - template - struct unique_usertype_traits { - typedef T type; - typedef T actual_type; - static const bool value = false; - - template - static bool is_null(U&&) { - return false; - } - - template - static auto get(U&& value) { - return std::addressof(detail::deref(value)); - } - }; - - template - struct unique_usertype_traits> { - typedef T type; - typedef std::shared_ptr actual_type; - static const bool value = true; - - static bool is_null(const actual_type& p) { - return p == nullptr; - } - - static type* get(const actual_type& p) { - return p.get(); - } - }; - - template - struct unique_usertype_traits> { - typedef T type; - typedef std::unique_ptr actual_type; - static const bool value = true; - - static bool is_null(const actual_type& p) { - return p == nullptr; - } - - static type* get(const actual_type& p) { - return p.get(); - } - }; - - template - struct non_null {}; - - template - struct function_sig {}; - - struct upvalue_index { - int index; - upvalue_index(int idx) : index(lua_upvalueindex(idx)) { - - } - - operator int() const { - return index; - } - }; - - struct raw_index { - int index; - raw_index(int i) : index(i) { - - } - - operator int() const { - return index; - } - }; - - struct absolute_index { - int index; - absolute_index(lua_State* L, int idx) : index(lua_absindex(L, idx)) { - - } - - operator int() const { - return index; - } - }; - - struct ref_index { - int index; - ref_index(int idx) : index(idx) { - - } - - operator int() const { - return index; - } - }; - - struct lightuserdata_value { - void* value; - lightuserdata_value(void* data) : value(data) {} - operator void*() const { return value; } - }; - - struct userdata_value { - void* value; - userdata_value(void* data) : value(data) {} - operator void*() const { return value; } - }; - - template - struct light { - L* value; - - light(L& x) : value(std::addressof(x)) {} - light(L* x) : value(x) {} - light(void* x) : value(static_cast(x)) {} - operator L* () const { return value; } - operator L& () const { return *value; } - }; - - template - auto make_light(T& l) { - typedef meta::unwrapped_t>> L; - return light(l); - } - - template - struct user { - U value; - - user(U x) : value(std::move(x)) {} - operator U* () { return std::addressof(value); } - operator U& () { return value; } - operator const U& () const { return value; } - }; - - template - auto make_user(T&& u) { - typedef meta::unwrapped_t> U; - return user(std::forward(u)); - } - - template - struct metatable_registry_key { - T key; - - metatable_registry_key(T key) : key(std::forward(key)) {} - }; - - template - auto meta_registry_key(T&& key) { - typedef meta::unqualified_t K; - return metatable_registry_key(std::forward(key)); - } - - template - struct closure { - lua_CFunction c_function; - std::tuple upvalues; - closure(lua_CFunction f, Upvalues... targetupvalues) : c_function(f), upvalues(std::forward(targetupvalues)...) {} - }; - - template <> - struct closure<> { - lua_CFunction c_function; - int upvalues; - closure(lua_CFunction f, int upvalue_count = 0) : c_function(f), upvalues(upvalue_count) {} - }; - - typedef closure<> c_closure; - - template - closure make_closure(lua_CFunction f, Args&&... args) { - return closure(f, std::forward(args)...); - } - - template - struct function_arguments { - std::tuple arguments; - template , function_arguments>> = meta::enabler> - function_arguments(Arg&& arg, Args&&... args) : arguments(std::forward(arg), std::forward(args)...) {} - }; - - template , typename... Args> - auto as_function(Args&&... args) { - return function_arguments...>(std::forward(args)...); - } - - template , typename... Args> - auto as_function_reference(Args&&... args) { - return function_arguments(std::forward(args)...); - } - - template - struct as_table_t { - T source; - template - as_table_t(Args&&... args) : source(std::forward(args)...) {} - - operator std::add_lvalue_reference_t () { - return source; - } - }; - - template - struct nested { - T source; - - template - nested(Args&&... args) : source(std::forward(args)...) {} - - operator std::add_lvalue_reference_t() { - return source; - } - }; - - template - as_table_t as_table(T&& container) { - return as_table_t(std::forward(container)); - } - - struct this_state { - lua_State* L; - operator lua_State* () const { - return L; - } - lua_State* operator-> () const { - return L; - } - }; - - struct new_table { - int sequence_hint = 0; - int map_hint = 0; - - new_table() = default; - new_table(const new_table&) = default; - new_table(new_table&&) = default; - new_table& operator=(const new_table&) = default; - new_table& operator=(new_table&&) = default; - - new_table(int sequence_hint, int map_hint = 0) : sequence_hint(sequence_hint), map_hint(map_hint) {} - }; - - enum class call_syntax { - dot = 0, - colon = 1 - }; - - enum class call_status : int { - ok = LUA_OK, - yielded = LUA_YIELD, - runtime = LUA_ERRRUN, - memory = LUA_ERRMEM, - handler = LUA_ERRERR, - gc = LUA_ERRGCMM, - syntax = LUA_ERRSYNTAX, - file = LUA_ERRFILE, - }; - - enum class thread_status : int { - ok = LUA_OK, - yielded = LUA_YIELD, - runtime = LUA_ERRRUN, - memory = LUA_ERRMEM, - gc = LUA_ERRGCMM, - handler = LUA_ERRERR, - dead = -1, - }; - - enum class load_status : int { - ok = LUA_OK, - syntax = LUA_ERRSYNTAX, - memory = LUA_ERRMEM, - gc = LUA_ERRGCMM, - file = LUA_ERRFILE, - }; - - enum class type : int { - none = LUA_TNONE, - lua_nil = LUA_TNIL, -#ifndef __OBJC__ - nil = lua_nil, -#endif // Objective C++ Keyword - string = LUA_TSTRING, - number = LUA_TNUMBER, - thread = LUA_TTHREAD, - boolean = LUA_TBOOLEAN, - function = LUA_TFUNCTION, - userdata = LUA_TUSERDATA, - lightuserdata = LUA_TLIGHTUSERDATA, - table = LUA_TTABLE, - poly = none | lua_nil | string | number | thread | - table | boolean | function | userdata | lightuserdata - }; - - inline const std::string& to_string(call_status c) { - static const std::array names{{ - "ok", - "yielded", - "runtime", - "memory", - "handler", - "gc", - "syntax", - "file", - }}; - switch (c) { - case call_status::ok: - return names[0]; - case call_status::yielded: - return names[1]; - case call_status::runtime: - return names[2]; - case call_status::memory: - return names[3]; - case call_status::handler: - return names[4]; - case call_status::gc: - return names[5]; - case call_status::syntax: - return names[6]; - case call_status::file: - return names[7]; - } - return names[0]; - } - - inline const std::string& to_string(load_status c) { - static const std::array names{ { - "ok", - "memory", - "gc", - "syntax", - "file", - } }; - switch (c) { - case load_status::ok: - return names[0]; - case load_status::memory: - return names[1]; - case load_status::gc: - return names[2]; - case load_status::syntax: - return names[3]; - case load_status::file: - return names[4]; - } - return names[0]; - } - - enum class meta_function { - construct, - index, - new_index, - mode, - call, - call_function = call, - metatable, - to_string, - length, - unary_minus, - addition, - subtraction, - multiplication, - division, - modulus, - power_of, - involution = power_of, - concatenation, - equal_to, - less_than, - less_than_or_equal_to, - garbage_collect, - floor_division, - bitwise_left_shift, - bitwise_right_shift, - bitwise_not, - bitwise_and, - bitwise_or, - bitwise_xor, - pairs, - next - }; - - typedef meta_function meta_method; - - inline const std::array& meta_function_names() { - static const std::array names = { { - "new", - "__index", - "__newindex", - "__mode", - "__call", - "__mt", - "__tostring", - "__len", - "__unm", - "__add", - "__sub", - "__mul", - "__div", - "__mod", - "__pow", - "__concat", - "__eq", - "__lt", - "__le", - "__gc", - - "__idiv", - "__shl", - "__shr", - "__bnot", - "__band", - "__bor", - "__bxor", - - "__pairs", - "__next" - } }; - return names; - } - - inline const std::string& to_string(meta_function mf) { - return meta_function_names()[static_cast(mf)]; - } - - inline type type_of(lua_State* L, int index) { - return static_cast(lua_type(L, index)); - } - - inline int type_panic(lua_State* L, int index, type expected, type actual) noexcept(false) { - return luaL_error(L, "stack index %d, expected %s, received %s", index, - expected == type::poly ? "anything" : lua_typename(L, static_cast(expected)), - expected == type::poly ? "anything" : lua_typename(L, static_cast(actual)) - ); - } - - // Specify this function as the handler for lua::check if you know there's nothing wrong - inline int no_panic(lua_State*, int, type, type) noexcept { - return 0; - } - - inline void type_error(lua_State* L, int expected, int actual) noexcept(false) { - luaL_error(L, "expected %s, received %s", lua_typename(L, expected), lua_typename(L, actual)); - } - - inline void type_error(lua_State* L, type expected, type actual) noexcept(false) { - type_error(L, static_cast(expected), static_cast(actual)); - } - - inline void type_assert(lua_State* L, int index, type expected, type actual) noexcept(false) { - if (expected != type::poly && expected != actual) { - type_panic(L, index, expected, actual); - } - } - - inline void type_assert(lua_State* L, int index, type expected) { - type actual = type_of(L, index); - type_assert(L, index, expected, actual); - } - - inline std::string type_name(lua_State* L, type t) { - return lua_typename(L, static_cast(t)); - } - - class reference; - class stack_reference; - template - struct proxy; - template - class usertype; - template - class basic_table_core; - template - using table_core = basic_table_core; - template - using stack_table_core = basic_table_core; - template - using basic_table = basic_table_core; - typedef table_core table; - typedef table_core global_table; - typedef stack_table_core stack_table; - typedef stack_table_core stack_global_table; - template - struct basic_environment; - using environment = basic_environment; - using stack_environment = basic_environment; - template - class basic_function; - template - class basic_protected_function; - using protected_function = basic_protected_function; - using stack_protected_function = basic_protected_function; - using unsafe_function = basic_function; - using safe_function = basic_protected_function; - using stack_unsafe_function = basic_function; - using stack_safe_function = basic_protected_function; -#ifdef SOL_SAFE_FUNCTIONS - using function = protected_function; - using stack_function = stack_protected_function; -#else - using function = unsafe_function; - using stack_function = stack_unsafe_function; -#endif - template - class basic_object; - template - class basic_userdata; - template - class basic_lightuserdata; - struct variadic_args; - using object = basic_object; - using stack_object = basic_object; - using userdata = basic_userdata; - using stack_userdata = basic_userdata; - using lightuserdata = basic_lightuserdata; - using stack_lightuserdata = basic_lightuserdata; - class coroutine; - class thread; - struct variadic_args; - struct this_state; - struct this_environment; - - namespace detail { - template - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template - struct lua_type_of> : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template - struct lua_type_of> : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template <> - struct lua_type_of : std::integral_constant { }; - - template - struct lua_type_of> : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of::value>> : std::integral_constant {}; - - template - struct lua_type_of::value>> : std::integral_constant {}; - - template - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template - struct is_container>::value>> : std::true_type {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template class V, typename... Args> - struct accumulate : std::integral_constant {}; - - template class V, typename T, typename... Args> - struct accumulate : accumulate::value, V, Args...> {}; - } // detail - - template - struct is_unique_usertype : std::integral_constant::value> {}; - - template - struct lua_type_of : detail::lua_type_of { - typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_; - }; - - template - struct lua_size : std::integral_constant { - typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_; - }; - - template - struct lua_size> : std::integral_constant::value + lua_size::value> { }; - - template - struct lua_size> : std::integral_constant::value> { }; - - namespace detail { - template - struct void_ { typedef void type; }; - template - struct has_internal_marker_impl : std::false_type {}; - template - struct has_internal_marker_impl::type> : std::true_type {}; - - template - struct has_internal_marker : has_internal_marker_impl {}; - } - - template - struct is_lua_primitive : std::integral_constant>::value - || ((type::userdata == lua_type_of>::value) - && detail::has_internal_marker>>::value - && !detail::has_internal_marker>>::value) - || std::is_base_of>::value - || std::is_base_of>::value - || meta::is_specialization_of>::value - || meta::is_specialization_of>::value - > { }; - - template - struct is_lua_reference : std::integral_constant>::value - || std::is_base_of>::value - || meta::is_specialization_of>::value - > { }; - - template - struct is_lua_primitive : std::true_type {}; - template - struct is_lua_primitive> : std::true_type { }; - template - struct is_lua_primitive> : std::true_type { }; - template - struct is_lua_primitive> : is_lua_primitive { }; - template - struct is_lua_primitive> : std::true_type {}; - template <> - struct is_lua_primitive : std::true_type {}; - template <> - struct is_lua_primitive : std::true_type {}; - template - struct is_lua_primitive> : is_lua_primitive {}; - - template - struct is_proxy_primitive : is_lua_primitive { }; - - template - struct is_transparent_argument : std::false_type {}; - - template <> - struct is_transparent_argument : std::true_type {}; - - template <> - struct is_transparent_argument : std::true_type {}; - - template <> - struct is_transparent_argument : std::true_type {}; - - template - struct is_variadic_arguments : std::is_same {}; - - template - struct lua_bind_traits : meta::bind_traits { - private: - typedef meta::bind_traits base_t; - public: - typedef std::integral_constant::value != 0> runtime_variadics_t; - static const std::size_t true_arity = base_t::arity; - static const std::size_t arity = base_t::arity - meta::count_for::value; - static const std::size_t true_free_arity = base_t::free_arity; - static const std::size_t free_arity = base_t::free_arity - meta::count_for::value; - }; - - template - struct is_table : std::false_type {}; - template - struct is_table> : std::true_type {}; - - template - struct is_function : std::false_type {}; - template - struct is_function> : std::true_type {}; - template - struct is_function> : std::true_type {}; - - template - struct is_lightuserdata : std::false_type {}; - template - struct is_lightuserdata> : std::true_type {}; - - template - struct is_userdata : std::false_type {}; - template - struct is_userdata> : std::true_type {}; - - template - struct is_environment : std::integral_constant::value || is_table::value> {}; - - template - struct is_container : detail::is_container{}; - - template - inline type type_of() { - return lua_type_of>::value; - } - - namespace detail { - template - struct lua_type_of, std::enable_if_t<::sol::is_container::value>> : std::integral_constant {}; - - template - struct lua_type_of, std::enable_if_t::value>> : lua_type_of {}; - } // detail -} // sol - -// end of sol/types.hpp - -// beginning of sol/stack_reference.hpp - -namespace sol { - class stack_reference { - private: - lua_State* L = nullptr; - int index = 0; - - protected: - int registry_index() const noexcept { - return LUA_NOREF; - } - - public: - stack_reference() noexcept = default; - stack_reference(lua_nil_t) noexcept : stack_reference() {}; - stack_reference(lua_State* L, int i) noexcept : L(L), index(lua_absindex(L, i)) {} - stack_reference(lua_State* L, absolute_index i) noexcept : L(L), index(i) {} - stack_reference(lua_State* L, raw_index i) noexcept : L(L), index(i) {} - stack_reference(lua_State* L, ref_index i) noexcept = delete; - stack_reference(stack_reference&& o) noexcept = default; - stack_reference& operator=(stack_reference&&) noexcept = default; - stack_reference(const stack_reference&) noexcept = default; - stack_reference& operator=(const stack_reference&) noexcept = default; - - int push() const noexcept { - return push(lua_state()); - } - - int push(lua_State* Ls) const noexcept { - lua_pushvalue(lua_state(), index); - if (Ls != lua_state()) { - lua_xmove(lua_state(), Ls, 1); - } - return 1; - } - - void pop() const noexcept { - pop(lua_state()); - } - - void pop(lua_State* Ls, int n = 1) const noexcept { - lua_pop(Ls, n); - } - - int stack_index() const noexcept { - return index; - } - - type get_type() const noexcept { - int result = lua_type(L, index); - return static_cast(result); - } - - lua_State* lua_state() const noexcept { - return L; - } - - bool valid() const noexcept { - type t = get_type(); - return t != type::lua_nil && t != type::none; - } - }; - - inline bool operator== (const stack_reference& l, const stack_reference& r) { - return lua_compare(l.lua_state(), l.stack_index(), r.stack_index(), LUA_OPEQ) == 0; - } - - inline bool operator!= (const stack_reference& l, const stack_reference& r) { - return !operator==(l, r); - } - - inline bool operator==(const stack_reference& lhs, const lua_nil_t&) { - return !lhs.valid(); - } - - inline bool operator==(const lua_nil_t&, const stack_reference& rhs) { - return !rhs.valid(); - } - - inline bool operator!=(const stack_reference& lhs, const lua_nil_t&) { - return lhs.valid(); - } - - inline bool operator!=(const lua_nil_t&, const stack_reference& rhs) { - return rhs.valid(); - } -} // sol - -// end of sol/stack_reference.hpp - -namespace sol { - namespace stack { - inline void remove(lua_State* L, int rawindex, int count) { - if (count < 1) - return; - int top = lua_gettop(L); - if (rawindex == -count || top == rawindex) { - // Slice them right off the top - lua_pop(L, static_cast(count)); - return; - } - - // Remove each item one at a time using stack operations - // Probably slower, maybe, haven't benchmarked, - // but necessary - int index = lua_absindex(L, rawindex); - if (index < 0) { - index = lua_gettop(L) + (index + 1); - } - int last = index + count; - for (int i = index; i < last; ++i) { - lua_remove(L, index); - } - } - - struct push_popper_at { - lua_State* L; - int index; - int count; - push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) { } - ~push_popper_at() { remove(L, index, count); } - }; - - template - struct push_popper_n { - lua_State* L; - int t; - push_popper_n(lua_State* luastate, int x) : L(luastate), t(x) { } - ~push_popper_n() { lua_pop(L, t); } - }; - template <> - struct push_popper_n { - push_popper_n(lua_State*, int) { } - }; - template - struct push_popper { - T t; - push_popper(T x) : t(x) { t.push(); } - ~push_popper() { t.pop(); } - }; - template - struct push_popper { - push_popper(T) {} - ~push_popper() {} - }; - template - push_popper push_pop(T&& x) { - return push_popper(std::forward(x)); - } - template - push_popper_at push_pop_at(T&& x) { - int c = x.push(); - lua_State* L = x.lua_state(); - return push_popper_at(L, lua_absindex(L, -c), c); - } - template - push_popper_n pop_n(lua_State* L, int x) { - return push_popper_n(L, x); - } - } // stack - - namespace detail { - struct global_tag { } const global_{}; - struct no_safety_tag {} const no_safety{}; - } // detail - - class reference { - private: - lua_State* luastate = nullptr; // non-owning - int ref = LUA_NOREF; - - int copy() const noexcept { - if (ref == LUA_NOREF) - return LUA_NOREF; - push(); - return luaL_ref(lua_state(), LUA_REGISTRYINDEX); - } - - protected: - reference(lua_State* L, detail::global_tag) noexcept : luastate(L) { - lua_pushglobaltable(lua_state()); - ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); - } - - int stack_index() const noexcept { - return -1; - } - - void deref() const noexcept { - luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref); - } - - public: - reference() noexcept = default; - reference(lua_nil_t) noexcept : reference() {} - reference(const stack_reference& r) noexcept : reference(r.lua_state(), r.stack_index()) {} - reference(stack_reference&& r) noexcept : reference(r.lua_state(), r.stack_index()) {} - reference(lua_State* L, int index = -1) noexcept : luastate(L) { - lua_pushvalue(lua_state(), index); - ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); - } - reference(lua_State* L, ref_index index) noexcept : luastate(L) { - lua_rawgeti(L, LUA_REGISTRYINDEX, index.index); - ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); - } - - ~reference() noexcept { - deref(); - } - - reference(reference&& o) noexcept { - luastate = o.luastate; - ref = o.ref; - - o.luastate = nullptr; - o.ref = LUA_NOREF; - } - - reference& operator=(reference&& o) noexcept { - if (valid()) { - deref(); - } - luastate = o.luastate; - ref = o.ref; - - o.luastate = nullptr; - o.ref = LUA_NOREF; - - return *this; - } - - reference(const reference& o) noexcept { - luastate = o.luastate; - ref = o.copy(); - } - - reference& operator=(const reference& o) noexcept { - luastate = o.luastate; - deref(); - ref = o.copy(); - return *this; - } - - int push() const noexcept { - return push(lua_state()); - } - - int push(lua_State* Ls) const noexcept { - lua_rawgeti(Ls, LUA_REGISTRYINDEX, ref); - return 1; - } - - void pop() const noexcept { - pop(lua_state()); - } - - void pop(lua_State* Ls, int n = 1) const noexcept { - lua_pop(Ls, n); - } - - int registry_index() const noexcept { - return ref; - } - - bool valid() const noexcept { - return !(ref == LUA_NOREF || ref == LUA_REFNIL); - } - - explicit operator bool() const noexcept { - return valid(); - } - - type get_type() const noexcept { - auto pp = stack::push_pop(*this); - int result = lua_type(lua_state(), -1); - return static_cast(result); - } - - lua_State* lua_state() const noexcept { - return luastate; - } - }; - - inline bool operator== (const reference& l, const reference& r) { - auto ppl = stack::push_pop(l); - auto ppr = stack::push_pop(r); - return lua_compare(l.lua_state(), -1, -2, LUA_OPEQ) == 1; - } - - inline bool operator!= (const reference& l, const reference& r) { - return !operator==(l, r); - } - - inline bool operator==(const reference& lhs, const lua_nil_t&) { - return !lhs.valid(); - } - - inline bool operator==(const lua_nil_t&, const reference& rhs) { - return !rhs.valid(); - } - - inline bool operator!=(const reference& lhs, const lua_nil_t&) { - return lhs.valid(); - } - - inline bool operator!=(const lua_nil_t&, const reference& rhs) { - return rhs.valid(); - } -} // sol - -// end of sol/reference.hpp - -// beginning of sol/stack.hpp - -// beginning of sol/stack_core.hpp - -// beginning of sol/tie.hpp - -namespace sol { - - namespace detail { - template - struct is_speshul : std::false_type {}; - } - - template - struct tie_size : std::tuple_size {}; - - template - struct is_tieable : std::integral_constant::value > 0)> {}; - - template - struct tie_t : public std::tuple...> { - private: - typedef std::tuple...> base_t; - - template - void set(std::false_type, T&& target) { - std::get<0>(*this) = std::forward(target); - } - - template - void set(std::true_type, T&& target) { - typedef tie_size> value_size; - typedef tie_size> tie_size; - typedef std::conditional_t<(value_size::value < tie_size::value), value_size, tie_size> indices_size; - typedef std::make_index_sequence indices; - set_extra(detail::is_speshul>(), indices(), std::forward(target)); - } - - template - void set_extra(std::true_type, std::index_sequence, T&& target) { - using std::get; - (void)detail::swallow{ 0, - (get(static_cast(*this)) = get(types(), target), 0)... - , 0 }; - } - - template - void set_extra(std::false_type, std::index_sequence, T&& target) { - using std::get; - (void)detail::swallow{ 0, - (get(static_cast(*this)) = get(target), 0)... - , 0 }; - } - - public: - using base_t::base_t; - - template - tie_t& operator= (T&& value) { - typedef is_tieable> tieable; - set(tieable(), std::forward(value)); - return *this; - } - - }; - - template - struct tie_size< tie_t > : std::tuple_size< std::tuple > { }; - - namespace adl_barrier_detail { - template - inline tie_t...> tie(Tn&&... argn) { - return tie_t...>(std::forward(argn)...); - } - } - - using namespace adl_barrier_detail; - -} // sol - -// end of sol/tie.hpp - -// beginning of sol/stack_guard.hpp - -namespace sol { - namespace detail { - inline void stack_fail(int, int) { -#ifndef SOL_NO_EXCEPTIONS - throw error(detail::direct_error, "imbalanced stack after operation finish"); -#else - // Lol, what do you want, an error printout? :3c - // There's no sane default here. The right way would be C-style abort(), and that's not acceptable, so - // hopefully someone will register their own stack_fail thing for the `fx` parameter of stack_guard. -#endif // No Exceptions - } - } // detail - - struct stack_guard { - lua_State* L; - int top; - std::function on_mismatch; - - stack_guard(lua_State* L) : stack_guard(L, lua_gettop(L)) {} - stack_guard(lua_State* L, int top, std::function fx = detail::stack_fail) : L(L), top(top), on_mismatch(std::move(fx)) {} - bool check_stack(int modification = 0) const { - int bottom = lua_gettop(L) + modification; - if (top == bottom) { - return true; - } - on_mismatch(top, bottom); - return false; - } - ~stack_guard() { - check_stack(); - } - }; -} // sol - -// end of sol/stack_guard.hpp - -#include - -namespace sol { - namespace detail { - struct as_reference_tag {}; - template - struct as_pointer_tag {}; - template - struct as_value_tag {}; - - using special_destruct_func = void(*)(void*); - - template - inline void special_destruct(void* memory) { - T** pointerpointer = static_cast(memory); - special_destruct_func* dx = static_cast(static_cast(pointerpointer + 1)); - Real* target = static_cast(static_cast(dx + 1)); - target->~Real(); - } - - template - inline int unique_destruct(lua_State* L) { - void* memory = lua_touserdata(L, 1); - T** pointerpointer = static_cast(memory); - special_destruct_func& dx = *static_cast(static_cast(pointerpointer + 1)); - (dx)(memory); - return 0; - } - - template - inline int user_alloc_destroy(lua_State* L) { - void* rawdata = lua_touserdata(L, 1); - T* data = static_cast(rawdata); - std::allocator alloc; - alloc.destroy(data); - return 0; - } - - template - inline int usertype_alloc_destroy(lua_State* L) { - void* rawdata = lua_touserdata(L, 1); - T** pdata = static_cast(rawdata); - T* data = *pdata; - std::allocator alloc{}; - alloc.destroy(data); - return 0; - } - - template - void reserve(T&, std::size_t) {} - - template - void reserve(std::vector& arr, std::size_t hint) { - arr.reserve(hint); - } - - template - void reserve(std::basic_string& arr, std::size_t hint) { - arr.reserve(hint); - } - } // detail - - namespace stack { - - template - struct field_getter; - template - struct probe_field_getter; - template - struct field_setter; - template - struct getter; - template - struct popper; - template - struct pusher; - template::value, typename = void> - struct checker; - template - struct check_getter; - - struct probe { - bool success; - int levels; - - probe(bool s, int l) : success(s), levels(l) {} - - operator bool() const { return success; }; - }; - - struct record { - int last; - int used; - - record() : last(), used() {} - void use(int count) { - last = count; - used += count; - } - }; - - namespace stack_detail { - template - struct strip { - typedef T type; - }; - template - struct strip> { - typedef T& type; - }; - template - struct strip> { - typedef T& type; - }; - template - struct strip> { - typedef T type; - }; - template - using strip_t = typename strip::type; - - const bool default_check_arguments = -#ifdef SOL_CHECK_ARGUMENTS - true; -#else - false; -#endif - template - inline decltype(auto) unchecked_get(lua_State* L, int index, record& tracking) { - return getter>{}.get(L, index, tracking); - } - - template - inline int push_reference(lua_State* L, Arg&& arg, Args&&... args) { - typedef meta::all< - std::is_lvalue_reference, - meta::neg>, - meta::neg>>, - meta::neg>> - > use_reference_tag; - return pusher>>{}.push(L, std::forward(arg), std::forward(args)...); - } - } // stack_detail - - inline bool maybe_indexable(lua_State* L, int index = -1) { - type t = type_of(L, index); - return t == type::userdata || t == type::table; - } - - template - inline int push(lua_State* L, T&& t, Args&&... args) { - return pusher>{}.push(L, std::forward(t), std::forward(args)...); - } - - // overload allows to use a pusher of a specific type, but pass in any kind of args - template::value>> - inline int push(lua_State* L, Arg&& arg, Args&&... args) { - return pusher>{}.push(L, std::forward(arg), std::forward(args)...); - } - - template - inline int push_reference(lua_State* L, T&& t, Args&&... args) { - return stack_detail::push_reference(L, std::forward(t), std::forward(args)...); - } - - template - inline int push_reference(lua_State* L, Arg&& arg, Args&&... args) { - return stack_detail::push_reference(L, std::forward(arg), std::forward(args)...); - } - - inline int multi_push(lua_State*) { - // do nothing - return 0; - } - - template - inline int multi_push(lua_State* L, T&& t, Args&&... args) { - int pushcount = push(L, std::forward(t)); - void(sol::detail::swallow{ (pushcount += sol::stack::push(L, std::forward(args)), 0)... }); - return pushcount; - } - - inline int multi_push_reference(lua_State*) { - // do nothing - return 0; - } - - template - inline int multi_push_reference(lua_State* L, T&& t, Args&&... args) { - int pushcount = push_reference(L, std::forward(t)); - void(sol::detail::swallow{ (pushcount += sol::stack::push_reference(L, std::forward(args)), 0)... }); - return pushcount; - } - - template - bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - typedef meta::unqualified_t Tu; - checker c; - // VC++ has a bad warning here: shut it up - (void)c; - return c.check(L, index, std::forward(handler), tracking); - } - - template - bool check(lua_State* L, int index, Handler&& handler) { - record tracking{}; - return check(L, index, std::forward(handler), tracking); - } - - template - bool check(lua_State* L, int index = -lua_size>::value) { - auto handler = no_panic; - return check(L, index, handler); - } - - template - inline decltype(auto) check_get(lua_State* L, int index, Handler&& handler, record& tracking) { - return check_getter>{}.get(L, index, std::forward(handler), tracking); - } - - template - inline decltype(auto) check_get(lua_State* L, int index, Handler&& handler) { - record tracking{}; - return check_get(L, index, handler, tracking); - } - - template - inline decltype(auto) check_get(lua_State* L, int index = -lua_size>::value) { - auto handler = no_panic; - return check_get(L, index, handler); - } - - namespace stack_detail { - -#ifdef SOL_CHECK_ARGUMENTS - template - inline auto tagged_get(types, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get(L, index, tracking)) { - auto op = check_get(L, index, type_panic, tracking); - return *std::move(op); - } -#else - template - inline decltype(auto) tagged_get(types, lua_State* L, int index, record& tracking) { - return stack_detail::unchecked_get(L, index, tracking); - } -#endif - - template - inline decltype(auto) tagged_get(types>, lua_State* L, int index, record& tracking) { - return stack_detail::unchecked_get>(L, index, tracking); - } - - template - struct check_types { - template - static bool check(types, lua_State* L, int firstargument, Handler&& handler, record& tracking) { - if (!stack::check(L, firstargument + tracking.used, handler, tracking)) - return false; - return check(types(), L, firstargument, std::forward(handler), tracking); - } - - template - static bool check(types<>, lua_State*, int, Handler&&, record&) { - return true; - } - }; - - template <> - struct check_types { - template - static bool check(types, lua_State*, int, Handler&&, record&) { - return true; - } - }; - - } // stack_detail - - template - bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack_detail::check_types{}.check(types...>(), L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler) { - record tracking{}; - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index) { - auto handler = no_panic; - return multi_check(L, index, handler); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler, record& tracking) { - return multi_check(L, index, std::forward(handler), tracking); - } - - template - bool multi_check(lua_State* L, int index, Handler&& handler) { - return multi_check(L, index, std::forward(handler)); - } - - template - bool multi_check(lua_State* L, int index) { - return multi_check(L, index); - } - - template - inline decltype(auto) get(lua_State* L, int index, record& tracking) { - return stack_detail::tagged_get(types(), L, index, tracking); - } - - template - inline decltype(auto) get(lua_State* L, int index = -lua_size>::value) { - record tracking{}; - return get(L, index, tracking); - } - - template - inline decltype(auto) pop(lua_State* L) { - return popper>{}.pop(L); - } - - template - void get_field(lua_State* L, Key&& key) { - field_getter, global, raw>{}.get(L, std::forward(key)); - } - - template - void get_field(lua_State* L, Key&& key, int tableindex) { - field_getter, global, raw>{}.get(L, std::forward(key), tableindex); - } - - template - void raw_get_field(lua_State* L, Key&& key) { - get_field(L, std::forward(key)); - } - - template - void raw_get_field(lua_State* L, Key&& key, int tableindex) { - get_field(L, std::forward(key), tableindex); - } - - template - probe probe_get_field(lua_State* L, Key&& key) { - return probe_field_getter, global, raw>{}.get(L, std::forward(key)); - } - - template - probe probe_get_field(lua_State* L, Key&& key, int tableindex) { - return probe_field_getter, global, raw>{}.get(L, std::forward(key), tableindex); - } - - template - probe probe_raw_get_field(lua_State* L, Key&& key) { - return probe_get_field(L, std::forward(key)); - } - - template - probe probe_raw_get_field(lua_State* L, Key&& key, int tableindex) { - return probe_get_field(L, std::forward(key), tableindex); - } - - template - void set_field(lua_State* L, Key&& key, Value&& value) { - field_setter, global, raw>{}.set(L, std::forward(key), std::forward(value)); - } - - template - void set_field(lua_State* L, Key&& key, Value&& value, int tableindex) { - field_setter, global, raw>{}.set(L, std::forward(key), std::forward(value), tableindex); - } - - template - void raw_set_field(lua_State* L, Key&& key, Value&& value) { - set_field(L, std::forward(key), std::forward(value)); - } - - template - void raw_set_field(lua_State* L, Key&& key, Value&& value, int tableindex) { - set_field(L, std::forward(key), std::forward(value), tableindex); - } - } // stack -} // sol - -// end of sol/stack_core.hpp - -// beginning of sol/stack_check.hpp - -// beginning of sol/usertype_traits.hpp - -// beginning of sol/demangle.hpp - -#include -#include - -namespace sol { - namespace detail { -#if defined(__GNUC__) || defined(__clang__) - template - inline std::string ctti_get_type_name() { - const static std::array removals = { { "{anonymous}", "(anonymous namespace)" } }; - std::string name = __PRETTY_FUNCTION__; - std::size_t start = name.find_first_of('['); - start = name.find_first_of('=', start); - std::size_t end = name.find_last_of(']'); - if (end == std::string::npos) - end = name.size(); - if (start == std::string::npos) - start = 0; - if (start < name.size() - 1) - start += 1; - name = name.substr(start, end - start); - start = name.rfind("seperator_mark"); - if (start != std::string::npos) { - name.erase(start - 2, name.length()); - } - while (!name.empty() && std::isblank(name.front())) name.erase(name.begin()); - while (!name.empty() && std::isblank(name.back())) name.pop_back(); - - for (std::size_t r = 0; r < removals.size(); ++r) { - auto found = name.find(removals[r]); - while (found != std::string::npos) { - name.erase(found, removals[r].size()); - found = name.find(removals[r]); - } - } - - return name; - } -#elif defined(_MSC_VER) - template - inline std::string ctti_get_type_name() { - const static std::array removals = { { "public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'" } }; - std::string name = __FUNCSIG__; - std::size_t start = name.find("get_type_name"); - if (start == std::string::npos) - start = 0; - else - start += 13; - if (start < name.size() - 1) - start += 1; - std::size_t end = name.find_last_of('>'); - if (end == std::string::npos) - end = name.size(); - name = name.substr(start, end - start); - if (name.find("struct", 0) == 0) - name.replace(0, 6, "", 0); - if (name.find("class", 0) == 0) - name.replace(0, 5, "", 0); - while (!name.empty() && std::isblank(name.front())) name.erase(name.begin()); - while (!name.empty() && std::isblank(name.back())) name.pop_back(); - - for (std::size_t r = 0; r < removals.size(); ++r) { - auto found = name.find(removals[r]); - while (found != std::string::npos) { - name.erase(found, removals[r].size()); - found = name.find(removals[r]); - } - } - - return name; - } -#else -#error Compiler not supported for demangling -#endif // compilers - - template - inline std::string demangle_once() { - std::string realname = ctti_get_type_name(); - return realname; - } - - template - inline std::string short_demangle_once() { - std::string realname = ctti_get_type_name(); - // This isn't the most complete but it'll do for now...? - static const std::array ops = { { "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" } }; - int level = 0; - std::ptrdiff_t idx = 0; - for (idx = static_cast(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) { - if (level == 0 && realname[idx] == ':') { - break; - } - bool isleft = realname[idx] == '<'; - bool isright = realname[idx] == '>'; - if (!isleft && !isright) - continue; - bool earlybreak = false; - for (const auto& op : ops) { - std::size_t nisop = realname.rfind(op, idx); - if (nisop == std::string::npos) - continue; - std::size_t nisopidx = idx - op.size() + 1; - if (nisop == nisopidx) { - idx = static_cast(nisopidx); - earlybreak = true; - } - break; - } - if (earlybreak) { - continue; - } - level += isleft ? -1 : 1; - } - if (idx > 0) { - realname.erase(0, realname.length() < static_cast(idx) ? realname.length() : idx + 1); - } - return realname; - } - - template - inline const std::string& demangle() { - static const std::string d = demangle_once(); - return d; - } - - template - inline const std::string& short_demangle() { - static const std::string d = short_demangle_once(); - return d; - } - } // detail -} // sol - -// end of sol/demangle.hpp - -namespace sol { - - template - struct usertype_traits { - static const std::string& name() { - static const std::string& n = detail::short_demangle(); - return n; - } - static const std::string& qualified_name() { - static const std::string& q_n = detail::demangle(); - return q_n; - } - static const std::string& metatable() { - static const std::string m = std::string("sol.").append(detail::demangle()); - return m; - } - static const std::string& user_metatable() { - static const std::string u_m = std::string("sol.").append(detail::demangle()).append(".user"); - return u_m; - } - static const std::string& user_gc_metatable() { - static const std::string u_g_m = std::string("sol.").append(detail::demangle()).append(".user\xE2\x99\xBB"); - return u_g_m; - } - static const std::string& gc_table() { - static const std::string g_t = std::string("sol.").append(detail::demangle()).append(".\xE2\x99\xBB"); - return g_t; - } - }; - -} - -// end of sol/usertype_traits.hpp - -// beginning of sol/inheritance.hpp - -#include - -namespace sol { - template - struct base_list { }; - template - using bases = base_list; - - typedef bases<> base_classes_tag; - const auto base_classes = base_classes_tag(); - - namespace detail { - - template - struct has_derived { - static bool value; - }; - - template - bool has_derived::value = false; - - inline std::size_t unique_id() { - static std::atomic x(0); - return ++x; - } - - template - struct id_for { - static const std::size_t value; - }; - - template - const std::size_t id_for::value = unique_id(); - - inline decltype(auto) base_class_check_key() { - static const auto& key = "class_check"; - return key; - } - - inline decltype(auto) base_class_cast_key() { - static const auto& key = "class_cast"; - return key; - } - - inline decltype(auto) base_class_index_propogation_key() { - static const auto& key = u8"\xF0\x9F\x8C\xB2.index"; - return key; - } - - inline decltype(auto) base_class_new_index_propogation_key() { - static const auto& key = u8"\xF0\x9F\x8C\xB2.new_index"; - return key; - } - - template - struct inheritance { - static bool type_check_bases(types<>, std::size_t) { - return false; - } - - template - static bool type_check_bases(types, std::size_t ti) { - return ti == id_for::value || type_check_bases(types(), ti); - } - - static bool type_check(std::size_t ti) { - return ti == id_for::value || type_check_bases(types(), ti); - } - - static void* type_cast_bases(types<>, T*, std::size_t) { - return nullptr; - } - - template - static void* type_cast_bases(types, T* data, std::size_t ti) { - // Make sure to convert to T first, and then dynamic cast to the proper type - return ti != id_for::value ? type_cast_bases(types(), data, ti) : static_cast(static_cast(data)); - } - - static void* type_cast(void* voiddata, std::size_t ti) { - T* data = static_cast(voiddata); - return static_cast(ti != id_for::value ? type_cast_bases(types(), data, ti) : data); - } - }; - - using inheritance_check_function = decltype(&inheritance::type_check); - using inheritance_cast_function = decltype(&inheritance::type_cast); - - } // detail -} // sol - -// end of sol/inheritance.hpp - -#include - -namespace sol { - namespace stack { - namespace stack_detail { - template - inline bool check_metatable(lua_State* L, int index = -2) { - const auto& metakey = usertype_traits::metatable(); - luaL_getmetatable(L, &metakey[0]); - const type expectedmetatabletype = static_cast(lua_type(L, -1)); - if (expectedmetatabletype != type::lua_nil) { - if (lua_rawequal(L, -1, index) == 1) { - lua_pop(L, 1 + static_cast(poptable)); - return true; - } - } - lua_pop(L, 1); - return false; - } - - template - struct basic_check { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - bool success = check_func(L, index) == 1; - if (!success) { - // expected type, actual type - handler(L, index, expected, type_of(L, index)); - } - return success; - } - }; - } // stack_detail - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - const type indextype = type_of(L, index); - bool success = expected == indextype; - if (!success) { - // expected type, actual type - handler(L, index, expected, indextype); - } - return success; - } - }; - - template - struct checker::value>> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - bool success = lua_isinteger(L, index) == 1; - if (!success) { - // expected type, actual type - handler(L, index, type::number, type_of(L, index)); - } - return success; - } - }; - - template - struct checker::value>> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - bool success = lua_isnumber(L, index) == 1; - if (!success) { - // expected type, actual type - handler(L, index, type::number, type_of(L, index)); - } - return success; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - bool success = lua_isnil(L, index); - if (success) { - tracking.use(1); - return success; - } - tracking.use(0); - success = lua_isnone(L, index); - if (!success) { - // expected type, actual type - handler(L, index, expected, type_of(L, index)); - } - return success; - } - }; - - template - struct checker : checker {}; - - template - struct checker { - template - static bool check(lua_State*, int, Handler&&, record& tracking) { - tracking.use(0); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State*, int, Handler&&, record& tracking) { - tracking.use(0); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State*, int, Handler&&, record& tracking) { - tracking.use(0); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State*, int, Handler&&, record& tracking) { - tracking.use(0); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - bool success = !lua_isnone(L, index); - if (!success) { - // expected type, actual type - handler(L, index, type::none, type_of(L, index)); - } - return success; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - type t = type_of(L, index); - bool success = t == type::userdata || t == type::lightuserdata; - if (!success) { - // expected type, actual type - handler(L, index, type::lightuserdata, t); - } - return success; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - type t = type_of(L, index); - bool success = t == type::userdata; - if (!success) { - // expected type, actual type - handler(L, index, type::userdata, t); - } - return success; - } - }; - - template - struct checker, type::userdata, C> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack::check(L, index, std::forward(handler), tracking); - } - }; - - template - struct checker, type::userdata, C> : checker, type::lightuserdata, C> {}; - - template - struct checker, type::userdata, C> : checker::value, C> {}; - - template - struct checker : stack_detail::basic_check {}; - template - struct checker, type::function, C> : checker {}; - template - struct checker : checker {}; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - type t = type_of(L, index); - if (t == type::lua_nil || t == type::none || t == type::function) { - // allow for lua_nil to be returned - return true; - } - if (t != type::userdata && t != type::table) { - handler(L, index, type::function, t); - return false; - } - // Do advanced check for call-style userdata? - static const auto& callkey = to_string(meta_function::call); - if (lua_getmetatable(L, index) == 0) { - // No metatable, no __call key possible - handler(L, index, type::function, t); - return false; - } - if (lua_isnoneornil(L, -1)) { - lua_pop(L, 1); - handler(L, index, type::function, t); - return false; - } - lua_getfield(L, -1, &callkey[0]); - if (lua_isnoneornil(L, -1)) { - lua_pop(L, 2); - handler(L, index, type::function, t); - return false; - } - // has call, is definitely a function - lua_pop(L, 2); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - type t = type_of(L, index); - if (t == type::table) { - return true; - } - if (t != type::userdata) { - handler(L, index, type::table, t); - return false; - } - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - if (lua_getmetatable(L, index) == 0) { - return true; - } - type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { - lua_pop(L, 1); - return true; - } - if (t != type::userdata) { - lua_pop(L, 1); - handler(L, index, expected, t); - return false; - } - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - if (lua_getmetatable(L, index) == 0) { - return true; - } - type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { - lua_pop(L, 1); - return true; - } - if (t != type::userdata) { - lua_pop(L, 1); - handler(L, index, type::table, t); - return false; - } - return true; - } - }; - - template - struct checker, type::poly, C> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); - if (lua_getmetatable(L, index) == 0) { - return true; - } - type t = type_of(L, -1); - if (t == type::table || t == type::none || t == type::nil) { - lua_pop(L, 1); - return true; - } - if (t != type::userdata) { - lua_pop(L, 1); - handler(L, index, type::table, t); - return false; - } - return true; - } - }; - - template - struct checker, type::userdata, C> { - template - static bool check(types, lua_State* L, type indextype, int index, Handler&& handler, record& tracking) { - tracking.use(1); - if (indextype != type::userdata) { - handler(L, index, type::userdata, indextype); - return false; - } - if (meta::any, std::is_same, std::is_same, std::is_same>::value) - return true; - if (lua_getmetatable(L, index) == 0) { - return true; - } - int metatableindex = lua_gettop(L); - if (stack_detail::check_metatable(L, metatableindex)) - return true; - if (stack_detail::check_metatable(L, metatableindex)) - return true; - if (stack_detail::check_metatable>(L, metatableindex)) - return true; - bool success = false; - if (detail::has_derived::value) { - auto pn = stack::pop_n(L, 1); - lua_pushstring(L, &detail::base_class_check_key()[0]); - lua_rawget(L, metatableindex); - if (type_of(L, -1) != type::lua_nil) { - void* basecastdata = lua_touserdata(L, -1); - detail::inheritance_check_function ic = (detail::inheritance_check_function)basecastdata; - success = ic(detail::id_for::value); - } - } - if (!success) { - lua_pop(L, 1); - handler(L, index, type::userdata, indextype); - return false; - } - lua_pop(L, 1); - return true; - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - const type indextype = type_of(L, index); - return checker, type::userdata, C>{}.check(types(), L, indextype, index, std::forward(handler), tracking); - } - }; - - template - struct checker { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - const type indextype = type_of(L, index); - // Allow lua_nil to be transformed to nullptr - if (indextype == type::lua_nil) { - tracking.use(1); - return true; - } - return checker, type::userdata, C>{}.check(L, index, std::forward(handler), tracking); - } - }; - - template - struct checker::value>> { - typedef typename unique_usertype_traits::type T; - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - const type indextype = type_of(L, index); - tracking.use(1); - if (indextype != type::userdata) { - handler(L, index, type::userdata, indextype); - return false; - } - if (lua_getmetatable(L, index) == 0) { - return true; - } - int metatableindex = lua_gettop(L); - if (stack_detail::check_metatable>(L, metatableindex)) - return true; - lua_pop(L, 1); - handler(L, index, type::userdata, indextype); - return false; - } - }; - - template - struct checker, type::userdata, C> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - return checker{}.check(L, index, std::forward(handler), tracking); - } - }; - - template - struct checker, type::poly, C> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack::multi_check(L, index, std::forward(handler), tracking); - } - }; - - template - struct checker, type::poly, C> { - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - return stack::multi_check(L, index, std::forward(handler), tracking); - } - }; - - template - struct checker, type::poly, C> { - template - static bool check(lua_State* L, int index, Handler&&, record& tracking) { - type t = type_of(L, index); - if (t == type::none) { - tracking.use(0); - return true; - } - if (t == type::lua_nil) { - tracking.use(1); - return true; - } - return stack::check(L, index, no_panic, tracking); - } - }; - } // stack -} // sol - -// end of sol/stack_check.hpp - -// beginning of sol/stack_get.hpp - -// beginning of sol/overload.hpp - -namespace sol { - template - struct overload_set { - std::tuple functions; - template >> = meta::enabler> - overload_set (Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} - overload_set(const overload_set&) = default; - overload_set(overload_set&&) = default; - overload_set& operator=(const overload_set&) = default; - overload_set& operator=(overload_set&&) = default; - }; - - template - decltype(auto) overload(Args&&... args) { - return overload_set...>(std::forward(args)...); - } -} - -// end of sol/overload.hpp - -#ifdef SOL_CODECVT_SUPPORT -#include -#endif - -namespace sol { - namespace stack { - - template - struct getter { - static T& get(lua_State* L, int index, record& tracking) { - return getter>{}.get(L, index, tracking); - } - }; - - template - struct getter::value>> { - static T get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_tonumber(L, index)); - } - }; - - template - struct getter, std::is_signed>::value>> { - static T get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_tointeger(L, index)); - } - }; - - template - struct getter, std::is_unsigned>::value>> { - static T get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_tointeger(L, index)); - } - }; - - template - struct getter::value>> { - static T get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_tointegerx(L, index, nullptr)); - } - }; - - template - struct getter, std::enable_if_t>::value>> { - static T get(lua_State* L, int relindex, record& tracking) { - typedef typename T::value_type V; - return get(types(), L, relindex, tracking); - } - - template - static T get(types, lua_State* L, int relindex, record& tracking) { - tracking.use(1); - - int index = lua_absindex(L, relindex); - T arr; -#if SOL_LUA_VERSION >= 503 - // This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3 - for (lua_Integer i = 0; ; i += lua_size::value, lua_pop(L, lua_size::value)) { - bool isnil = false; - for (int vi = 0; vi < lua_size::value; ++vi) { - type t = static_cast(lua_geti(L, index, i + vi)); - isnil = t == type::lua_nil; - if (isnil) { - if (i == 0) { - break; - } - lua_pop(L, (vi + 1)); - return arr; - } - } - if (isnil) - continue; - arr.push_back(stack::get(L, -lua_size::value)); - } -#else - // Zzzz slower but necessary thanks to the lower version API and missing functions qq - for (lua_Integer i = 0; ; i += lua_size::value, lua_pop(L, lua_size::value)) { - bool isnil = false; - for (int vi = 0; vi < lua_size::value; ++vi) { - lua_pushinteger(L, i); - lua_gettable(L, index); - type t = type_of(L, -1); - isnil = t == type::lua_nil; - if (isnil) { - if (i == 0) { - break; - } - lua_pop(L, (vi + 1)); - return arr; - } - } - if (isnil) - continue; - arr.push_back(stack::get(L, -1)); - } -#endif - return arr; - } - }; - - template - struct getter, std::enable_if_t>::value>> { - static T get(lua_State* L, int index, record& tracking) { - typedef typename T::value_type P; - typedef typename P::first_type K; - typedef typename P::second_type V; - return get(types(), L, index, tracking); - } - - template - static T get(types, lua_State* L, int relindex, record& tracking) { - tracking.use(1); - - T associative; - int index = lua_absindex(L, relindex); - lua_pushnil(L); - while (lua_next(L, index) != 0) { - decltype(auto) key = stack::check_get(L, -2); - if (!key) { - lua_pop(L, 1); - continue; - } - associative.emplace(std::forward(*key), stack::get(L, -1)); - lua_pop(L, 1); - } - return associative; - } - }; - - template - struct getter, std::enable_if_t::value>> { - static T get(lua_State* L, int index, record& tracking) { - getter g; - // VC++ has a bad warning here: shut it up - (void)g; - return g.get(L, index, tracking); - } - }; - - template - struct getter, std::enable_if_t, meta::neg>>>::value>> { - static T get(lua_State* L, int index, record& tracking) { - typedef typename T::value_type V; - getter> g; - // VC++ has a bad warning here: shut it up - (void)g; - return g.get(types>(), L, index, tracking); - } - }; - - template - struct getter, std::enable_if_t, meta::has_key_value_pair>>::value>> { - static T get(lua_State* L, int index, record& tracking) { - typedef typename T::value_type P; - typedef typename P::first_type K; - typedef typename P::second_type V; - getter> g; - // VC++ has a bad warning here: shut it up - (void)g; - return g.get(types>(), L, index, tracking); - } - }; - - template - struct getter::value || std::is_base_of::value>> { - static T get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return T(L, index); - } - }; - - template<> - struct getter { - static userdata_value get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return userdata_value(lua_touserdata(L, index)); - } - }; - - template<> - struct getter { - static lightuserdata_value get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return lightuserdata_value(lua_touserdata(L, index)); - } - }; - - template - struct getter> { - static light get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return light(static_cast(lua_touserdata(L, index))); - } - }; - - template - struct getter> { - static T& get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return *static_cast(lua_touserdata(L, index)); - } - }; - - template - struct getter> { - static T* get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_touserdata(L, index)); - } - }; - - template<> - struct getter { - static type get(lua_State *L, int index, record& tracking) { - tracking.use(1); - return static_cast(lua_type(L, index)); - } - }; - - template<> - struct getter { - static bool get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return lua_toboolean(L, index) != 0; - } - }; - - template<> - struct getter { - static std::string get(lua_State* L, int index, record& tracking) { - tracking.use(1); - std::size_t len; - auto str = lua_tolstring(L, index, &len); - return std::string( str, len ); - } - }; - - template <> - struct getter { - string_detail::string_shim get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - const char* p = lua_tolstring(L, index, &len); - return string_detail::string_shim(p, len); - } - }; - - template<> - struct getter { - static const char* get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return lua_tostring(L, index); - } - }; - - template<> - struct getter { - static char get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - auto str = lua_tolstring(L, index, &len); - return len > 0 ? str[0] : '\0'; - } - }; - -#ifdef SOL_CODECVT_SUPPORT - template<> - struct getter { - static std::wstring get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - auto str = lua_tolstring(L, index, &len); - if (len < 1) - return std::wstring(); - if (sizeof(wchar_t) == 2) { - static std::wstring_convert> convert; - std::wstring r = convert.from_bytes(str, str + len); -#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 7 - // Fuck you, MinGW, and fuck you libstdc++ for introducing this absolutely asinine bug - // https://sourceforge.net/p/mingw-w64/bugs/538/ - // http://chat.stackoverflow.com/transcript/message/32271369#32271369 - for (auto& c : r) { - uint8_t* b = reinterpret_cast(&c); - std::swap(b[0], b[1]); - } -#endif - return r; - } - static std::wstring_convert> convert; - std::wstring r = convert.from_bytes(str, str + len); - return r; - } - }; - - template<> - struct getter { - static std::u16string get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - auto str = lua_tolstring(L, index, &len); - if (len < 1) - return std::u16string(); -#ifdef _MSC_VER - static std::wstring_convert, int16_t> convert; - auto intd = convert.from_bytes(str, str + len); - std::u16string r(intd.size(), '\0'); - std::memcpy(&r[0], intd.data(), intd.size() * sizeof(char16_t)); -#else - static std::wstring_convert, char16_t> convert; - std::u16string r = convert.from_bytes(str, str + len); -#endif // VC++ is a shit - return r; - } - }; - - template<> - struct getter { - static std::u32string get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - auto str = lua_tolstring(L, index, &len); - if (len < 1) - return std::u32string(); -#ifdef _MSC_VER - static std::wstring_convert, int32_t> convert; - auto intd = convert.from_bytes(str, str + len); - std::u32string r(intd.size(), '\0'); - std::memcpy(&r[0], intd.data(), r.size() * sizeof(char32_t)); -#else - static std::wstring_convert, char32_t> convert; - std::u32string r = convert.from_bytes(str, str + len); -#endif // VC++ is a shit - return r; - } - }; - - template<> - struct getter { - static wchar_t get(lua_State* L, int index, record& tracking) { - auto str = getter{}.get(L, index, tracking); - return str.size() > 0 ? str[0] : wchar_t(0); - } - }; - - template<> - struct getter { - static char16_t get(lua_State* L, int index, record& tracking) { - auto str = getter{}.get(L, index, tracking); - return str.size() > 0 ? str[0] : char16_t(0); - } - }; - - template<> - struct getter { - static char32_t get(lua_State* L, int index, record& tracking) { - auto str = getter{}.get(L, index, tracking); - return str.size() > 0 ? str[0] : char32_t(0); - } - }; -#endif // codecvt header support - - template<> - struct getter { - static meta_function get(lua_State *L, int index, record& tracking) { - tracking.use(1); - const char* name = getter{}.get(L, index, tracking); - const auto& mfnames = meta_function_names(); - for (std::size_t i = 0; i < mfnames.size(); ++i) - if (mfnames[i] == name) - return static_cast(i); - return meta_function::construct; - } - }; - - template<> - struct getter { - static lua_nil_t get(lua_State*, int, record& tracking) { - tracking.use(1); - return lua_nil; - } - }; - - template<> - struct getter { - static std::nullptr_t get(lua_State*, int, record& tracking) { - tracking.use(1); - return nullptr; - } - }; - - template<> - struct getter { - static nullopt_t get(lua_State*, int, record& tracking) { - tracking.use(1); - return nullopt; - } - }; - - template<> - struct getter { - static this_state get(lua_State* L, int, record& tracking) { - tracking.use(0); - return this_state{ L }; - } - }; - - template<> - struct getter { - static lua_CFunction get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return lua_tocfunction(L, index); - } - }; - - template<> - struct getter { - static c_closure get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return c_closure(lua_tocfunction(L, index), -1); - } - }; - - template<> - struct getter { - static error get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t sz = 0; - const char* err = lua_tolstring(L, index, &sz); - if (err == nullptr) { - return error(detail::direct_error, ""); - } - return error(detail::direct_error, std::string(err, sz)); - } - }; - - template<> - struct getter { - static void* get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return lua_touserdata(L, index); - } - }; - - template - struct getter> { - static T* get_no_lua_nil(lua_State* L, int index, record& tracking) { - tracking.use(1); - void** pudata = static_cast(lua_touserdata(L, index)); - void* udata = *pudata; - return get_no_lua_nil_from(L, udata, index, tracking); - } - - static T* get_no_lua_nil_from(lua_State* L, void* udata, int index, record&) { - if (detail::has_derived::value && luaL_getmetafield(L, index, &detail::base_class_cast_key()[0]) != 0) { - void* basecastdata = lua_touserdata(L, -1); - detail::inheritance_cast_function ic = (detail::inheritance_cast_function)basecastdata; - // use the casting function to properly adjust the pointer for the desired T - udata = ic(udata, detail::id_for::value); - lua_pop(L, 1); - } - T* obj = static_cast(udata); - return obj; - } - - static T& get(lua_State* L, int index, record& tracking) { - return *get_no_lua_nil(L, index, tracking); - } - }; - - template - struct getter> { - static T* get(lua_State* L, int index, record& tracking) { - type t = type_of(L, index); - if (t == type::lua_nil) { - tracking.use(1); - return nullptr; - } - getter> g; - // Avoid VC++ warning - (void)g; - return g.get_no_lua_nil(L, index, tracking); - } - }; - - template - struct getter> { - static T* get(lua_State* L, int index, record& tracking) { - getter> g; - // Avoid VC++ warning - (void)g; - return g.get_no_lua_nil(L, index, tracking); - } - }; - - template - struct getter { - static T& get(lua_State* L, int index, record& tracking) { - getter> g; - // Avoid VC++ warning - (void)g; - return g.get(L, index, tracking); - } - }; - - template - struct getter> { - static T& get(lua_State* L, int index, record& tracking) { - getter g; - // Avoid VC++ warning - (void)g; - return g.get(L, index, tracking); - } - }; - - template - struct getter { - static T* get(lua_State* L, int index, record& tracking) { - getter> g; - // Avoid VC++ warning - (void)g; - return g.get(L, index, tracking); - } - }; - - template - struct getter::value>> { - typedef typename unique_usertype_traits::type P; - typedef typename unique_usertype_traits::actual_type Real; - - static Real& get(lua_State* L, int index, record& tracking) { - tracking.use(1); - P** pref = static_cast(lua_touserdata(L, index)); - detail::special_destruct_func* fx = static_cast(static_cast(pref + 1)); - Real* mem = static_cast(static_cast(fx + 1)); - return *mem; - } - }; - - template - struct getter> { - typedef std::tuple(nullptr, 0))...> R; - - template - static R apply(std::index_sequence<>, lua_State*, int, record&, TArgs&&... args) { - // Fuck you too, VC++ - return R{std::forward(args)...}; - } - - template - static R apply(std::index_sequence, lua_State* L, int index, record& tracking, TArgs&&... args) { - // Fuck you too, VC++ - typedef std::tuple_element_t> T; - return apply(std::index_sequence(), L, index, tracking, std::forward(args)..., stack::get(L, index + tracking.used, tracking)); - } - - static R get(lua_State* L, int index, record& tracking) { - return apply(std::make_index_sequence(), L, index, tracking); - } - }; - - template - struct getter> { - static decltype(auto) get(lua_State* L, int index, record& tracking) { - return std::pair(L, index)), decltype(stack::get(L, index))>{stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking)}; - } - }; - } // stack -} // sol - -// end of sol/stack_get.hpp - -// beginning of sol/stack_check_get.hpp - -namespace sol { - namespace stack { - template - struct check_getter { - typedef decltype(stack_detail::unchecked_get(nullptr, 0, std::declval())) R; - - template - static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - if (!check(L, index, std::forward(handler))) { - tracking.use(static_cast(!lua_isnone(L, index))); - return nullopt; - } - return stack_detail::unchecked_get(L, index, tracking); - } - }; - - template - struct check_getter> { - template - static decltype(auto) get(lua_State* L, int index, Handler&&, record& tracking) { - return check_get(L, index, no_panic, tracking); - } - }; - - template - struct check_getter::value && lua_type_of::value == type::number>> { - template - static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - int isnum = 0; - lua_Integer value = lua_tointegerx(L, index, &isnum); - if (isnum == 0) { - type t = type_of(L, index); - tracking.use(static_cast(t != type::none)); - handler(L, index, type::number, t); - return nullopt; - } - tracking.use(1); - return static_cast(value); - } - }; - - template - struct check_getter::value && !meta::any_same::value>> { - template - static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - int isnum = 0; - lua_Integer value = lua_tointegerx(L, index, &isnum); - if (isnum == 0) { - type t = type_of(L, index); - tracking.use(static_cast(t != type::none)); - handler(L, index, type::number, t); - return nullopt; - } - tracking.use(1); - return static_cast(value); - } - }; - - template - struct check_getter::value>> { - template - static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - int isnum = 0; - lua_Number value = lua_tonumberx(L, index, &isnum); - if (isnum == 0) { - type t = type_of(L, index); - tracking.use(static_cast(t != type::none)); - handler(L, index, type::number, t); - return nullopt; - } - tracking.use(1); - return static_cast(value); - } - }; - - template - struct getter> { - static decltype(auto) get(lua_State* L, int index, record& tracking) { - return check_get(L, index, no_panic, tracking); - } - }; - } // stack -} // sol - -// end of sol/stack_check_get.hpp - -// beginning of sol/stack_push.hpp - -// beginning of sol/raii.hpp - -namespace sol { - namespace detail { - struct default_construct { - template - static void construct(T&& obj, Args&&... args) { - std::allocator> alloc{}; - alloc.construct(obj, std::forward(args)...); - } - - template - void operator()(T&& obj, Args&&... args) const { - construct(std::forward(obj), std::forward(args)...); - } - }; - - struct default_destruct { - template - static void destroy(T&& obj) { - std::allocator> alloc{}; - alloc.destroy(obj); - } - - template - void operator()(T&& obj) const { - destroy(std::forward(obj)); - } - }; - - struct deleter { - template - void operator()(T* p) const { - delete p; - } - }; - - template - inline std::unique_ptr make_unique_deleter(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); - } - - template - struct tagged { - T value; - template , tagged>> = meta::enabler> - tagged(Arg&& arg, Args&&... args) : value(std::forward(arg), std::forward(args)...) {} - }; - } // detail - - template - struct constructor_list {}; - - template - using constructors = constructor_list; - - const auto default_constructor = constructors>{}; - - struct no_construction {}; - const auto no_constructor = no_construction{}; - - struct call_construction {}; - const auto call_constructor = call_construction{}; - - template - struct constructor_wrapper { - std::tuple functions; - template , constructor_wrapper>> = meta::enabler> - constructor_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} - }; - - template - inline auto initializers(Functions&&... functions) { - return constructor_wrapper...>(std::forward(functions)...); - } - - template - struct factory_wrapper { - std::tuple functions; - template , factory_wrapper>> = meta::enabler> - factory_wrapper(Arg&& arg, Args&&... args) : functions(std::forward(arg), std::forward(args)...) {} - }; - - template - inline auto factories(Functions&&... functions) { - return factory_wrapper...>(std::forward(functions)...); - } - - template - struct destructor_wrapper { - Function fx; - destructor_wrapper(Function f) : fx(std::move(f)) {} - }; - - template <> - struct destructor_wrapper {}; - - const destructor_wrapper default_destructor{}; - - template - inline auto destructor(Fx&& fx) { - return destructor_wrapper>(std::forward(fx)); - } - -} // sol - -// end of sol/raii.hpp - -#ifdef SOL_CODECVT_SUPPORT -#endif - -namespace sol { - namespace stack { - inline int push_environment_of(lua_State* L, int index = -1) { -#if SOL_LUA_VERSION < 502 - // Use lua_setfenv - lua_getfenv(L, index); - return 1; -#else - // Use upvalues as explained in Lua 5.2 and beyond's manual - if (lua_getupvalue(L, index, 1) == nullptr) { - push(L, lua_nil); - return 1; - } -#endif - return 1; - } - - template - int push_environment_of(const T& target) { - target.push(); - return push_environment_of(target.lua_state(), -1) + 1; - } - - template - struct pusher> { - template - static int push_fx(lua_State* L, F&& f, Args&&... args) { - // Basically, we store all user-data like this: - // If it's a movable/copyable value (no std::ref(x)), then we store the pointer to the new - // data in the first sizeof(T*) bytes, and then however many bytes it takes to - // do the actual object. Things that are std::ref or plain T* are stored as - // just the sizeof(T*), and nothing else. - T** pointerpointer = static_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); - T*& referencereference = *pointerpointer; - T* allocationtarget = reinterpret_cast(pointerpointer + 1); - referencereference = allocationtarget; - std::allocator alloc{}; - alloc.construct(allocationtarget, std::forward(args)...); - f(); - return 1; - } - - template - static int push_keyed(lua_State* L, K&& k, Args&&... args) { - return push_fx(L, [&L, &k]() { - luaL_newmetatable(L, &k[0]); - lua_setmetatable(L, -2); - }, std::forward(args)...); - } - - template - static int push(lua_State* L, Args&&... args) { - return push_keyed(L, usertype_traits::metatable(), std::forward(args)...); - } - }; - - template - struct pusher> { - template - static int push_fx(lua_State* L, F&& f, T* obj) { - if (obj == nullptr) - return stack::push(L, lua_nil); - T** pref = static_cast(lua_newuserdata(L, sizeof(T*))); - *pref = obj; - f(); - return 1; - } - - template - static int push_keyed(lua_State* L, K&& k, T* obj) { - return push_fx(L, [&L, &k]() { - luaL_newmetatable(L, &k[0]); - lua_setmetatable(L, -2); - }, obj); - } - - static int push(lua_State* L, T* obj) { - return push_keyed(L, usertype_traits*>::metatable(), obj); - } - }; - - template <> - struct pusher { - template - static int push(lua_State* L, T&& obj) { - return stack::push(L, detail::ptr(obj)); - } - }; - - template - struct pusher { - template - static int push(lua_State* L, Args&&... args) { - return pusher>{}.push(L, std::forward(args)...); - } - }; - - template - struct pusher>, meta::neg>, std::is_base_of>>>>::value>> { - template - static int push(lua_State* L, Args&&... args) { - return pusher>{}.push(L, std::forward(args)...); - } - }; - - template - struct pusher::value>> { - typedef typename unique_usertype_traits::type P; - typedef typename unique_usertype_traits::actual_type Real; - - template >> = meta::enabler> - static int push(lua_State* L, Arg&& arg) { - return push_deep(L, std::forward(arg)); - } - - template - static int push(lua_State* L, Arg0&& arg0, Arg0&& arg1, Args&&... args) { - return push_deep(L, std::forward(arg0), std::forward(arg1), std::forward(args)...); - } - - template - static int push_deep(lua_State* L, Args&&... args) { - P** pref = static_cast(lua_newuserdata(L, sizeof(P*) + sizeof(detail::special_destruct_func) + sizeof(Real))); - detail::special_destruct_func* fx = static_cast(static_cast(pref + 1)); - Real* mem = static_cast(static_cast(fx + 1)); - *fx = detail::special_destruct; - detail::default_construct::construct(mem, std::forward(args)...); - *pref = unique_usertype_traits::get(*mem); - if (luaL_newmetatable(L, &usertype_traits>::metatable()[0]) == 1) { - set_field(L, "__gc", detail::unique_destruct

); - } - lua_setmetatable(L, -2); - return 1; - } - }; - - template - struct pusher> { - static int push(lua_State* L, const std::reference_wrapper& t) { - return stack::push(L, std::addressof(detail::deref(t.get()))); - } - }; - - template - struct pusher::value>> { - static int push(lua_State* L, const T& value) { - lua_pushnumber(L, value); - return 1; - } - }; - - template - struct pusher, std::is_signed>::value>> { - static int push(lua_State* L, const T& value) { - lua_pushinteger(L, static_cast(value)); - return 1; - } - }; - - template - struct pusher::value>> { - static int push(lua_State* L, const T& value) { - if (std::is_same::value) { - return stack::push(L, static_cast(value)); - } - return stack::push(L, static_cast>(value)); - } - }; - - template - struct pusher, std::is_unsigned>::value>> { - static int push(lua_State* L, const T& value) { - lua_pushinteger(L, static_cast(value)); - return 1; - } - }; - - template - struct pusher, std::enable_if_t>>::value>> { - static int push(lua_State* L, const as_table_t& tablecont) { - auto& cont = detail::deref(detail::unwrap(tablecont.source)); - lua_createtable(L, static_cast(cont.size()), 0); - int tableindex = lua_gettop(L); - std::size_t index = 1; - for (const auto& i : cont) { -#if SOL_LUA_VERSION >= 503 - int p = stack::push(L, i); - for (int pi = 0; pi < p; ++pi) { - lua_seti(L, tableindex, static_cast(index++)); - } -#else - lua_pushinteger(L, static_cast(index)); - int p = stack::push(L, i); - if (p == 1) { - ++index; - lua_settable(L, tableindex); - } - else { - int firstindex = tableindex + 1 + 1; - for (int pi = 0; pi < p; ++pi) { - stack::push(L, index); - lua_pushvalue(L, firstindex); - lua_settable(L, tableindex); - ++index; - ++firstindex; - } - lua_pop(L, 1 + p); - } -#endif - } - // TODO: figure out a better way to do this...? - //set_field(L, -1, cont.size()); - return 1; - } - }; - - template - struct pusher, std::enable_if_t>>::value>> { - static int push(lua_State* L, const as_table_t& tablecont) { - auto& cont = detail::deref(detail::unwrap(tablecont.source)); - lua_createtable(L, static_cast(cont.size()), 0); - int tableindex = lua_gettop(L); - for (const auto& pair : cont) { - set_field(L, pair.first, pair.second, tableindex); - } - return 1; - } - }; - - template - struct pusher::value || std::is_base_of::value>> { - static int push(lua_State* L, const T& ref) { - return ref.push(L); - } - - static int push(lua_State* L, T&& ref) { - return ref.push(L); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, bool b) { - lua_pushboolean(L, b); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, lua_nil_t) { - lua_pushnil(L); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, metatable_t) { - lua_pushlstring(L, "__mt", 4); - return 1; - } - }; - - template<> - struct pusher> { - static int push(lua_State* L, lua_CFunction func, int n = 0) { - lua_pushcclosure(L, func, n); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, lua_CFunction func, int n = 0) { - lua_pushcclosure(L, func, n); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, c_closure cc) { - lua_pushcclosure(L, cc.c_function, cc.upvalues); - return 1; - } - }; - - template - struct pusher> { - template - static int push(std::index_sequence, lua_State* L, T&& c) { - int pushcount = multi_push(L, detail::forward_get(c.upvalues)...); - return stack::push(L, c_closure(c.c_function, pushcount)); - } - - template - static int push(lua_State* L, T&& c) { - return push(std::make_index_sequence<1 + sizeof...(Args)>(), L, std::forward(c)); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, void* userdata) { - lua_pushlightuserdata(L, userdata); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, lightuserdata_value userdata) { - lua_pushlightuserdata(L, userdata); - return 1; - } - }; - - template - struct pusher> { - static int push(lua_State* L, light l) { - lua_pushlightuserdata(L, static_cast(l.value)); - return 1; - } - }; - - template - struct pusher> { - template - static int push_with(lua_State* L, Key&& name, Args&&... args) { - // A dumb pusher - void* rawdata = lua_newuserdata(L, sizeof(T)); - T* data = static_cast(rawdata); - std::allocator alloc; - alloc.construct(data, std::forward(args)...); - if (with_meta) { - lua_CFunction cdel = detail::user_alloc_destroy; - // Make sure we have a plain GC set for this data - if (luaL_newmetatable(L, name) != 0) { - lua_pushcclosure(L, cdel, 0); - lua_setfield(L, -2, "__gc"); - } - lua_setmetatable(L, -2); - } - return 1; - } - - template , no_metatable_t, metatable_t>> = meta::enabler> - static int push(lua_State* L, Arg&& arg, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, std::forward(arg), std::forward(args)...); - } - - template - static int push(lua_State* L, no_metatable_t, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, std::forward(args)...); - } - - template - static int push(lua_State* L, metatable_t, Key&& key, Args&&... args) { - const auto name = &key[0]; - return push_with(L, name, std::forward(args)...); - } - - static int push(lua_State* L, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, u.value); - } - - static int push(lua_State* L, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, std::move(u.value)); - } - - static int push(lua_State* L, no_metatable_t, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, u.value); - } - - static int push(lua_State* L, no_metatable_t, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable()[0]; - return push_with(L, name, std::move(u.value)); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, userdata_value data) { - void** ud = static_cast(lua_newuserdata(L, sizeof(void*))); - *ud = data.value; - return 1; - } - }; - - template<> - struct pusher { - static int push_sized(lua_State* L, const char* str, std::size_t len) { - lua_pushlstring(L, str, len); - return 1; - } - - static int push(lua_State* L, const char* str) { - if (str == nullptr) - return stack::push(L, lua_nil); - return push_sized(L, str, std::char_traits::length(str)); - } - - static int push(lua_State* L, const char* strb, const char* stre) { - return push_sized(L, strb, stre - strb); - } - - static int push(lua_State* L, const char* str, std::size_t len) { - return push_sized(L, str, len); - } - }; - - template - struct pusher { - static int push(lua_State* L, const char(&str)[N]) { - lua_pushlstring(L, str, N - 1); - return 1; - } - - static int push(lua_State* L, const char(&str)[N], std::size_t sz) { - lua_pushlstring(L, str, sz); - return 1; - } - }; - - template <> - struct pusher { - static int push(lua_State* L, char c) { - const char str[2] = { c, '\0' }; - return stack::push(L, str, 1); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const std::string& str) { - lua_pushlstring(L, str.c_str(), str.size()); - return 1; - } - - static int push(lua_State* L, const std::string& str, std::size_t sz) { - lua_pushlstring(L, str.c_str(), sz); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, meta_function m) { - const std::string& str = to_string(m); - lua_pushlstring(L, str.c_str(), str.size()); - return 1; - } - }; - -#ifdef SOL_CODECVT_SUPPORT - template<> - struct pusher { - static int push(lua_State* L, const wchar_t* wstr) { - return push(L, wstr, std::char_traits::length(wstr)); - } - - static int push(lua_State* L, const wchar_t* wstr, std::size_t sz) { - return push(L, wstr, wstr + sz); - } - - static int push(lua_State* L, const wchar_t* strb, const wchar_t* stre) { - if (sizeof(wchar_t) == 2) { - static std::wstring_convert> convert; - std::string u8str = convert.to_bytes(strb, stre); - return stack::push(L, u8str); - } - static std::wstring_convert> convert; - std::string u8str = convert.to_bytes(strb, stre); - return stack::push(L, u8str); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const char16_t* u16str) { - return push(L, u16str, std::char_traits::length(u16str)); - } - - static int push(lua_State* L, const char16_t* u16str, std::size_t sz) { - return push(L, u16str, u16str + sz); - } - - static int push(lua_State* L, const char16_t* strb, const char16_t* stre) { -#ifdef _MSC_VER - static std::wstring_convert, int16_t> convert; - std::string u8str = convert.to_bytes(reinterpret_cast(strb), reinterpret_cast(stre)); -#else - static std::wstring_convert, char16_t> convert; - std::string u8str = convert.to_bytes(strb, stre); -#endif // VC++ is a shit - return stack::push(L, u8str); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const char32_t* u32str) { - return push(L, u32str, u32str + std::char_traits::length(u32str)); - } - - static int push(lua_State* L, const char32_t* u32str, std::size_t sz) { - return push(L, u32str, u32str + sz); - } - - static int push(lua_State* L, const char32_t* strb, const char32_t* stre) { -#ifdef _MSC_VER - static std::wstring_convert, int32_t> convert; - std::string u8str = convert.to_bytes(reinterpret_cast(strb), reinterpret_cast(stre)); -#else - static std::wstring_convert, char32_t> convert; - std::string u8str = convert.to_bytes(strb, stre); -#endif // VC++ is a shit - return stack::push(L, u8str); - } - }; - - template - struct pusher { - static int push(lua_State* L, const wchar_t(&str)[N]) { - return push(L, str, N - 1); - } - - static int push(lua_State* L, const wchar_t(&str)[N], std::size_t sz) { - return stack::push(L, str, str + sz); - } - }; - - template - struct pusher { - static int push(lua_State* L, const char16_t(&str)[N]) { - return push(L, str, N - 1); - } - - static int push(lua_State* L, const char16_t(&str)[N], std::size_t sz) { - return stack::push(L, str, str + sz); - } - }; - - template - struct pusher { - static int push(lua_State* L, const char32_t(&str)[N]) { - return push(L, str, N - 1); - } - - static int push(lua_State* L, const char32_t(&str)[N], std::size_t sz) { - return stack::push(L, str, str + sz); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, wchar_t c) { - const wchar_t str[2] = { c, '\0' }; - return stack::push(L, str, 1); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, char16_t c) { - const char16_t str[2] = { c, '\0' }; - return stack::push(L, str, 1); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, char32_t c) { - const char32_t str[2] = { c, '\0' }; - return stack::push(L, str, 1); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const std::wstring& wstr) { - return push(L, wstr.data(), wstr.size()); - } - - static int push(lua_State* L, const std::wstring& wstr, std::size_t sz) { - return stack::push(L, wstr.data(), wstr.data() + sz); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const std::u16string& u16str) { - return push(L, u16str, u16str.size()); - } - - static int push(lua_State* L, const std::u16string& u16str, std::size_t sz) { - return stack::push(L, u16str.data(), u16str.data() + sz); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const std::u32string& u32str) { - return push(L, u32str, u32str.size()); - } - - static int push(lua_State* L, const std::u32string& u32str, std::size_t sz) { - return stack::push(L, u32str.data(), u32str.data() + sz); - } - }; -#endif // codecvt Header Support - - template - struct pusher> { - template - static int push(std::index_sequence, lua_State* L, T&& t) { - int pushcount = 0; - (void)detail::swallow{ 0, (pushcount += stack::push(L, - detail::forward_get(t) - ), 0)... }; - return pushcount; - } - - template - static int push(lua_State* L, T&& t) { - return push(std::index_sequence_for(), L, std::forward(t)); - } - }; - - template - struct pusher> { - template - static int push(lua_State* L, T&& t) { - int pushcount = stack::push(L, detail::forward_get<0>(t)); - pushcount += stack::push(L, detail::forward_get<1>(t)); - return pushcount; - } - }; - - template - struct pusher> { - template - static int push(lua_State* L, T&& t) { - if (t == nullopt) { - return stack::push(L, nullopt); - } - return stack::push(L, t.value()); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, nullopt_t) { - return stack::push(L, lua_nil); - } - }; - - template<> - struct pusher { - static int push(lua_State* L, std::nullptr_t) { - return stack::push(L, lua_nil); - } - }; - - template<> - struct pusher { - static int push(lua_State*, const this_state&) { - return 0; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, const new_table& nt) { - lua_createtable(L, nt.sequence_hint, nt.map_hint); - return 1; - } - }; - } // stack -} // sol - -// end of sol/stack_push.hpp - -// beginning of sol/stack_pop.hpp - -namespace sol { - namespace stack { - template - struct popper { - inline static decltype(auto) pop(lua_State* L) { - record tracking{}; - decltype(auto) r = get(L, -lua_size::value, tracking); - lua_pop(L, tracking.used); - return r; - } - }; - - template - struct popper>::value>> { - static_assert(meta::neg>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!"); - }; - } // stack -} // sol - -// end of sol/stack_pop.hpp - -// beginning of sol/stack_field.hpp - -namespace sol { - namespace stack { - template - struct field_getter { - template - void get(lua_State* L, Key&& key, int tableindex = -2) { - push(L, std::forward(key)); - lua_gettable(L, tableindex); - } - }; - - template - struct field_getter { - template - void get(lua_State* L, Key&& key, int tableindex = -2) { - push(L, std::forward(key)); - lua_rawget(L, tableindex); - } - }; - - template - struct field_getter { - void get(lua_State* L, metatable_t, int tableindex = -1) { - if (lua_getmetatable(L, tableindex) == 0) - push(L, lua_nil); - } - }; - - template - struct field_getter { - void get(lua_State* L, env_t, int tableindex = -1) { -#if SOL_LUA_VERSION < 502 - // Use lua_setfenv - lua_getfenv(L, tableindex); -#else - // Use upvalues as explained in Lua 5.2 and beyond's manual - if (lua_getupvalue(L, tableindex, 1) == nullptr) { - push(L, lua_nil); - } -#endif - } - }; - - template - struct field_getter::value>> { - template - void get(lua_State* L, Key&& key, int = -1) { - lua_getglobal(L, &key[0]); - } - }; - - template - struct field_getter::value>> { - template - void get(lua_State* L, Key&& key, int tableindex = -1) { - lua_getfield(L, tableindex, &key[0]); - } - }; - -#if SOL_LUA_VERSION >= 503 - template - struct field_getter::value && !std::is_same::value>> { - template - void get(lua_State* L, Key&& key, int tableindex = -1) { - lua_geti(L, tableindex, static_cast(key)); - } - }; -#endif // Lua 5.3.x - -#if SOL_LUA_VERSION >= 502 - template - struct field_getter { - void get(lua_State* L, void* key, int tableindex = -1) { - lua_rawgetp(L, tableindex, key); - } - }; -#endif // Lua 5.3.x - - template - struct field_getter::value && !std::is_same::value>> { - template - void get(lua_State* L, Key&& key, int tableindex = -1) { - lua_rawgeti(L, tableindex, static_cast(key)); - } - }; - - template - struct field_getter, b, raw, C> { - template - void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) { - get_field(L, detail::forward_get<0>(keys), tableindex); - void(detail::swallow{ (get_field(L, detail::forward_get(keys)), 0)... }); - reference saved(L, -1); - lua_pop(L, static_cast(sizeof...(I))); - saved.push(); - } - - template - void get(lua_State* L, Keys&& keys) { - apply(std::make_index_sequence(), L, std::forward(keys), lua_absindex(L, -1)); - } - - template - void get(lua_State* L, Keys&& keys, int tableindex) { - apply(std::make_index_sequence(), L, std::forward(keys), tableindex); - } - }; - - template - struct field_getter, b, raw, C> { - template - void get(lua_State* L, Keys&& keys, int tableindex) { - get_field(L, detail::forward_get<0>(keys), tableindex); - get_field(L, detail::forward_get<1>(keys)); - reference saved(L, -1); - lua_pop(L, static_cast(2)); - saved.push(); - } - - template - void get(lua_State* L, Keys&& keys) { - get_field(L, detail::forward_get<0>(keys)); - get_field(L, detail::forward_get<1>(keys)); - reference saved(L, -1); - lua_pop(L, static_cast(2)); - saved.push(); - } - }; - - template - struct field_setter { - template - void set(lua_State* L, Key&& key, Value&& value, int tableindex = -3) { - push(L, std::forward(key)); - push(L, std::forward(value)); - lua_settable(L, tableindex); - } - }; - - template - struct field_setter { - template - void set(lua_State* L, Key&& key, Value&& value, int tableindex = -3) { - push(L, std::forward(key)); - push(L, std::forward(value)); - lua_rawset(L, tableindex); - } - }; - - template - struct field_setter { - template - void set(lua_State* L, metatable_t, Value&& value, int tableindex = -2) { - push(L, std::forward(value)); - lua_setmetatable(L, tableindex); - } - }; - - template - struct field_setter::value>> { - template - void set(lua_State* L, Key&& key, Value&& value, int = -2) { - push(L, std::forward(value)); - lua_setglobal(L, &key[0]); - } - }; - - template - struct field_setter::value>> { - template - void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { - push(L, std::forward(value)); - lua_setfield(L, tableindex, &key[0]); - } - }; - -#if SOL_LUA_VERSION >= 503 - template - struct field_setter::value && !std::is_same::value>> { - template - void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { - push(L, std::forward(value)); - lua_seti(L, tableindex, static_cast(key)); - } - }; -#endif // Lua 5.3.x - - template - struct field_setter::value && !std::is_same::value>> { - template - void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { - push(L, std::forward(value)); - lua_rawseti(L, tableindex, static_cast(key)); - } - }; - -#if SOL_LUA_VERSION >= 502 - template - struct field_setter { - template - void set(lua_State* L, void* key, Value&& value, int tableindex = -2) { - push(L, std::forward(value)); - lua_rawsetp(L, tableindex, key); - } - }; -#endif // Lua 5.2.x - - template - struct field_setter, b, raw, C> { - template - void apply(std::index_sequence, lua_State* L, Key&& keys, Value&& value, int tableindex) { - I < 1 ? - set_field(L, detail::forward_get(keys), std::forward(value), tableindex) : - set_field(L, detail::forward_get(keys), std::forward(value)); - } - - template - void apply(std::index_sequence, lua_State* L, Keys&& keys, Value&& value, int tableindex) { - I0 < 1 ? get_field(L, detail::forward_get(keys), tableindex) : get_field(L, detail::forward_get(keys), -1); - apply(std::index_sequence(), L, std::forward(keys), std::forward(value), -1); - } - - template - void top_apply(std::index_sequence, lua_State* L, Keys&& keys, Value&& value, int tableindex) { - apply(std::index_sequence(), L, std::forward(keys), std::forward(value), tableindex); - lua_pop(L, static_cast(sizeof...(I))); - } - - template - void set(lua_State* L, Keys&& keys, Value&& value, int tableindex = -3) { - top_apply(std::make_index_sequence(), L, std::forward(keys), std::forward(value), tableindex); - } - }; - - template - struct field_setter, b, raw, C> { - template - void set(lua_State* L, Keys&& keys, Value&& value, int tableindex = -1) { - get_field(L, detail::forward_get<0>(keys), tableindex); - set_field(L, detail::forward_get<1>(keys), std::forward(value)); - lua_pop(L, 1); - } - }; - } // stack -} // sol - -// end of sol/stack_field.hpp - -// beginning of sol/stack_probe.hpp - -namespace sol { - namespace stack { - template - struct probe_field_getter { - template - probe get(lua_State* L, Key&& key, int tableindex = -2) { - if (!b && !maybe_indexable(L, tableindex)) { - return probe(false, 0); - } - get_field(L, std::forward(key), tableindex); - return probe(!check(L), 1); - } - }; - - template - struct probe_field_getter, b, raw, C> { - template - probe get(lua_State* L, Keys&& keys, int tableindex = -2) { - if (!b && !maybe_indexable(L, tableindex)) { - return probe(false, 0); - } - get_field(L, std::get<0>(keys), tableindex); - if (!maybe_indexable(L)) { - return probe(false, 1); - } - get_field(L, std::get<1>(keys), tableindex); - return probe(!check(L), 2); - } - }; - - template - struct probe_field_getter, b, raw, C> { - template - probe apply(std::index_sequence, int sofar, lua_State* L, Keys&& keys, int tableindex) { - get_field < I < 1 && b, raw>(L, std::get(keys), tableindex); - return probe(!check(L), sofar); - } - - template - probe apply(std::index_sequence, int sofar, lua_State* L, Keys&& keys, int tableindex) { - get_field < I < 1 && b, raw>(L, std::get(keys), tableindex); - if (!maybe_indexable(L)) { - return probe(false, sofar); - } - return apply(std::index_sequence(), sofar + 1, L, std::forward(keys), -1); - } - - template - probe get(lua_State* L, Keys&& keys, int tableindex = -2) { - if (!b && !maybe_indexable(L, tableindex)) { - return probe(false, 0); - } - return apply(std::index_sequence_for(), 1, L, std::forward(keys), tableindex); - } - }; - } // stack -} // sol - -// end of sol/stack_probe.hpp - -#include - -namespace sol { - namespace stack { - namespace stack_detail { - template - inline int push_as_upvalues(lua_State* L, T& item) { - typedef std::decay_t 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 data_t; - - data_t data{ {} }; - std::memcpy(&data[0], std::addressof(item), itemsize); - int pushcount = 0; - for (auto&& v : data) { - pushcount += push(L, lightuserdata_value(v)); - } - return pushcount; - } - - template - inline std::pair get_as_upvalues(lua_State* L, int index = 2) { - const static std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*); - typedef std::array data_t; - data_t voiddata{ {} }; - for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { - voiddata[i] = get(L, upvalue_index(index++)); - } - return std::pair(*reinterpret_cast(static_cast(voiddata.data())), index); - } - - struct evaluator { - template - static decltype(auto) eval(types<>, std::index_sequence<>, lua_State*, int, record&, Fx&& fx, Args&&... args) { - return std::forward(fx)(std::forward(args)...); - } - - template - static decltype(auto) eval(types, std::index_sequence, lua_State* L, int start, record& tracking, Fx&& fx, FxArgs&&... fxargs) { - return eval(types(), std::index_sequence(), L, start, tracking, std::forward(fx), std::forward(fxargs)..., stack_detail::unchecked_get(L, start + tracking.used, tracking)); - } - }; - - template ::value>> - inline decltype(auto) call(types, types ta, std::index_sequence tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { -#ifndef _MSC_VER - static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); -#endif // This compiler make me so fucking sad - multi_check(L, start, type_panic); - record tracking{}; - return evaluator{}.eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); - } - - template - inline void call(types, types ta, std::index_sequence tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { -#ifndef _MSC_VER - static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); -#endif // This compiler make me so fucking sad - multi_check(L, start, type_panic); - record tracking{}; - evaluator{}.eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); - } - } // stack_detail - - template - int set_ref(lua_State* L, T&& arg, int tableindex = -2) { - push(L, std::forward(arg)); - return luaL_ref(L, tableindex); - } - - template ::value>> - inline decltype(auto) call(types tr, types ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { - typedef std::make_index_sequence args_indices; - return stack_detail::call(tr, ta, args_indices(), L, start, std::forward(fx), std::forward(args)...); - } - - template ::value>> - inline decltype(auto) call(types tr, types ta, lua_State* L, Fx&& fx, FxArgs&&... args) { - return call(tr, ta, L, 1, std::forward(fx), std::forward(args)...); - } - - template - inline void call(types tr, types ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { - typedef std::make_index_sequence args_indices; - stack_detail::call(tr, ta, args_indices(), L, start, std::forward(fx), std::forward(args)...); - } - - template - inline void call(types tr, types ta, lua_State* L, Fx&& fx, FxArgs&&... args) { - call(tr, ta, L, 1, std::forward(fx), std::forward(args)...); - } - - template ::value>> - inline decltype(auto) call_from_top(types tr, types ta, lua_State* L, Fx&& fx, FxArgs&&... args) { - return call(tr, ta, L, static_cast(lua_gettop(L) - sizeof...(Args)), std::forward(fx), std::forward(args)...); - } - - template - inline void call_from_top(types tr, types ta, lua_State* L, Fx&& fx, FxArgs&&... args) { - call(tr, ta, L, static_cast(lua_gettop(L) - sizeof...(Args)), std::forward(fx), std::forward(args)...); - } - - template - inline int call_into_lua(types tr, types ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) { - call(tr, ta, L, start, std::forward(fx), std::forward(fxargs)...); - lua_settop(L, 0); - return 0; - } - - template>::value>> - inline int call_into_lua(types, types ta, lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) { - decltype(auto) r = call(types>(), ta, L, start, std::forward(fx), std::forward(fxargs)...); - lua_settop(L, 0); - return push_reference(L, std::forward(r)); - } - - template - inline int call_lua(lua_State* L, int start, Fx&& fx, FxArgs&&... fxargs) { - typedef lua_bind_traits> traits_type; - typedef typename traits_type::args_list args_list; - typedef typename traits_type::returns_list returns_list; - return call_into_lua(returns_list(), args_list(), L, start, std::forward(fx), std::forward(fxargs)...); - } - - inline call_syntax get_call_syntax(lua_State* L, const std::string& key, int index) { - if (lua_gettop(L) == 0) { - return call_syntax::dot; - } - luaL_getmetatable(L, key.c_str()); - auto pn = pop_n(L, 1); - if (lua_compare(L, -1, index, LUA_OPEQ) != 1) { - return call_syntax::dot; - } - return call_syntax::colon; - } - - inline void script(lua_State* L, const std::string& code) { - if (luaL_dostring(L, code.c_str())) { - lua_error(L); - } - } - - inline void script_file(lua_State* L, const std::string& filename) { - if (luaL_dofile(L, filename.c_str())) { - lua_error(L); - } - } - - inline void luajit_exception_handler(lua_State* L, int(*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) { -#ifdef SOL_LUAJIT - lua_pushlightuserdata(L, (void*)handler); - auto pn = pop_n(L, 1); - luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_ON); -#else - (void)L; - (void)handler; -#endif - } - - inline void luajit_exception_off(lua_State* L) { -#ifdef SOL_LUAJIT - luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC | LUAJIT_MODE_OFF); -#else - (void)L; -#endif - } - } // stack -} // sol - -// end of sol/stack.hpp - -// beginning of sol/object_base.hpp - -namespace sol { - - template - class basic_object_base : public base_t { - private: - template - decltype(auto) as_stack(std::true_type) const { - return stack::get(base_t::lua_state(), base_t::stack_index()); - } - - template - decltype(auto) as_stack(std::false_type) const { - base_t::push(); - return stack::pop(base_t::lua_state()); - } - - template - bool is_stack(std::true_type) const { - return stack::check(base_t::lua_state(), base_t::stack_index(), no_panic); - } - - template - bool is_stack(std::false_type) const { - int r = base_t::registry_index(); - if (r == LUA_REFNIL) - return meta::any_same, lua_nil_t, nullopt_t, std::nullptr_t>::value ? true : false; - if (r == LUA_NOREF) - return false; - auto pp = stack::push_pop(*this); - return stack::check(base_t::lua_state(), -1, no_panic); - } - - public: - basic_object_base() noexcept = default; - basic_object_base(const basic_object_base&) = default; - basic_object_base(basic_object_base&&) = default; - basic_object_base& operator=(const basic_object_base&) = default; - basic_object_base& operator=(basic_object_base&&) = default; - template , basic_object_base>>> = meta::enabler> - basic_object_base(T&& arg, Args&&... args) : base_t(std::forward(arg), std::forward(args)...) { } - - template - decltype(auto) as() const { - return as_stack(std::is_same()); - } - - template - bool is() const { - return is_stack(std::is_same()); - } - }; -} // sol - -// end of sol/object_base.hpp - -// beginning of sol/userdata.hpp - -namespace sol { - template - class basic_userdata : public basic_table { - typedef basic_table base_t; - public: - basic_userdata() noexcept = default; - template , basic_userdata>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_userdata(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_userdata>::value) { - auto pp = stack::push_pop(*this); - type_assert(base_t::lua_state(), -1, type::userdata); - } -#endif // Safety - } - basic_userdata(const basic_userdata&) = default; - basic_userdata(basic_userdata&&) = default; - basic_userdata& operator=(const basic_userdata&) = default; - basic_userdata& operator=(basic_userdata&&) = default; - basic_userdata(const stack_reference& r) : basic_userdata(r.lua_state(), r.stack_index()) {} - basic_userdata(stack_reference&& r) : basic_userdata(r.lua_state(), r.stack_index()) {} - template >>, meta::neg, ref_index>>> = meta::enabler> - basic_userdata(lua_State* L, T&& r) : basic_userdata(L, sol::ref_index(r.registry_index())) {} - basic_userdata(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_userdata(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, index, type_panic); -#endif // Safety - } - }; - - template - class basic_lightuserdata : public basic_object_base { - typedef basic_object_base base_t; - public: - basic_lightuserdata() noexcept = default; - template , basic_lightuserdata>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_lightuserdata(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_lightuserdata>::value) { - auto pp = stack::push_pop(*this); - type_assert(base_t::lua_state(), -1, type::lightuserdata); - } -#endif // Safety - } - basic_lightuserdata(const basic_lightuserdata&) = default; - basic_lightuserdata(basic_lightuserdata&&) = default; - basic_lightuserdata& operator=(const basic_lightuserdata&) = default; - basic_lightuserdata& operator=(basic_lightuserdata&&) = default; - basic_lightuserdata(const stack_reference& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} - basic_lightuserdata(stack_reference&& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} - template >>, meta::neg, ref_index>>> = meta::enabler> - basic_lightuserdata(lua_State* L, T&& r) : basic_lightuserdata(L, sol::ref_index(r.registry_index())) {} - basic_lightuserdata(lua_State* L, int index = -1) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_lightuserdata(lua_State* L, ref_index index) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, index, type_panic); -#endif // Safety - } - }; - -} // sol - -// end of sol/userdata.hpp - -// beginning of sol/as_args.hpp - -namespace sol { - template - struct to_args_t { - T src; - }; - - template - auto as_args(Source&& source) { - return to_args_t{ std::forward(source) }; - } - - namespace stack { - template - struct pusher> { - int push(lua_State* L, const to_args_t& e) { - int p = 0; - for (const auto& i : e.src) { - p += stack::push(L, i); - } - return p; - } - }; - } -} // sol - -// end of sol/as_args.hpp - -// beginning of sol/variadic_args.hpp - -// beginning of sol/stack_proxy.hpp - -// beginning of sol/function.hpp - -// beginning of sol/function_result.hpp - -// beginning of sol/proxy_base.hpp - -namespace sol { - struct proxy_base_tag {}; - - template - struct proxy_base : proxy_base_tag { - operator std::string() const { - const Super& super = *static_cast(static_cast(this)); - return super.template get(); - } - - template>, is_proxy_primitive>> = meta::enabler> - operator T () const { - const Super& super = *static_cast(static_cast(this)); - return super.template get(); - } - - template>, meta::neg>>> = meta::enabler> - operator T& () const { - const Super& super = *static_cast(static_cast(this)); - return super.template get(); - } - }; -} // sol - -// end of sol/proxy_base.hpp - -#include - -namespace sol { - struct function_result : public proxy_base { - private: - lua_State* L; - int index; - int returncount; - - public: - function_result() = default; - function_result(lua_State* Ls, int idx = -1, int retnum = 0) : L(Ls), index(idx), returncount(retnum) { - - } - function_result(const function_result&) = default; - function_result& operator=(const function_result&) = default; - function_result(function_result&& o) : L(o.L), index(o.index), returncount(o.returncount) { - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - } - function_result& operator=(function_result&& o) { - L = o.L; - index = o.index; - returncount = o.returncount; - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - return *this; - } - - template - decltype(auto) get() const { - return stack::get(L, index); - } - - call_status status() const noexcept { - return call_status::ok; - } - - bool valid() const noexcept { - return status() == call_status::ok || status() == call_status::yielded; - } - - lua_State* lua_state() const { return L; }; - int stack_index() const { return index; }; - - ~function_result() { - lua_pop(L, returncount); - } - }; -} // sol - -// end of sol/function_result.hpp - -// beginning of sol/function_types.hpp - -// beginning of sol/function_types_core.hpp - -// beginning of sol/wrapper.hpp - -namespace sol { - - template - struct wrapper { - typedef lua_bind_traits traits_type; - typedef typename traits_type::args_list args_list; - typedef typename traits_type::args_list free_args_list; - typedef typename traits_type::returns_list returns_list; - - template - static decltype(auto) call(F& f, Args&&... args) { - return f(std::forward(args)...); - } - - struct caller { - template - decltype(auto) operator()(F& fx, Args&&... args) const { - return call(fx, std::forward(args)...); - } - }; - }; - - template - struct wrapper>>::value>> { - typedef lua_bind_traits traits_type; - typedef typename traits_type::args_list args_list; - typedef typename traits_type::args_list free_args_list; - typedef typename traits_type::returns_list returns_list; - - template - static decltype(auto) invoke(Args&&... args) { - return fx(std::forward(args)...); - } - - template - static decltype(auto) call(F& fx, Args&&... args) { - return fx(std::forward(args)...); - } - - struct caller { - template - decltype(auto) operator()(F& fx, Args&&... args) const { - return call(fx, std::forward(args)...); - } - }; - - template - struct invoker { - template - decltype(auto) operator()(Args&&... args) const { - return invoke(std::forward(args)...); - } - }; - }; - - template - struct wrapper>::value>> { - typedef lua_bind_traits traits_type; - typedef typename traits_type::object_type object_type; - typedef typename traits_type::return_type return_type; - typedef typename traits_type::args_list args_list; - typedef types free_args_list; - typedef typename traits_type::returns_list returns_list; - - template - static decltype(auto) invoke(object_type& mem) { - return mem.*fx; - } - - template - static decltype(auto) invoke(object_type& mem, Arg&& arg, Args&&...) { - return mem.*fx = std::forward(arg); - } - - template - static decltype(auto) call(Fx&& fx, object_type& mem) { - return (mem.*fx); - } - - template - static void call(Fx&& fx, object_type& mem, Arg&& arg, Args&&...) { - (mem.*fx) = std::forward(arg); - } - - struct caller { - template - decltype(auto) operator()(Fx&& fx, object_type& mem, Args&&... args) const { - return call(std::forward(fx), mem, std::forward(args)...); - } - }; - - template - struct invoker { - template - decltype(auto) operator()(Args&&... args) const { - return invoke(std::forward(args)...); - } - }; - }; - - template - struct member_function_wrapper { - typedef O object_type; - typedef lua_bind_traits traits_type; - typedef typename traits_type::args_list args_list; - typedef types free_args_list; - typedef meta::tuple_types returns_list; - - template - static R invoke(O& mem, Args&&... args) { - return (mem.*fx)(std::forward(args)...); - } - - template - static R call(Fx&& fx, O& mem, Args&&... args) { - return (mem.*fx)(std::forward(args)...); - } - - struct caller { - template - decltype(auto) operator()(Fx&& fx, O& mem, Args&&... args) const { - return call(std::forward(fx), mem, std::forward(args)...); - } - }; - - template - struct invoker { - template - decltype(auto) operator()(O& mem, Args&&... args) const { - return invoke(mem, std::forward(args)...); - } - }; - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - -} // sol - -// end of sol/wrapper.hpp - -namespace sol { - namespace function_detail { - template - inline int call(lua_State* L) { - Fx& fx = stack::get>(L, upvalue_index(start)); - return fx(L); - } - } // function_detail -} // sol - -// end of sol/function_types_core.hpp - -// beginning of sol/function_types_templated.hpp - -// beginning of sol/call.hpp - -// beginning of sol/protect.hpp - -namespace sol { - - template - struct protect_t { - T value; - - template >> = meta::enabler> - protect_t(Arg&& arg, Args&&... args) : value(std::forward(arg), std::forward(args)...) {} - - protect_t(const protect_t&) = default; - protect_t(protect_t&&) = default; - protect_t& operator=(const protect_t&) = default; - protect_t& operator=(protect_t&&) = default; - - }; - - template - auto protect(T&& value) { - return protect_t>(std::forward(value)); - } - -} // sol - -// end of sol/protect.hpp - -// beginning of sol/property.hpp - -namespace sol { - - struct no_prop { }; - - template - struct property_wrapper { - typedef std::integral_constant::value> can_read; - typedef std::integral_constant::value> can_write; - typedef std::conditional_t Read; - typedef std::conditional_t Write; - Read read; - Write write; - - template - property_wrapper(Rx&& r, Wx&& w) : read(std::forward(r)), write(std::forward(w)) {} - }; - - namespace property_detail { - template - inline decltype(auto) property(std::true_type, R&& read, W&& write) { - return property_wrapper, std::decay_t>(std::forward(read), std::forward(write)); - } - template - inline decltype(auto) property(std::false_type, W&& write, R&& read) { - return property_wrapper, std::decay_t>(std::forward(read), std::forward(write)); - } - template - inline decltype(auto) property(std::true_type, R&& read) { - return property_wrapper, void>(std::forward(read), no_prop()); - } - template - inline decltype(auto) property(std::false_type, W&& write) { - return property_wrapper>(no_prop(), std::forward(write)); - } - } // property_detail - - template - inline decltype(auto) property(F&& f, G&& g) { - typedef lua_bind_traits> left_traits; - typedef lua_bind_traits> right_traits; - return property_detail::property(meta::boolean<(left_traits::free_arity < right_traits::free_arity)>(), std::forward(f), std::forward(g)); - } - - template - inline decltype(auto) property(F&& f) { - typedef lua_bind_traits> left_traits; - return property_detail::property(meta::boolean<(left_traits::free_arity < 2)>(), std::forward(f)); - } - - template - inline decltype(auto) readonly_property(F&& f) { - return property_detail::property(std::true_type(), std::forward(f)); - } - - template - inline decltype(auto) writeonly_property(F&& f) { - return property_detail::property(std::false_type(), std::forward(f)); - } - - template - struct readonly_wrapper { - T v; - - readonly_wrapper(T v) : v(std::move(v)) {} - - operator T& () { - return v; - } - operator const T& () const { - return v; - } - }; - - // Allow someone to make a member variable readonly (const) - template - inline auto readonly(R T::* v) { - return readonly_wrapper>(v); - } - - template - struct var_wrapper { - T value; - template - var_wrapper(Args&&... args) : value(std::forward(args)...) {} - var_wrapper(const var_wrapper&) = default; - var_wrapper(var_wrapper&&) = default; - var_wrapper& operator=(const var_wrapper&) = default; - var_wrapper& operator=(var_wrapper&&) = default; - }; - - template - inline auto var(V&& v) { - typedef meta::unqualified_t T; - return var_wrapper(std::forward(v)); - } - - namespace meta { - template - struct is_member_object : std::is_member_object_pointer {}; - - template - struct is_member_object> : std::true_type {}; - } - -} // sol - -// end of sol/property.hpp - -namespace sol { - namespace function_detail { - inline int no_construction_error(lua_State* L) { - return luaL_error(L, "sol: cannot call this constructor (tagged as non-constructible)"); - } - } - - namespace call_detail { - - template - inline auto& pick(std::true_type, property_wrapper& f) { - return f.read; - } - - template - inline auto& pick(std::false_type, property_wrapper& f) { - return f.write; - } - - template - struct void_call : void_call> {}; - - template - struct void_call> { - static void call(Args...) {} - }; - - template - struct constructor_match { - T* obj; - - constructor_match(T* o) : obj(o) {} - - template - int operator()(types, index_value, types r, types a, lua_State* L, int, int start) const { - detail::default_construct func{}; - return stack::call_into_lua(r, a, L, start, func, obj); - } - }; - - namespace overload_detail { - template - inline int overload_match_arity(types<>, std::index_sequence<>, std::index_sequence, Match&&, lua_State* L, int, int, Args&&...) { - return luaL_error(L, "sol: no matching function call takes this number of arguments and the specified types"); - } - - template - inline int overload_match_arity(types, std::index_sequence, std::index_sequence, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - typedef lua_bind_traits> traits; - typedef meta::tuple_types return_types; - typedef typename traits::free_args_list args_list; - // compile-time eliminate any functions that we know ahead of time are of improper arity - if (meta::find_in_pack_v, index_value...>::value) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - stack::record tracking{}; - if (!stack::stack_detail::check_types{}.check(args_list(), L, start, no_panic, tracking)) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - return matchfx(types(), index_value(), return_types(), args_list(), L, fxarity, start, std::forward(args)...); - } - - template - inline int overload_match_arity_single(types<>, std::index_sequence<>, std::index_sequence, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - - template - inline int overload_match_arity_single(types, std::index_sequence, std::index_sequence, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - typedef lua_bind_traits> traits; - typedef meta::tuple_types return_types; - typedef typename traits::free_args_list args_list; - // compile-time eliminate any functions that we know ahead of time are of improper arity - if (meta::find_in_pack_v, index_value...>::value) { - return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) { - return overload_match_arity(types<>(), std::index_sequence<>(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - return matchfx(types(), index_value(), return_types(), args_list(), L, fxarity, start, std::forward(args)...); - } - - template - inline int overload_match_arity_single(types, std::index_sequence, std::index_sequence, Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - typedef lua_bind_traits> traits; - typedef meta::tuple_types return_types; - typedef typename traits::free_args_list args_list; - // compile-time eliminate any functions that we know ahead of time are of improper arity - if (meta::find_in_pack_v, index_value...>::value) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - if (!traits::runtime_variadics_t::value && traits::free_arity != fxarity) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - stack::record tracking{}; - if (!stack::stack_detail::check_types{}.check(args_list(), L, start, no_panic, tracking)) { - return overload_match_arity(types(), std::index_sequence(), std::index_sequence(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - return matchfx(types(), index_value(), return_types(), args_list(), L, fxarity, start, std::forward(args)...); - } - } // overload_detail - - template - inline int overload_match_arity(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - return overload_detail::overload_match_arity_single(types(), std::make_index_sequence(), std::index_sequence<>(), std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - - template - inline int overload_match(Match&& matchfx, lua_State* L, int start, Args&&... args) { - int fxarity = lua_gettop(L) - (start - 1); - return overload_match_arity(std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - - template - inline int construct_match(Match&& matchfx, lua_State* L, int fxarity, int start, Args&&... args) { - // use same overload resolution matching as all other parts of the framework - return overload_match_arity::call)...>(std::forward(matchfx), L, fxarity, start, std::forward(args)...); - } - - template - inline int construct(lua_State* L) { - static const auto& meta = usertype_traits::metatable(); - int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; - argcount -= static_cast(syntax); - - T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); - T*& referencepointer = *pointerpointer; - T* obj = reinterpret_cast(pointerpointer + 1); - referencepointer = obj; - reference userdataref(L, -1); - userdataref.pop(); - - construct_match(constructor_match(obj), L, argcount, 1 + static_cast(syntax)); - - userdataref.push(); - luaL_getmetatable(L, &meta[0]); - if (type_of(L, -1) == type::lua_nil) { - lua_pop(L, 1); - return luaL_error(L, "sol: unable to get usertype metatable"); - } - - lua_setmetatable(L, -2); - return 1; - } - - template - struct agnostic_lua_call_wrapper { - template - static int call(lua_State* L, Fx&& f, Args&&... args) { - typedef wrapper> wrap; - typedef typename wrap::returns_list returns_list; - typedef typename wrap::free_args_list args_list; - typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + 1, caller(), std::forward(f), std::forward(args)...); - } - }; - - template - struct agnostic_lua_call_wrapper, true, is_variable, checked, boost, C> { - template - static int call(lua_State* L, F&& f) { - return stack::push_reference(L, detail::unwrap(f.value)); - } - }; - - template - struct agnostic_lua_call_wrapper, false, is_variable, checked, boost, C> { - template - static int call_assign(std::true_type, lua_State* L, V&& f) { - detail::unwrap(f.value) = stack::get>(L, boost + (is_variable ? 3 : 1)); - return 0; - } - - template - static int call_assign(std::false_type, lua_State* L, Args&&...) { - return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available"); - } - - template - static int call_const(std::false_type, lua_State* L, Args&&... args) { - typedef meta::unwrapped_t R; - return call_assign(std::is_assignable>, R>(), L, std::forward(args)...); - } - - template - static int call_const(std::true_type, lua_State* L, Args&&...) { - return luaL_error(L, "sol: cannot write to a readonly (const) variable"); - } - - template - static int call(lua_State* L, V&& f) { - return call_const(std::is_const>(), L, f); - } - }; - - template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, lua_r_CFunction f) { - return f(L); - } - }; - - template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, lua_CFunction f) { - return f(L); - } - }; - - template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, const no_prop&) { - return luaL_error(L, is_index ? "sol: cannot read from a writeonly property" : "sol: cannot write to a readonly property"); - } - }; - - template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, const no_construction&) { - return function_detail::no_construction_error(L); - } - }; - - template - struct agnostic_lua_call_wrapper, is_index, is_variable, checked, boost, C> { - static int call(lua_State*, const bases&) { - // Uh. How did you even call this, lul - return 0; - } - }; - - template - struct agnostic_lua_call_wrapper, is_index, is_variable, checked, boost, C> { - static int call(lua_State* L, std::reference_wrapper f) { - return agnostic_lua_call_wrapper{}.call(L, f.get()); - } - }; - - template - struct lua_call_wrapper : agnostic_lua_call_wrapper {}; - - template - struct lua_call_wrapper::value>> { - typedef wrapper> wrap; - typedef typename wrap::object_type object_type; - - template - static int call(lua_State* L, Fx&& f, object_type& o) { - typedef typename wrap::returns_list returns_list; - typedef typename wrap::args_list args_list; - typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + ( is_variable ? 3 : 2 ), caller(), std::forward(f), o); - } - - template - static int call(lua_State* L, Fx&& f) { - typedef std::conditional_t::value, object_type, T> Ta; -#ifdef SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - return luaL_error(L, "sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)"); - } - object_type* o = static_cast(maybeo.value()); - return call(L, std::forward(f), *o); -#else - object_type& o = static_cast(*stack::get>(L, 1)); - return call(L, std::forward(f), o); -#endif // Safety - } - }; - - template - struct lua_call_wrapper::value>> { - typedef lua_bind_traits traits_type; - typedef wrapper> wrap; - typedef typename wrap::object_type object_type; - - template - static int call_assign(std::true_type, lua_State* L, V&& f, object_type& o) { - typedef typename wrap::args_list args_list; - typedef typename wrap::caller caller; - return stack::call_into_lua(types(), args_list(), L, boost + ( is_variable ? 3 : 2 ), caller(), f, o); - } - - template - static int call_assign(std::true_type, lua_State* L, V&& f) { - typedef std::conditional_t::value, object_type, T> Ta; -#ifdef SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - if (is_variable) { - return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)"); - } - return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)"); - } - object_type* o = static_cast(maybeo.value()); - return call_assign(std::true_type(), L, f, *o); -#else - object_type& o = static_cast(*stack::get>(L, 1)); - return call_assign(std::true_type(), L, f, o); -#endif // Safety - } - - template - static int call_assign(std::false_type, lua_State* L, Args&&...) { - return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available"); - } - - template - static int call_const(std::false_type, lua_State* L, Args&&... args) { - typedef typename traits_type::return_type R; - return call_assign(std::is_copy_assignable>(), L, std::forward(args)...); - } - - template - static int call_const(std::true_type, lua_State* L, Args&&...) { - return luaL_error(L, "sol: cannot write to a readonly (const) variable"); - } - - template - static int call(lua_State* L, V&& f) { - return call_const(std::is_const(), L, std::forward(f)); - } - - template - static int call(lua_State* L, V&& f, object_type& o) { - return call_const(std::is_const(), L, std::forward(f), o); - } - }; - - template - struct lua_call_wrapper::value>> { - typedef lua_bind_traits traits_type; - typedef wrapper> wrap; - typedef typename wrap::object_type object_type; - - template - static int call(lua_State* L, V&& v, object_type& o) { - typedef typename wrap::returns_list returns_list; - typedef typename wrap::caller caller; - F f(std::forward(v)); - return stack::call_into_lua(returns_list(), types<>(), L, boost + ( is_variable ? 3 : 2 ), caller(), f, o); - } - - template - static int call(lua_State* L, V&& f) { - typedef std::conditional_t::value, object_type, T> Ta; -#ifdef SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - if (is_variable) { - return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)"); - } - return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)"); - } - object_type* o = static_cast(maybeo.value()); - return call(L, f, *o); -#else - object_type& o = static_cast(*stack::get>(L, 1)); - return call(L, f, o); -#endif // Safety - } - }; - - template - struct lua_call_wrapper, false, is_variable, checked, boost, C> { - typedef lua_bind_traits traits_type; - typedef wrapper> wrap; - typedef typename wrap::object_type object_type; - - template - static int call(lua_State* L, V&&) { - return luaL_error(L, "sol: cannot write to a sol::readonly variable"); - } - - template - static int call(lua_State* L, V&&, object_type&) { - return luaL_error(L, "sol: cannot write to a sol::readonly variable"); - } - }; - - template - struct lua_call_wrapper, true, is_variable, checked, boost, C> : lua_call_wrapper { - - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef constructor_list F; - - static int call(lua_State* L, F&) { - const auto& metakey = usertype_traits::metatable(); - int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; - argcount -= static_cast(syntax); - - T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); - reference userdataref(L, -1); - T*& referencepointer = *pointerpointer; - T* obj = reinterpret_cast(pointerpointer + 1); - referencepointer = obj; - - construct_match(constructor_match(obj), L, argcount, boost + 1 + static_cast(syntax)); - - userdataref.push(); - luaL_getmetatable(L, &metakey[0]); - if (type_of(L, -1) == type::lua_nil) { - lua_pop(L, 1); - return luaL_error(L, "sol: unable to get usertype metatable"); - } - - lua_setmetatable(L, -2); - return 1; - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef constructor_wrapper F; - - struct onmatch { - template - int operator()(types, index_value, types r, types a, lua_State* L, int, int start, F& f) { - const auto& metakey = usertype_traits::metatable(); - T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); - reference userdataref(L, -1); - T*& referencepointer = *pointerpointer; - T* obj = reinterpret_cast(pointerpointer + 1); - referencepointer = obj; - - auto& func = std::get(f.functions); - stack::call_into_lua(r, a, L, boost + start, func, detail::implicit_wrapper(obj)); - - userdataref.push(); - luaL_getmetatable(L, &metakey[0]); - if (type_of(L, -1) == type::lua_nil) { - lua_pop(L, 1); - std::string err = "sol: unable to get usertype metatable for "; - err += usertype_traits::name(); - return luaL_error(L, err.c_str()); - } - lua_setmetatable(L, -2); - - return 1; - } - }; - - static int call(lua_State* L, F& f) { - call_syntax syntax = stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1); - int syntaxval = static_cast(syntax); - int argcount = lua_gettop(L) - syntaxval; - return construct_match>...>(onmatch(), L, argcount, 1 + syntaxval, f); - } - - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, std::enable_if_t::value>> { - typedef destructor_wrapper F; - - static int call(lua_State* L, const F&) { - return detail::usertype_alloc_destroy(L); - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, std::enable_if_t::value>> { - typedef destructor_wrapper F; - - static int call(lua_State* L, const F& f) { - T& obj = stack::get(L); - f.fx(detail::implicit_wrapper(obj)); - return 0; - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef overload_set F; - - struct on_match { - template - int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.functions); - return lua_call_wrapper{}.call(L, f); - } - }; - - static int call(lua_State* L, F& fx) { - return overload_match_arity(on_match(), L, lua_gettop(L), 1, fx); - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef factory_wrapper F; - - struct on_match { - template - int operator()(types, index_value, types, types, lua_State* L, int, int, F& fx) { - auto& f = std::get(fx.functions); - return lua_call_wrapper{}.call(L, f); - } - }; - - static int call(lua_State* L, F& fx) { - return overload_match_arity(on_match(), L, lua_gettop(L) - boost, 1 + boost, fx); - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef std::conditional_t P; - typedef meta::unqualified_t

U; - typedef wrapper wrap; - typedef lua_bind_traits traits_type; - typedef meta::unqualified_t> object_type; - - template - static int self_call(std::true_type, lua_State* L, F&& f) { - // The type being void means we don't have any arguments, so it might be a free functions? - typedef typename traits_type::free_args_list args_list; - typedef typename wrap::returns_list returns_list; - typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f); - } - - template - static int self_call(std::false_type, lua_State* L, F&& f) { - typedef meta::pop_front_type_t args_list; - typedef T Ta; -#ifdef SOL_SAFE_USERTYPE - auto maybeo = stack::check_get(L, 1); - if (!maybeo || maybeo.value() == nullptr) { - if (is_variable) { - return luaL_error(L, "sol: 'self' argument is lua_nil (bad '.' access?)"); - } - return luaL_error(L, "sol: 'self' argument is lua_nil (pass 'self' as first argument)"); - } - object_type* o = static_cast(maybeo.value()); -#else - object_type* o = static_cast(stack::get>(L, 1)); -#endif // Safety - typedef typename wrap::returns_list returns_list; - typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, *o); - } - - template - static int defer_call(std::false_type, lua_State* L, F&& f, Args&&... args) { - return self_call(meta::any, meta::boolean>::value != type::userdata>>(), L, pick(meta::boolean(), f), std::forward(args)...); - } - - template - static int defer_call(std::true_type, lua_State* L, F&& f, Args&&... args) { - auto& p = pick(meta::boolean(), std::forward(f)); - return lua_call_wrapper, is_index, is_variable, checked, boost>{}.call(L, p, std::forward(args)...); - } - - template - static int call(lua_State* L, F&& f, Args&&... args) { - typedef meta::any< - std::is_void, - std::is_same, - meta::is_specialization_of, - meta::is_specialization_of, - meta::is_specialization_of, - std::is_member_pointer - > is_specialized; - return defer_call(is_specialized(), L, std::forward(f), std::forward(args)...); - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - typedef protect_t F; - - template - static int call(lua_State* L, F& fx, Args&&... args) { - return lua_call_wrapper{}.call(L, fx.value, std::forward(args)...); - } - }; - - template - struct lua_call_wrapper, is_index, is_variable, checked, boost, C> { - template - static int call(lua_State* L, F&& f) { - return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::get<0>(f.arguments)); - } - }; - - template - inline int call_wrapped(lua_State* L, Fx&& fx, Args&&... args) { - return lua_call_wrapper, is_index, is_variable, stack::stack_detail::default_check_arguments, boost>{}.call(L, std::forward(fx), std::forward(args)...); - } - - template - inline int call_user(lua_State* L) { - auto& fx = stack::get>(L, upvalue_index(start)); - return call_wrapped(L, fx); - } - - template - struct is_var_bind : std::false_type {}; - - template - struct is_var_bind::value>> : std::true_type {}; - - template <> - struct is_var_bind : std::true_type {}; - - template - struct is_var_bind> : std::true_type {}; - - template - struct is_var_bind> : std::true_type {}; - - template - struct is_var_bind> : is_var_bind {}; - } // call_detail - - template - struct is_variable_binding : call_detail::is_var_bind> {}; - - template - struct is_function_binding : meta::neg> {}; - -} // sol - -// end of sol/call.hpp - -namespace sol { - namespace function_detail { - template - inline int call_wrapper_variable(std::false_type, lua_State* L) { - typedef meta::bind_traits> traits_type; - typedef typename traits_type::args_list args_list; - typedef meta::tuple_types return_type; - return stack::call_into_lua(return_type(), args_list(), L, 1, fx); - } - - template - inline int call_set_assignable(std::false_type, T&&, lua_State* L) { - return luaL_error(L, "cannot write to this type: copy assignment/constructor not available"); - } - - template - inline int call_set_assignable(std::true_type, lua_State* L, T&& mem) { - (mem.*variable) = stack::get(L, 2); - return 0; - } - - template - inline int call_set_variable(std::false_type, lua_State* L, T&&) { - return luaL_error(L, "cannot write to a const variable"); - } - - template - inline int call_set_variable(std::true_type, lua_State* L, T&& mem) { - return call_set_assignable(std::is_assignable, R>(), L, std::forward(mem)); - } - - template - inline int call_wrapper_variable(std::true_type, lua_State* L) { - typedef meta::bind_traits> traits_type; - typedef typename traits_type::object_type T; - typedef typename traits_type::return_type R; - auto& mem = stack::get(L, 1); - switch (lua_gettop(L)) { - case 1: { - decltype(auto) r = (mem.*variable); - stack::push_reference(L, std::forward(r)); - return 1; } - case 2: - return call_set_variable(meta::neg>(), L, mem); - default: - return luaL_error(L, "incorrect number of arguments to member variable function call"); - } - } - - template - inline int call_wrapper_function(std::false_type, lua_State* L) { - return call_wrapper_variable(std::is_member_object_pointer(), L); - } - - template - inline int call_wrapper_function(std::true_type, lua_State* L) { - return call_detail::call_wrapped(L, fx); - } - - template - int call_wrapper_entry(lua_State* L) { - return call_wrapper_function(std::is_member_function_pointer>(), L); - } - - template - struct c_call_matcher { - template - int operator()(types, index_value, types, types, lua_State* L, int, int) const { - typedef meta::at_in_pack_t target; - return target::call(L); - } - }; - - } // function_detail - - template - inline int c_call(lua_State* L) { -#ifdef __clang__ - return detail::trampoline(L, function_detail::call_wrapper_entry); -#else - return detail::static_trampoline<(&function_detail::call_wrapper_entry)>(L); -#endif // fuck you clang :c - } - - template - struct wrap { - typedef F type; - - static int call(lua_State* L) { - return c_call(L); - } - }; - - template - inline int c_call(lua_State* L) { - if (sizeof...(Fxs) < 2) { - return meta::at_in_pack_t<0, Fxs...>::call(L); - } - else { - return call_detail::overload_match_arity(function_detail::c_call_matcher(), L, lua_gettop(L), 1); - } - } - -} // sol - -// end of sol/function_types_templated.hpp - -// beginning of sol/function_types_stateless.hpp - -namespace sol { - namespace function_detail { - template - struct upvalue_free_function { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - auto udata = stack::stack_detail::get_as_upvalues(L); - function_type* fx = udata.first; - return call_detail::call_wrapped(L, fx); - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_member_function { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member function pointer - // idx n + 1: is the object's void pointer - // We don't need to store the size, because the other side is templated - // with the same member function pointer type - auto memberdata = stack::stack_detail::get_as_upvalues(L); - auto objdata = stack::stack_detail::get_as_upvalues(L, memberdata.second); - function_type& memfx = memberdata.first; - auto& item = *objdata.first; - return call_detail::call_wrapped(L, memfx, item); - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_member_variable { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member variable pointer - // idx n + 1: is the object's void pointer - // We don't need to store the size, because the other side is templated - // with the same member function pointer type - auto memberdata = stack::stack_detail::get_as_upvalues(L); - auto objdata = stack::stack_detail::get_as_upvalues(L, memberdata.second); - auto& mem = *objdata.first; - function_type& var = memberdata.first; - switch (lua_gettop(L)) { - case 0: - return call_detail::call_wrapped(L, var, mem); - case 1: - return call_detail::call_wrapped(L, var, mem); - default: - return luaL_error(L, "sol: incorrect number of arguments to member variable function"); - } - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_member_variable> { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member variable pointer - // idx n + 1: is the object's void pointer - // We don't need to store the size, because the other side is templated - // with the same member function pointer type - auto memberdata = stack::stack_detail::get_as_upvalues(L); - auto objdata = stack::stack_detail::get_as_upvalues(L, memberdata.second); - auto& mem = *objdata.first; - function_type& var = memberdata.first; - switch (lua_gettop(L)) { - case 0: - return call_detail::call_wrapped(L, var, mem); - default: - return luaL_error(L, "sol: incorrect number of arguments to member variable function"); - } - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_this_member_function { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member variable pointer - auto memberdata = stack::stack_detail::get_as_upvalues(L); - function_type& memfx = memberdata.first; - return call_detail::call_wrapped(L, memfx); - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_this_member_variable { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member variable pointer - auto memberdata = stack::stack_detail::get_as_upvalues(L); - function_type& var = memberdata.first; - switch (lua_gettop(L)) { - case 1: - return call_detail::call_wrapped(L, var); - case 2: - return call_detail::call_wrapped(L, var); - default: - return luaL_error(L, "sol: incorrect number of arguments to member variable function"); - } - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - - template - struct upvalue_this_member_variable> { - typedef std::remove_pointer_t> function_type; - typedef lua_bind_traits traits_type; - - static int real_call(lua_State* L) { - // Layout: - // idx 1...n: verbatim data of member variable pointer - auto memberdata = stack::stack_detail::get_as_upvalues(L); - function_type& var = memberdata.first; - switch (lua_gettop(L)) { - case 1: - return call_detail::call_wrapped(L, var); - default: - return luaL_error(L, "sol: incorrect number of arguments to member variable function"); - } - } - - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - int operator()(lua_State* L) { - return call(L); - } - }; - } // function_detail -} // sol - -// end of sol/function_types_stateless.hpp - -// beginning of sol/function_types_stateful.hpp - -namespace sol { - namespace function_detail { - template - struct functor_function { - typedef meta::unwrapped_t> Function; - Function fx; - - template - functor_function(Function f, Args&&... args) : fx(std::move(f), std::forward(args)...) {} - - int call(lua_State* L) { - return call_detail::call_wrapped(L, fx); - } - - int operator()(lua_State* L) { - auto f = [&](lua_State*) -> int { return this->call(L); }; - return detail::trampoline(L, f); - } - }; - - template - struct member_function { - typedef std::remove_pointer_t> function_type; - typedef meta::function_return_t return_type; - typedef meta::function_args_t args_lists; - function_type invocation; - T member; - - template - member_function(function_type f, Args&&... args) : invocation(std::move(f)), member(std::forward(args)...) {} - - int call(lua_State* L) { - return call_detail::call_wrapped(L, invocation, detail::unwrap(detail::deref(member))); - } - - int operator()(lua_State* L) { - auto f = [&](lua_State*) -> int { return this->call(L); }; - return detail::trampoline(L, f); - } - }; - - template - struct member_variable { - typedef std::remove_pointer_t> function_type; - typedef typename meta::bind_traits::return_type return_type; - typedef typename meta::bind_traits::args_list args_lists; - function_type var; - T member; - typedef std::add_lvalue_reference_t>> M; - - template - member_variable(function_type v, Args&&... args) : var(std::move(v)), member(std::forward(args)...) {} - - int call(lua_State* L) { - M mem = detail::unwrap(detail::deref(member)); - switch (lua_gettop(L)) { - case 0: - return call_detail::call_wrapped(L, var, mem); - case 1: - return call_detail::call_wrapped(L, var, mem); - default: - return luaL_error(L, "sol: incorrect number of arguments to member variable function"); - } - } - - int operator()(lua_State* L) { - auto f = [&](lua_State*) -> int { return this->call(L); }; - return detail::trampoline(L, f); - } - }; - } // function_detail -} // sol - -// end of sol/function_types_stateful.hpp - -// beginning of sol/function_types_overloaded.hpp - -namespace sol { - namespace function_detail { - template - struct overloaded_function { - typedef std::tuple overload_list; - typedef std::make_index_sequence indices; - overload_list overloads; - - overloaded_function(overload_list set) - : overloads(std::move(set)) {} - - overloaded_function(Functions... fxs) - : overloads(fxs...) { - - } - - template - int call(types, index_value, types, types, lua_State* L, int, int) { - auto& func = std::get(overloads); - return call_detail::call_wrapped(L, func); - } - - int operator()(lua_State* L) { - auto mfx = [&](auto&&... args) { return this->call(std::forward(args)...); }; - return call_detail::overload_match(mfx, L, 1 + start_skew); - } - }; - } // function_detail -} // sol - -// end of sol/function_types_overloaded.hpp - -// beginning of sol/resolve.hpp - -namespace sol { - -#ifndef __clang__ - // constexpr is fine for not-clang - - namespace detail { - template(Args...)>> - inline constexpr auto resolve_i(types, F&&)->R(meta::unqualified_t::*)(Args...) { - using Sig = R(Args...); - typedef meta::unqualified_t Fu; - return static_cast(&Fu::operator()); - } - - template> - inline constexpr auto resolve_f(std::true_type, F&& f) - -> decltype(resolve_i(types>(), std::forward(f))) { - return resolve_i(types>(), std::forward(f)); - } - - template - inline constexpr void resolve_f(std::false_type, F&&) { - static_assert(meta::has_deducible_signature::value, - "Cannot use no-template-parameter call with an overloaded functor: specify the signature"); - } - - template> - inline constexpr auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature(), std::forward(f))) { - return resolve_f(meta::has_deducible_signature {}, std::forward(f)); - } - - template> - inline constexpr auto resolve_i(types, F&& f) -> decltype(resolve_i(types(), std::forward(f))) { - return resolve_i(types(), std::forward(f)); - } - - template - inline constexpr Sig C::* resolve_v(std::false_type, Sig C::* mem_func_ptr) { - return mem_func_ptr; - } - - template - inline constexpr Sig C::* resolve_v(std::true_type, Sig C::* mem_variable_ptr) { - return mem_variable_ptr; - } - } // detail - - template - inline constexpr auto resolve(R fun_ptr(Args...))->R(*)(Args...) { - return fun_ptr; - } - - template - inline constexpr Sig* resolve(Sig* fun_ptr) { - return fun_ptr; - } - - template - inline constexpr auto resolve(R(C::*mem_ptr)(Args...))->R(C::*)(Args...) { - return mem_ptr; - } - - template - inline constexpr Sig C::* resolve(Sig C::* mem_ptr) { - return detail::resolve_v(std::is_member_object_pointer(), mem_ptr); - } - - template>> = meta::enabler> - inline constexpr auto resolve(F&& f) -> decltype(detail::resolve_i(types(), std::forward(f))) { - return detail::resolve_i(types(), std::forward(f)); - } -#else - - // Clang has distinct problems with constexpr arguments, - // so don't use the constexpr versions inside of clang. - - namespace detail { - template(Args...)>> - inline auto resolve_i(types, F&&)->R(meta::unqualified_t::*)(Args...) { - using Sig = R(Args...); - typedef meta::unqualified_t Fu; - return static_cast(&Fu::operator()); - } - - template> - inline auto resolve_f(std::true_type, F&& f) - -> decltype(resolve_i(types>(), std::forward(f))) { - return resolve_i(types>(), std::forward(f)); - } - - template - inline void resolve_f(std::false_type, F&&) { - static_assert(meta::has_deducible_signature::value, - "Cannot use no-template-parameter call with an overloaded functor: specify the signature"); - } - - template> - inline auto resolve_i(types<>, F&& f) -> decltype(resolve_f(meta::has_deducible_signature(), std::forward(f))) { - return resolve_f(meta::has_deducible_signature {}, std::forward(f)); - } - - template> - inline auto resolve_i(types, F&& f) -> decltype(resolve_i(types(), std::forward(f))) { - return resolve_i(types(), std::forward(f)); - } - - template - inline Sig C::* resolve_v(std::false_type, Sig C::* mem_func_ptr) { - return mem_func_ptr; - } - - template - inline Sig C::* resolve_v(std::true_type, Sig C::* mem_variable_ptr) { - return mem_variable_ptr; - } - } // detail - - template - inline auto resolve(R fun_ptr(Args...))->R(*)(Args...) { - return fun_ptr; - } - - template - inline Sig* resolve(Sig* fun_ptr) { - return fun_ptr; - } - - template - inline auto resolve(R(C::*mem_ptr)(Args...))->R(C::*)(Args...) { - return mem_ptr; - } - - template - inline Sig C::* resolve(Sig C::* mem_ptr) { - return detail::resolve_v(std::is_member_object_pointer(), mem_ptr); - } - - template - inline auto resolve(F&& f) -> decltype(detail::resolve_i(types(), std::forward(f))) { - return detail::resolve_i(types(), std::forward(f)); - } - -#endif - -} // sol - -// end of sol/resolve.hpp - -namespace sol { - namespace function_detail { - template - struct class_indicator {}; - - struct call_indicator {}; - } - namespace stack { - template - struct pusher> { - template - static void select_convertible(std::false_type, types, lua_State* L, Fx&& fx, Args&&... args) { - typedef std::remove_pointer_t> clean_fx; - typedef function_detail::functor_function F; - set_fx(L, std::forward(fx), std::forward(args)...); - } - - template - static void select_convertible(std::true_type, types, lua_State* L, Fx&& fx, Args&&... args) { - using fx_ptr_t = R(*)(A...); - fx_ptr_t fxptr = detail::unwrap(std::forward(fx)); - select_function(std::true_type(), L, fxptr, std::forward(args)...); - } - - template - static void select_convertible(types t, lua_State* L, Fx&& fx, Args&&... args) { - typedef std::decay_t> raw_fx_t; - typedef R(*fx_ptr_t)(A...); - typedef std::is_convertible is_convertible; - select_convertible(is_convertible(), t, L, std::forward(fx), std::forward(args)...); - } - - template - static void select_convertible(types<>, lua_State* L, Fx&& fx, Args&&... args) { - typedef meta::function_signature_t> Sig; - select_convertible(types(), L, std::forward(fx), std::forward(args)...); - } - - template - static void select_reference_member_variable(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef std::remove_pointer_t> clean_fx; - typedef function_detail::member_variable, clean_fx> F; - set_fx(L, std::forward(fx), std::forward(obj), std::forward(args)...); - } - - template - static void select_reference_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef std::decay_t dFx; - dFx memfxptr(std::forward(fx)); - auto userptr = detail::ptr(std::forward(obj), std::forward(args)...); - lua_CFunction freefunc = &function_detail::upvalue_member_variable, meta::unqualified_t>::call; - - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, memfxptr); - upvalues += stack::push(L, lightuserdata_value(static_cast(userptr))); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_member_variable(std::false_type, lua_State* L, Fx&& fx, Args&&... args) { - select_convertible(types(), L, std::forward(fx), std::forward(args)...); - } - - template >> = meta::enabler> - static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef meta::boolean>::value || std::is_pointer::value> is_reference; - select_reference_member_variable(is_reference(), L, std::forward(fx), std::forward(obj), std::forward(args)...); - } - - template - static void select_member_variable(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator) { - lua_CFunction freefunc = &function_detail::upvalue_this_member_variable::call; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, fx); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_member_variable(std::true_type, lua_State* L, Fx&& fx) { - typedef typename meta::bind_traits>::object_type C; - lua_CFunction freefunc = &function_detail::upvalue_this_member_variable::call; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, fx); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_reference_member_function(std::false_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef std::decay_t clean_fx; - typedef function_detail::member_function, clean_fx> F; - set_fx(L, std::forward(fx), std::forward(obj), std::forward(args)...); - } - - template - static void select_reference_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef std::decay_t dFx; - dFx memfxptr(std::forward(fx)); - auto userptr = detail::ptr(std::forward(obj), std::forward(args)...); - lua_CFunction freefunc = &function_detail::upvalue_member_function, meta::unqualified_t>::call; - - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, memfxptr); - upvalues += stack::push(L, lightuserdata_value(static_cast(userptr))); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_member_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) { - select_member_variable(meta::is_member_object>(), L, std::forward(fx), std::forward(args)...); - } - - template >> = meta::enabler> - static void select_member_function(std::true_type, lua_State* L, Fx&& fx, T&& obj, Args&&... args) { - typedef meta::boolean>::value || std::is_pointer::value> is_reference; - select_reference_member_function(is_reference(), L, std::forward(fx), std::forward(obj), std::forward(args)...); - } - - template - static void select_member_function(std::true_type, lua_State* L, Fx&& fx, function_detail::class_indicator) { - lua_CFunction freefunc = &function_detail::upvalue_this_member_function::call; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, fx); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_member_function(std::true_type, lua_State* L, Fx&& fx) { - typedef typename meta::bind_traits>::object_type C; - lua_CFunction freefunc = &function_detail::upvalue_this_member_function::call; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, fx); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static void select_function(std::false_type, lua_State* L, Fx&& fx, Args&&... args) { - select_member_function(std::is_member_function_pointer>(), L, std::forward(fx), std::forward(args)...); - } - - template - static void select_function(std::true_type, lua_State* L, Fx&& fx, Args&&... args) { - std::decay_t target(std::forward(fx), std::forward(args)...); - lua_CFunction freefunc = &function_detail::upvalue_free_function::call; - - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::stack_detail::push_as_upvalues(L, target); - stack::push(L, c_closure(freefunc, upvalues)); - } - - static void select_function(std::true_type, lua_State* L, lua_CFunction f) { - stack::push(L, f); - } - - template >, std::is_base_of>>> = meta::enabler> - static void select(lua_State* L, Fx&& fx, Args&&... args) { - select_function(std::is_function>(), L, std::forward(fx), std::forward(args)...); - } - - template >, std::is_base_of>>> = meta::enabler> - static void select(lua_State* L, Fx&& fx) { - stack::push(L, std::forward(fx)); - } - - template - static void set_fx(lua_State* L, Args&&... args) { - lua_CFunction freefunc = function_detail::call, 2>; - - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push>(L, std::forward(args)...); - stack::push(L, c_closure(freefunc, upvalues)); - } - - template - static int push(lua_State* L, Args&&... args) { - // Set will always place one thing (function) on the stack - select(L, std::forward(args)...); - return 1; - } - }; - - template - struct pusher> { - template - static int push_func(std::index_sequence, lua_State* L, FP&& fp) { - return stack::push(L, detail::forward_get(fp.arguments)...); - } - - static int push(lua_State* L, const function_arguments& fp) { - return push_func(std::make_index_sequence(), L, fp); - } - - static int push(lua_State* L, function_arguments&& fp) { - return push_func(std::make_index_sequence(), L, std::move(fp)); - } - }; - - template - struct pusher> { - static int push(lua_State* L, const std::function& fx) { - return pusher>{}.push(L, fx); - } - - static int push(lua_State* L, std::function&& fx) { - return pusher>{}.push(L, std::move(fx)); - } - }; - - template - struct pusher::value>> { - template - static int push(lua_State* L, F&& f, Args&&... args) { - return pusher>{}.push(L, std::forward(f), std::forward(args)...); - } - }; - - template - struct pusher, meta::neg>, meta::neg>>>::value>> { - template - static int push(lua_State* L, F&& f) { - return pusher>{}.push(L, std::forward(f)); - } - }; - - template - struct pusher> { - static int push(lua_State* L, overload_set&& set) { - typedef function_detail::overloaded_function<0, Functions...> F; - pusher>{}.set_fx(L, std::move(set.functions)); - return 1; - } - - static int push(lua_State* L, const overload_set& set) { - typedef function_detail::overloaded_function<0, Functions...> F; - pusher>{}.set_fx(L, set.functions); - return 1; - } - }; - - template - struct pusher> { - static int push(lua_State* L, protect_t&& pw) { - lua_CFunction cf = call_detail::call_user, 2>; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push>>(L, std::move(pw.value)); - return stack::push(L, c_closure(cf, upvalues)); - } - - static int push(lua_State* L, const protect_t& pw) { - lua_CFunction cf = call_detail::call_user, 2>; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push>>(L, pw.value); - return stack::push(L, c_closure(cf, upvalues)); - } - }; - - template - struct pusher, std::enable_if_t::value && !std::is_void::value>> { - static int push(lua_State* L, property_wrapper&& pw) { - return stack::push(L, sol::overload(std::move(pw.read), std::move(pw.write))); - } - static int push(lua_State* L, const property_wrapper& pw) { - return stack::push(L, sol::overload(pw.read, pw.write)); - } - }; - - template - struct pusher> { - static int push(lua_State* L, property_wrapper&& pw) { - return stack::push(L, std::move(pw.read)); - } - static int push(lua_State* L, const property_wrapper& pw) { - return stack::push(L, pw.read); - } - }; - - template - struct pusher> { - static int push(lua_State* L, property_wrapper&& pw) { - return stack::push(L, std::move(pw.write)); - } - static int push(lua_State* L, const property_wrapper& pw) { - return stack::push(L, pw.write); - } - }; - - template - struct pusher> { - static int push(lua_State* L, var_wrapper&& vw) { - return stack::push(L, std::move(vw.value)); - } - static int push(lua_State* L, const var_wrapper& vw) { - return stack::push(L, vw.value); - } - }; - - template - struct pusher> { - static int push(lua_State* L, const factory_wrapper& fw) { - typedef function_detail::overloaded_function<0, Functions...> F; - pusher>{}.set_fx(L, fw.functions); - return 1; - } - - static int push(lua_State* L, factory_wrapper&& fw) { - typedef function_detail::overloaded_function<0, Functions...> F; - pusher>{}.set_fx(L, std::move(fw.functions)); - return 1; - } - - static int push(lua_State* L, const factory_wrapper& set, function_detail::call_indicator) { - typedef function_detail::overloaded_function<1, Functions...> F; - pusher>{}.set_fx(L, set.functions); - return 1; - } - - static int push(lua_State* L, factory_wrapper&& set, function_detail::call_indicator) { - typedef function_detail::overloaded_function<1, Functions...> F; - pusher>{}.set_fx(L, std::move(set.functions)); - return 1; - } - }; - - template <> - struct pusher { - static int push(lua_State* L, no_construction) { - lua_CFunction cf = &function_detail::no_construction_error; - return stack::push(L, cf); - } - - static int push(lua_State* L, no_construction c, function_detail::call_indicator) { - return push(L, c); - } - }; - - template - struct pusher>> { - static int push(lua_State* L, detail::tagged>) { - lua_CFunction cf = call_detail::construct; - return stack::push(L, cf); - } - }; - - template - struct pusher>> { - template - static int push(lua_State* L, C&& c) { - lua_CFunction cf = call_detail::call_user, 2>; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push>>(L, std::forward(c)); - return stack::push(L, c_closure(cf, upvalues)); - } - }; - - template - struct pusher>> { - static int push(lua_State* L, destructor_wrapper) { - lua_CFunction cf = detail::usertype_alloc_destroy; - return stack::push(L, cf); - } - }; - - template - struct pusher>> { - static int push(lua_State* L, destructor_wrapper c) { - lua_CFunction cf = call_detail::call_user, 2>; - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push>(L, std::move(c)); - return stack::push(L, c_closure(cf, upvalues)); - } - }; - - } // stack -} // sol - -// end of sol/function_types.hpp - -namespace sol { - template - class basic_function : public base_t { - private: - void luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount) const { - lua_callk(base_t::lua_state(), static_cast(argcount), static_cast(resultcount), 0, nullptr); - } - - template - auto invoke(types, std::index_sequence, std::ptrdiff_t n) const { - luacall(n, lua_size>::value); - return stack::pop>(base_t::lua_state()); - } - - template - Ret invoke(types, std::index_sequence, std::ptrdiff_t n) const { - luacall(n, lua_size::value); - return stack::pop(base_t::lua_state()); - } - - template - void invoke(types, std::index_sequence, std::ptrdiff_t n) const { - luacall(n, 0); - } - - function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n) const { - int stacksize = lua_gettop(base_t::lua_state()); - int firstreturn = (std::max)(1, stacksize - static_cast(n)); - luacall(n, LUA_MULTRET); - int poststacksize = lua_gettop(base_t::lua_state()); - int returncount = poststacksize - (firstreturn - 1); - return function_result(base_t::lua_state(), firstreturn, returncount); - } - - public: - basic_function() = default; - template , basic_function>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_function(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_function>::value) { - auto pp = stack::push_pop(*this); - stack::check(base_t::lua_state(), -1, type_panic); - } -#endif // Safety - } - basic_function(const basic_function&) = default; - basic_function& operator=(const basic_function&) = default; - basic_function(basic_function&&) = default; - basic_function& operator=(basic_function&&) = default; - basic_function(const stack_reference& r) : basic_function(r.lua_state(), r.stack_index()) {} - basic_function(stack_reference&& r) : basic_function(r.lua_state(), r.stack_index()) {} - template >>, meta::neg>> = meta::enabler> - basic_function(lua_State* L, T&& r) : basic_function(L, sol::ref_index(r.registry_index())) {} - basic_function(lua_State* L, int index = -1) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_function(lua_State* L, ref_index index) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, -1, type_panic); -#endif // Safety - } - - template - function_result operator()(Args&&... args) const { - return call<>(std::forward(args)...); - } - - template - decltype(auto) operator()(types, Args&&... args) const { - return call(std::forward(args)...); - } - - template - decltype(auto) call(Args&&... args) const { - base_t::push(); - int pushcount = stack::multi_push_reference(base_t::lua_state(), std::forward(args)...); - return invoke(types(), std::make_index_sequence(), pushcount); - } - }; - - namespace stack { - template - struct getter> { - typedef meta::bind_traits fx_t; - typedef typename fx_t::args_list args_lists; - typedef meta::tuple_types return_types; - - template - static std::function get_std_func(types, types, lua_State* L, int index) { - sol::function f(L, index); - auto fx = [f, L, index](Args&&... args) -> meta::return_type_t { - return f.call(std::forward(args)...); - }; - return std::move(fx); - } - - template - static std::function get_std_func(types, types, lua_State* L, int index) { - sol::function f(L, index); - auto fx = [f, L, index](FxArgs&&... args) -> void { - f(std::forward(args)...); - }; - return std::move(fx); - } - - template - static std::function get_std_func(types<>, types t, lua_State* L, int index) { - return get_std_func(types(), t, L, index); - } - - static std::function get(lua_State* L, int index, record& tracking) { - tracking.last = 1; - tracking.used += 1; - type t = type_of(L, index); - if (t == type::none || t == type::lua_nil) { - return nullptr; - } - return get_std_func(return_types(), args_lists(), L, index); - } - }; - } // stack -} // sol - -// end of sol/function.hpp - -// beginning of sol/protected_function.hpp - -// beginning of sol/protected_function_result.hpp - -namespace sol { - struct protected_function_result : public proxy_base { - private: - lua_State* L; - int index; - int returncount; - int popcount; - call_status err; - - template - decltype(auto) tagged_get(types>) const { - if (!valid()) { - return optional(nullopt); - } - return stack::get>(L, index); - } - - template - decltype(auto) tagged_get(types) const { -#ifdef SOL_CHECK_ARGUMENTS - if (!valid()) { - type_panic(L, index, type_of(L, index), type::none); - } -#endif // Check Argument Safety - return stack::get(L, index); - } - - optional tagged_get(types>) const { - if (valid()) { - return nullopt; - } - return error(detail::direct_error, stack::get(L, index)); - } - - error tagged_get(types) const { -#ifdef SOL_CHECK_ARGUMENTS - if (valid()) { - type_panic(L, index, type_of(L, index), type::none); - } -#endif // Check Argument Safety - return error(detail::direct_error, stack::get(L, index)); - } - - public: - protected_function_result() = default; - protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept : L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) { - - } - protected_function_result(const protected_function_result&) = default; - protected_function_result& operator=(const protected_function_result&) = default; - protected_function_result(protected_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but we will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - o.popcount = 0; - o.err = call_status::runtime; - } - protected_function_result& operator=(protected_function_result&& o) noexcept { - L = o.L; - index = o.index; - returncount = o.returncount; - popcount = o.popcount; - err = o.err; - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but we will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - o.popcount = 0; - o.err = call_status::runtime; - return *this; - } - - call_status status() const noexcept { - return err; - } - - bool valid() const noexcept { - return status() == call_status::ok || status() == call_status::yielded; - } - - template - decltype(auto) get() const { - return tagged_get(types>()); - } - - lua_State* lua_state() const noexcept { return L; }; - int stack_index() const noexcept { return index; }; - - ~protected_function_result() { - stack::remove(L, index, popcount); - } - }; -} // sol - -// end of sol/protected_function_result.hpp - -#include - -namespace sol { - namespace detail { - inline reference& handler_storage() { - static sol::reference h; - return h; - } - - struct handler { - const reference& target; - int stackindex; - handler(const reference& target) : target(target), stackindex(0) { - if (target.valid()) { - stackindex = lua_gettop(target.lua_state()) + 1; - target.push(); - } - } - bool valid() const { return stackindex != 0; } - ~handler() { - if (valid()) { - lua_remove(target.lua_state(), stackindex); - } - } - }; - } - - template - class basic_protected_function : public base_t { - public: - static reference& get_default_handler() { - return detail::handler_storage(); - } - - static void set_default_handler(const reference& ref) { - detail::handler_storage() = ref; - } - - static void set_default_handler(reference&& ref) { - detail::handler_storage() = std::move(ref); - } - - private: - call_status luacall(std::ptrdiff_t argcount, std::ptrdiff_t resultcount, detail::handler& h) const { - return static_cast(lua_pcallk(base_t::lua_state(), static_cast(argcount), static_cast(resultcount), h.stackindex, 0, nullptr)); - } - - template - auto invoke(types, std::index_sequence, std::ptrdiff_t n, detail::handler& h) const { - luacall(n, sizeof...(Ret), h); - return stack::pop>(base_t::lua_state()); - } - - template - Ret invoke(types, std::index_sequence, std::ptrdiff_t n, detail::handler& h) const { - luacall(n, 1, h); - return stack::pop(base_t::lua_state()); - } - - template - void invoke(types, std::index_sequence, std::ptrdiff_t n, detail::handler& h) const { - luacall(n, 0, h); - } - - protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n, detail::handler& h) const { - int stacksize = lua_gettop(base_t::lua_state()); - int poststacksize = stacksize; - int firstreturn = 1; - int returncount = 0; - call_status code = call_status::ok; -#ifndef SOL_NO_EXCEPTIONS - auto onexcept = [&](const char* error) { - h.stackindex = 0; - if (h.target.valid()) { - h.target.push(); - stack::push(base_t::lua_state(), error); - lua_call(base_t::lua_state(), 1, 1); - } - else { - stack::push(base_t::lua_state(), error); - } - }; - try { -#endif // No Exceptions - firstreturn = (std::max)(1, static_cast(stacksize - n - static_cast(h.valid()))); - code = luacall(n, LUA_MULTRET, h); - poststacksize = lua_gettop(base_t::lua_state()) - static_cast(h.valid()); - returncount = poststacksize - (firstreturn - 1); -#ifndef SOL_NO_EXCEPTIONS - } - // Handle C++ errors thrown from C++ functions bound inside of lua - catch (const char* error) { - onexcept(error); - firstreturn = lua_gettop(base_t::lua_state()); - return protected_function_result(base_t::lua_state(), firstreturn, 0, 1, call_status::runtime); - } - catch (const std::exception& error) { - onexcept(error.what()); - firstreturn = lua_gettop(base_t::lua_state()); - return protected_function_result(base_t::lua_state(), firstreturn, 0, 1, call_status::runtime); - } - catch (...) { - onexcept("caught (...) unknown error during protected_function call"); - firstreturn = lua_gettop(base_t::lua_state()); - return protected_function_result(base_t::lua_state(), firstreturn, 0, 1, call_status::runtime); - } -#endif // No Exceptions - return protected_function_result(base_t::lua_state(), firstreturn, returncount, returncount, code); - } - - public: - reference error_handler; - - basic_protected_function() = default; - template , basic_protected_function>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_protected_function(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_function>::value) { - auto pp = stack::push_pop(*this); - stack::check(base_t::lua_state(), -1, type_panic); - } -#endif // Safety - } - basic_protected_function(const basic_protected_function&) = default; - basic_protected_function& operator=(const basic_protected_function&) = default; - basic_protected_function(basic_protected_function&&) = default; - basic_protected_function& operator=(basic_protected_function&&) = default; - basic_protected_function(const basic_function& b, reference eh = get_default_handler()) : base_t(b), error_handler(std::move(eh)) {} - basic_protected_function(basic_function&& b, reference eh = get_default_handler()) : base_t(std::move(b)), error_handler(std::move(eh)) {} - basic_protected_function(const stack_reference& r, reference eh = get_default_handler()) : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {} - basic_protected_function(stack_reference&& r, reference eh = get_default_handler()) : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {} - template - basic_protected_function(proxy_base&& p, reference eh = get_default_handler()) : basic_protected_function(p.operator basic_function(), std::move(eh)) {} - template - basic_protected_function(const proxy_base& p, reference eh = get_default_handler()) : basic_protected_function(p.operator basic_function(), std::move(eh)) {} - template >>, meta::neg>> = meta::enabler> - basic_protected_function(lua_State* L, T&& r, reference eh) : basic_protected_function(L, sol::ref_index(r.registry_index()), std::move(eh)) {} - basic_protected_function(lua_State* L, int index = -1, reference eh = get_default_handler()) : base_t(L, index), error_handler(std::move(eh)) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_protected_function(lua_State* L, ref_index index, reference eh = get_default_handler()) : base_t(L, index), error_handler(std::move(eh)) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, -1, type_panic); -#endif // Safety - } - - template - protected_function_result operator()(Args&&... args) const { - return call<>(std::forward(args)...); - } - - template - decltype(auto) operator()(types, Args&&... args) const { - return call(std::forward(args)...); - } - - template - decltype(auto) call(Args&&... args) const { - detail::handler h(error_handler); - base_t::push(); - int pushcount = stack::multi_push_reference(base_t::lua_state(), std::forward(args)...); - return invoke(types(), std::make_index_sequence(), pushcount, h); - } - }; -} // sol - -// end of sol/protected_function.hpp - -namespace sol { - struct stack_proxy : public proxy_base { - private: - lua_State* L; - int index; - - public: - stack_proxy() : L(nullptr), index(0) {} - stack_proxy(lua_State* L, int index) : L(L), index(index) {} - - template - decltype(auto) get() const { - return stack::get(L, stack_index()); - } - - int push() const { - return push(L); - } - - int push(lua_State* Ls) const { - lua_pushvalue(Ls, index); - return 1; - } - - lua_State* lua_state() const { return L; } - int stack_index() const { return index; } - - template - decltype(auto) call(Args&&... args) { - return get().template call(std::forward(args)...); - } - - template - decltype(auto) operator()(Args&&... args) { - return call<>(std::forward(args)...); - } - }; - - namespace stack { - template <> - struct getter { - static stack_proxy get(lua_State* L, int index = -1) { - return stack_proxy(L, index); - } - }; - - template <> - struct pusher { - static int push(lua_State*, const stack_proxy& ref) { - return ref.push(); - } - }; - } // stack - - namespace detail { - template <> - struct is_speshul : std::true_type {}; - template <> - struct is_speshul : std::true_type {}; - - template - stack_proxy get(types, index_value<0>, index_value, const T& fr) { - return stack_proxy(fr.lua_state(), static_cast(fr.stack_index() + I)); - } - - template 0)>> = meta::enabler> - stack_proxy get(types, index_value, index_value, const T& fr) { - return get(types(), index_value(), index_value::value>(), fr); - } - } - - template <> - struct tie_size : std::integral_constant {}; - - template - stack_proxy get(const function_result& fr) { - return stack_proxy(fr.lua_state(), static_cast(fr.stack_index() + I)); - } - - template - stack_proxy get(types t, const function_result& fr) { - return detail::get(t, index_value(), index_value<0>(), fr); - } - - template <> - struct tie_size : std::integral_constant {}; - - template - stack_proxy get(const protected_function_result& fr) { - return stack_proxy(fr.lua_state(), static_cast(fr.stack_index() + I)); - } - - template - stack_proxy get(types t, const protected_function_result& fr) { - return detail::get(t, index_value(), index_value<0>(), fr); - } -} // sol - -// end of sol/stack_proxy.hpp - -#include - -namespace sol { - template - struct va_iterator : std::iterator, std::ptrdiff_t, std::conditional_t, std::conditional_t> { - typedef std::iterator, std::ptrdiff_t, std::conditional_t, std::conditional_t> base_t; - typedef typename base_t::reference reference; - typedef typename base_t::pointer pointer; - typedef typename base_t::value_type value_type; - typedef typename base_t::difference_type difference_type; - typedef typename base_t::iterator_category iterator_category; - lua_State* L; - int index; - int stacktop; - stack_proxy sp; - - va_iterator() : L(nullptr), index((std::numeric_limits::max)()), stacktop((std::numeric_limits::max)()) {} - va_iterator(lua_State* luastate, int idx, int topidx) : L(luastate), index(idx), stacktop(topidx), sp(luastate, idx) {} - - reference operator*() { - return stack_proxy(L, index); - } - - pointer operator->() { - sp = stack_proxy(L, index); - return &sp; - } - - va_iterator& operator++ () { - ++index; - return *this; - } - - va_iterator operator++ (int) { - auto r = *this; - this->operator ++(); - return r; - } - - va_iterator& operator-- () { - --index; - return *this; - } - - va_iterator operator-- (int) { - auto r = *this; - this->operator --(); - return r; - } - - va_iterator& operator+= (difference_type idx) { - index += static_cast(idx); - return *this; - } - - va_iterator& operator-= (difference_type idx) { - index -= static_cast(idx); - return *this; - } - - difference_type operator- (const va_iterator& r) const { - return index - r.index; - } - - va_iterator operator+ (difference_type idx) const { - va_iterator r = *this; - r += idx; - return r; - } - - reference operator[](difference_type idx) { - return stack_proxy(L, index + static_cast(idx)); - } - - bool operator==(const va_iterator& r) const { - if (stacktop == (std::numeric_limits::max)()) { - return r.index == r.stacktop; - } - else if (r.stacktop == (std::numeric_limits::max)()) { - return index == stacktop; - } - return index == r.index; - } - - bool operator != (const va_iterator& r) const { - return !(this->operator==(r)); - } - - bool operator < (const va_iterator& r) const { - return index < r.index; - } - - bool operator > (const va_iterator& r) const { - return index > r.index; - } - - bool operator <= (const va_iterator& r) const { - return index <= r.index; - } - - bool operator >= (const va_iterator& r) const { - return index >= r.index; - } - }; - - template - inline va_iterator operator+(typename va_iterator::difference_type n, const va_iterator& r) { - return r + n; - } - - struct variadic_args { - private: - lua_State* L; - int index; - int stacktop; - - public: - typedef stack_proxy reference_type; - typedef stack_proxy value_type; - typedef stack_proxy* pointer; - typedef std::ptrdiff_t difference_type; - typedef std::size_t size_type; - typedef va_iterator iterator; - typedef va_iterator const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - variadic_args() = default; - variadic_args(lua_State* luastate, int stackindex = -1) : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lua_gettop(luastate)) {} - variadic_args(const variadic_args&) = default; - variadic_args& operator=(const variadic_args&) = default; - variadic_args(variadic_args&& o) : L(o.L), index(o.index), stacktop(o.stacktop) { - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but will be thorough - o.L = nullptr; - o.index = 0; - o.stacktop = 0; - } - variadic_args& operator=(variadic_args&& o) { - L = o.L; - index = o.index; - stacktop = o.stacktop; - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but will be thorough - o.L = nullptr; - o.index = 0; - o.stacktop = 0; - return *this; - } - - iterator begin() { return iterator(L, index, stacktop + 1); } - iterator end() { return iterator(L, stacktop + 1, stacktop + 1); } - const_iterator begin() const { return const_iterator(L, index, stacktop + 1); } - const_iterator end() const { return const_iterator(L, stacktop + 1, stacktop + 1); } - const_iterator cbegin() const { return begin(); } - const_iterator cend() const { return end(); } - - reverse_iterator rbegin() { return std::reverse_iterator(begin()); } - reverse_iterator rend() { return std::reverse_iterator(end()); } - const_reverse_iterator rbegin() const { return std::reverse_iterator(begin()); } - const_reverse_iterator rend() const { return std::reverse_iterator(end()); } - const_reverse_iterator crbegin() const { return std::reverse_iterator(cbegin()); } - const_reverse_iterator crend() const { return std::reverse_iterator(cend()); } - - int push() const { - return push(L); - } - - int push(lua_State* target) const { - int pushcount = 0; - for (int i = index; i <= stacktop; ++i) { - lua_pushvalue(L, i); - pushcount += 1; - } - if (target != L) { - lua_xmove(L, target, pushcount); - } - return pushcount; - } - - template - decltype(auto) get(difference_type start = 0) const { - return stack::get(L, index + static_cast(start)); - } - - stack_proxy operator[](difference_type start) const { - return stack_proxy(L, index + static_cast(start)); - } - - lua_State* lua_state() const { return L; }; - int stack_index() const { return index; }; - int leftover_count() const { return stacktop - (index - 1); } - int top() const { return stacktop; } - }; - - namespace stack { - template <> - struct getter { - static variadic_args get(lua_State* L, int index, record& tracking) { - tracking.last = 0; - return variadic_args(L, index); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, const variadic_args& ref) { - return ref.push(L); - } - }; - } // stack -} // sol - -// end of sol/variadic_args.hpp - -namespace sol { - - template ::value, typename T> - R make_reference(lua_State* L, T&& value) { - int backpedal = stack::push(L, std::forward(value)); - R r = stack::get(L, -backpedal); - if (should_pop) { - lua_pop(L, backpedal); - } - return r; - } - - template ::value, typename... Args> - R make_reference(lua_State* L, Args&&... args) { - int backpedal = stack::push(L, std::forward(args)...); - R r = stack::get(L, -backpedal); - if (should_pop) { - lua_pop(L, backpedal); - } - return r; - } - - template - class basic_object : public basic_object_base { - private: - typedef basic_object_base base_t; - - template - basic_object(std::integral_constant, lua_State* L, int index = -1) noexcept : base_t(L, index) { - if (invert_and_pop) { - lua_pop(L, -index); - } - } - - public: - basic_object() noexcept = default; - template , basic_object>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_object(T&& r) : base_t(std::forward(r)) {} - basic_object(lua_nil_t r) : base_t(r) {} - basic_object(const basic_object&) = default; - basic_object(basic_object&&) = default; - basic_object(const stack_reference& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} - basic_object(stack_reference&& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} - template - basic_object(const proxy_base& r) noexcept : basic_object(r.operator basic_object()) {} - template - basic_object(proxy_base&& r) noexcept : basic_object(r.operator basic_object()) {} - basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {} - basic_object(lua_State* L, ref_index index) noexcept : base_t(L, index) {} - template - basic_object(lua_State* L, in_place_type_t, Args&&... args) noexcept : basic_object(std::integral_constant::value>(), L, -stack::push(L, std::forward(args)...)) {} - template - basic_object(lua_State* L, in_place_t, T&& arg, Args&&... args) noexcept : basic_object(L, in_place, std::forward(arg), std::forward(args)...) {} - basic_object& operator=(const basic_object&) = default; - basic_object& operator=(basic_object&&) = default; - basic_object& operator=(const base_type& b) { base_t::operator=(b); return *this; } - basic_object& operator=(base_type&& b) { base_t::operator=(std::move(b)); return *this; } - template - basic_object& operator=(const proxy_base& r) { this->operator=(r.operator basic_object()); return *this; } - template - basic_object& operator=(proxy_base&& r) { this->operator=(r.operator basic_object()); return *this; } - }; - - template - object make_object(lua_State* L, T&& value) { - return make_reference(L, std::forward(value)); - } - - template - object make_object(lua_State* L, Args&&... args) { - return make_reference(L, std::forward(args)...); - } -} // sol - -// end of sol/object.hpp - -namespace sol { - template - struct proxy : public proxy_base> { - private: - typedef meta::condition, Key, std::tuple>, Key&, meta::unqualified_t>>> key_type; - - template - decltype(auto) tuple_get(std::index_sequence) const { - return tbl.template traverse_get(std::get(key)...); - } - - template - void tuple_set(std::index_sequence, T&& value) { - tbl.traverse_set(std::get(key)..., std::forward(value)); - } - - public: - Table tbl; - key_type key; - - template - proxy(Table table, T&& k) : tbl(table), key(std::forward(k)) {} - - template - proxy& set(T&& item) { - tuple_set(std::make_index_sequence>::value>(), std::forward(item)); - return *this; - } - - template - proxy& set_function(Args&&... args) { - tbl.set_function(key, std::forward(args)...); - return *this; - } - - template>>, meta::is_callable>> = meta::enabler> - proxy& operator=(U&& other) { - return set_function(std::forward(other)); - } - - template>>, meta::is_callable>> = meta::enabler> - proxy& operator=(U&& other) { - return set(std::forward(other)); - } - - template - decltype(auto) get() const { - return tuple_get(std::make_index_sequence>::value>()); - } - - template - decltype(auto) get_or(T&& otherwise) const { - typedef decltype(get()) U; - optional option = get>(); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) get_or(D&& otherwise) const { - optional option = get>(); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) operator[](K&& k) const { - auto keys = meta::tuplefy(key, std::forward(k)); - return proxy(tbl, std::move(keys)); - } - - template - decltype(auto) call(Args&&... args) { - return get().template call(std::forward(args)...); - } - - template - decltype(auto) operator()(Args&&... args) { - return call<>(std::forward(args)...); - } - - bool valid() const { - auto pp = stack::push_pop(tbl); - auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state())); - lua_pop(tbl.lua_state(), p.levels); - return p; - } - }; - - template - inline bool operator==(T&& left, const proxy& right) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator==(const proxy& right, T&& left) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator!=(T&& left, const proxy& right) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator!=(const proxy& right, T&& left) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator==(lua_nil_t, const proxy& right) { - return !right.valid(); - } - - template - inline bool operator==(const proxy& right, lua_nil_t) { - return !right.valid(); - } - - template - inline bool operator!=(lua_nil_t, const proxy& right) { - return right.valid(); - } - - template - inline bool operator!=(const proxy& right, lua_nil_t) { - return right.valid(); - } - - namespace stack { - template - struct pusher> { - static int push(lua_State* L, const proxy& p) { - sol::reference r = p; - return r.push(L); - } - }; - } // stack -} // sol - -// end of sol/proxy.hpp - -// beginning of sol/usertype.hpp - -// beginning of sol/usertype_metatable.hpp - -// beginning of sol/deprecate.hpp - -#ifndef SOL_DEPRECATED - #ifdef _MSC_VER - #define SOL_DEPRECATED __declspec(deprecated) - #elif __GNUC__ - #define SOL_DEPRECATED __attribute__((deprecated)) - #else - #define SOL_DEPRECATED [[deprecated]] - #endif // compilers -#endif // SOL_DEPRECATED - -namespace sol { - namespace detail { - template - struct SOL_DEPRECATED deprecate_type { - using type = T; - }; - } // detail -} // sol - -// end of sol/deprecate.hpp - -#include -#include - -namespace sol { - namespace usertype_detail { - const int metatable_index = 2; - const int metatable_core_index = 3; - const int filler_index = 4; - const int magic_index = 5; - - const int simple_metatable_index = 2; - const int index_function_index = 3; - const int newindex_function_index = 4; - - typedef void(*base_walk)(lua_State*, bool&, int&, string_detail::string_shim&); - typedef int(*member_search)(lua_State*, void*, int); - - struct call_information { - member_search index; - member_search new_index; - int runtime_target; - - call_information(member_search index, member_search newindex) : call_information(index, newindex, -1) {} - call_information(member_search index, member_search newindex, int runtimetarget) : index(index), new_index(newindex), runtime_target(runtimetarget) {} - }; - - typedef std::unordered_map mapping_t; - - struct variable_wrapper { - virtual int index(lua_State* L) = 0; - virtual int new_index(lua_State* L) = 0; - virtual ~variable_wrapper() {}; - }; - - template - struct callable_binding : variable_wrapper { - F fx; - - template - callable_binding(Arg&& arg) : fx(std::forward(arg)) {} - - virtual int index(lua_State* L) override { - return call_detail::call_wrapped(L, fx); - } - - virtual int new_index(lua_State* L) override { - return call_detail::call_wrapped(L, fx); - } - }; - - typedef std::unordered_map> variable_map; - typedef std::unordered_map function_map; - - struct simple_map { - const char* metakey; - variable_map variables; - function_map functions; - object index; - object newindex; - base_walk indexbaseclasspropogation; - base_walk newindexbaseclasspropogation; - - simple_map(const char* mkey, base_walk index, base_walk newindex, object i, object ni, variable_map&& vars, function_map&& funcs) - : metakey(mkey), variables(std::move(vars)), functions(std::move(funcs)), - index(std::move(i)), newindex(std::move(ni)), - indexbaseclasspropogation(index), newindexbaseclasspropogation(newindex) {} - }; - } - - struct usertype_metatable_core { - usertype_detail::mapping_t mapping; - lua_CFunction indexfunc; - lua_CFunction newindexfunc; - std::vector runtime; - bool mustindex; - - usertype_metatable_core(lua_CFunction ifx, lua_CFunction nifx) : - mapping(), indexfunc(ifx), - newindexfunc(nifx), runtime(), mustindex(false) - { - - } - - usertype_metatable_core(const usertype_metatable_core&) = default; - usertype_metatable_core(usertype_metatable_core&&) = default; - usertype_metatable_core& operator=(const usertype_metatable_core&) = default; - usertype_metatable_core& operator=(usertype_metatable_core&&) = default; - - }; - - namespace usertype_detail { - const lua_Integer toplevel_magic = static_cast(0xCCC2CCC1); - - struct add_destructor_tag {}; - struct check_destructor_tag {}; - struct verified_tag {} const verified{}; - - template - struct is_non_factory_constructor : std::false_type {}; - - template - struct is_non_factory_constructor> : std::true_type {}; - - template - struct is_non_factory_constructor> : std::true_type {}; - - template <> - struct is_non_factory_constructor : std::true_type {}; - - template - struct is_constructor : is_non_factory_constructor {}; - - template - struct is_constructor> : std::true_type {}; - - template - using has_constructor = meta::any>...>; - - template - struct is_destructor : std::false_type {}; - - template - struct is_destructor> : std::true_type {}; - - template - using has_destructor = meta::any>...>; - - struct no_comp { - template - bool operator()(A&&, B&&) const { - return false; - } - }; - - inline int is_indexer(string_detail::string_shim s) { - if (s == to_string(meta_function::index)) { - return 1; - } - else if (s == to_string(meta_function::new_index)) { - return 2; - } - return 0; - } - - inline int is_indexer(meta_function mf) { - if (mf == meta_function::index) { - return 1; - } - else if (mf == meta_function::new_index) { - return 2; - } - return 0; - } - - inline int is_indexer(call_construction) { - return 0; - } - - inline int is_indexer(base_classes_tag) { - return 0; - } - - inline auto make_shim(string_detail::string_shim s) { - return s; - } - - inline auto make_shim(call_construction) { - return string_detail::string_shim(to_string(meta_function::call_function)); - } - - inline auto make_shim(meta_function mf) { - return string_detail::string_shim(to_string(mf)); - } - - inline auto make_shim(base_classes_tag) { - return string_detail::string_shim(detail::base_class_cast_key()); - } - - template - inline std::string make_string(Arg&& arg) { - string_detail::string_shim s = make_shim(arg); - return std::string(s.c_str(), s.size()); - } - - template - inline luaL_Reg make_reg(N&& n, lua_CFunction f) { - luaL_Reg l{ make_shim(std::forward(n)).c_str(), f }; - return l; - } - - struct registrar { - registrar() = default; - registrar(const registrar&) = default; - registrar(registrar&&) = default; - registrar& operator=(const registrar&) = default; - registrar& operator=(registrar&&) = default; - virtual int push_um(lua_State* L) = 0; - virtual ~registrar() {} - }; - - inline bool is_toplevel(lua_State* L, int index = magic_index) { - int isnum = 0; - lua_Integer magic = lua_tointegerx(L, upvalue_index(index), &isnum); - return isnum != 0 && magic == toplevel_magic; - } - - inline int runtime_object_call(lua_State* L, void*, int runtimetarget) { - usertype_metatable_core& umc = stack::get>(L, upvalue_index(metatable_core_index)); - std::vector& runtime = umc.runtime; - object& runtimeobj = runtime[runtimetarget]; - return stack::push(L, runtimeobj); - } - - template - inline int indexing_fail(lua_State* L) { - if (is_index) { -#if 0//def SOL_SAFE_USERTYPE - auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); - string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); - return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); -#else - if (is_toplevel(L)) { - if (lua_getmetatable(L, 1) == 1) { - int metatarget = lua_gettop(L); - stack::get_field(L, stack_reference(L, raw_index(2)), metatarget); - return 1; - } - } - // With runtime extensibility, we can't hard-error things. They have to return nil, like regular table types, unfortunately... - return stack::push(L, lua_nil); -#endif - } - else { - auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); - string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); - return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); - } - } - - int runtime_new_index(lua_State* L, void*, int runtimetarget); - - template - inline int metatable_newindex(lua_State* L) { - if (is_toplevel(L)) { - auto non_indexable = [&L]() { - if (is_simple) { - simple_map& sm = stack::get>(L, upvalue_index(simple_metatable_index)); - function_map& functions = sm.functions; - optional maybeaccessor = stack::get>(L, 2); - if (!maybeaccessor) { - return; - } - std::string& accessor = maybeaccessor.value(); - auto preexistingit = functions.find(accessor); - if (preexistingit == functions.cend()) { - functions.emplace_hint(preexistingit, std::move(accessor), sol::object(L, 3)); - } - else { - preexistingit->second = sol::object(L, 3); - } - return; - } - usertype_metatable_core& umc = stack::get>(L, upvalue_index(metatable_core_index)); - bool mustindex = umc.mustindex; - if (!mustindex) - return; - optional maybeaccessor = stack::get>(L, 2); - if (!maybeaccessor) { - return; - } - std::string& accessor = maybeaccessor.value(); - mapping_t& mapping = umc.mapping; - std::vector& runtime = umc.runtime; - int target = static_cast(runtime.size()); - auto preexistingit = mapping.find(accessor); - if (preexistingit == mapping.cend()) { - runtime.emplace_back(L, 3); - mapping.emplace_hint(mapping.cend(), accessor, call_information(&runtime_object_call, &runtime_new_index, target)); - } - else { - target = preexistingit->second.runtime_target; - runtime[target] = sol::object(L, 3); - preexistingit->second = call_information(&runtime_object_call, &runtime_new_index, target); - } - }; - non_indexable(); - for (std::size_t i = 0; i < 4; lua_settop(L, 3), ++i) { - const char* metakey = nullptr; - switch (i) { - case 0: - metakey = &usertype_traits::metatable()[0]; - luaL_getmetatable(L, metakey); - break; - case 1: - metakey = &usertype_traits>::metatable()[0]; - luaL_getmetatable(L, metakey); - break; - case 2: - metakey = &usertype_traits::metatable()[0]; - luaL_getmetatable(L, metakey); - break; - case 3: - default: - metakey = &usertype_traits::user_metatable()[0]; - { - luaL_getmetatable(L, metakey); - lua_getmetatable(L, -1); - } - break; - } - int tableindex = lua_gettop(L); - if (type_of(L, tableindex) == type::lua_nil) { - continue; - } - stack::set_field(L, stack_reference(L, raw_index(2)), stack_reference(L, raw_index(3)), tableindex); - } - lua_settop(L, 0); - return 0; - } - return indexing_fail(L); - } - - inline int runtime_new_index(lua_State* L, void*, int runtimetarget) { - usertype_metatable_core& umc = stack::get>(L, upvalue_index(metatable_core_index)); - std::vector& runtime = umc.runtime; - object& runtimeobj = runtime[runtimetarget]; - runtimeobj = object(L, 3); - return 0; - } - - template - static void walk_single_base(lua_State* L, bool& found, int& ret, string_detail::string_shim&) { - if (found) - return; - const char* metakey = &usertype_traits::metatable()[0]; - const char* gcmetakey = &usertype_traits::gc_table()[0]; - const char* basewalkkey = is_index ? detail::base_class_index_propogation_key() : detail::base_class_new_index_propogation_key(); - - luaL_getmetatable(L, metakey); - if (type_of(L, -1) == type::lua_nil) { - lua_pop(L, 1); - return; - } - - stack::get_field(L, basewalkkey); - if (type_of(L, -1) == type::lua_nil) { - lua_pop(L, 2); - return; - } - lua_CFunction basewalkfunc = stack::pop(L); - lua_pop(L, 1); - - stack::get_field(L, gcmetakey); - int value = basewalkfunc(L); - if (value > -1) { - found = true; - ret = value; - } - } - - template - static void walk_all_bases(lua_State* L, bool& found, int& ret, string_detail::string_shim& accessor) { - (void)L; - (void)found; - (void)ret; - (void)accessor; - (void)detail::swallow{ 0, (walk_single_base(L, found, ret, accessor), 0)... }; - } - - template - inline int operator_wrap(lua_State* L) { - auto maybel = stack::check_get(L, 1); - if (maybel) { - auto mayber = stack::check_get(L, 2); - if (mayber) { - auto& l = *maybel; - auto& r = *mayber; - if (std::is_same::value) { - return stack::push(L, detail::ptr(l) == detail::ptr(r)); - } - else { - Op op; - return stack::push(L, (detail::ptr(l) == detail::ptr(r)) || op(detail::deref(l), detail::deref(r))); - } - } - } - return stack::push(L, false); - } - - template = meta::enabler> - inline void make_reg_op(Regs& l, int& index, const char* name) { - l[index] = { name, &operator_wrap }; - ++index; - } - - template = meta::enabler> - inline void make_reg_op(Regs&, int&, const char*) { - // Do nothing if there's no support - } - } // usertype_detail - - template - struct clean_type { - typedef std::conditional_t>::value, T&, std::decay_t> type; - }; - - template - using clean_type_t = typename clean_type::type; - - template - struct usertype_metatable : usertype_detail::registrar {}; - - template - struct usertype_metatable, Tn...> : usertype_metatable_core, usertype_detail::registrar { - typedef std::make_index_sequence indices; - typedef std::index_sequence half_indices; - typedef std::array regs_t; - typedef std::tuple RawTuple; - typedef std::tuple ...> Tuple; - template - struct check_binding : is_variable_binding> {}; - Tuple functions; - lua_CFunction destructfunc; - lua_CFunction callconstructfunc; - lua_CFunction indexbase; - lua_CFunction newindexbase; - usertype_detail::base_walk indexbaseclasspropogation; - usertype_detail::base_walk newindexbaseclasspropogation; - void* baseclasscheck; - void* baseclasscast; - bool secondarymeta; - bool hasequals; - bool hasless; - bool haslessequals; - - template >> = meta::enabler> - lua_CFunction make_func() const { - return std::get(functions); - } - - template >> = meta::enabler> - lua_CFunction make_func() const { - const auto& name = std::get(functions); - return (usertype_detail::make_shim(name) == "__newindex") ? &call : &call; - } - - static bool contains_variable() { - typedef meta::any...> has_variables; - return has_variables::value; - } - - bool contains_index() const { - bool idx = false; - (void)detail::swallow{ 0, ((idx |= (usertype_detail::is_indexer(std::get(functions)) != 0)), 0) ... }; - return idx; - } - - int finish_regs(regs_t& l, int& index) { - if (!hasless) { - const char* name = to_string(meta_function::less_than).c_str(); - usertype_detail::make_reg_op, meta::supports_op_less>(l, index, name); - } - if (!haslessequals) { - const char* name = to_string(meta_function::less_than_or_equal_to).c_str(); - usertype_detail::make_reg_op, meta::supports_op_less_equal>(l, index, name); - } - if (!hasequals) { - const char* name = to_string(meta_function::equal_to).c_str(); - usertype_detail::make_reg_op::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(l, index, name); - } - if (destructfunc != nullptr) { - l[index] = { to_string(meta_function::garbage_collect).c_str(), destructfunc }; - ++index; - } - return index; - } - - template - void make_regs(regs_t&, int&, call_construction, F&&) { - callconstructfunc = call; - secondarymeta = true; - } - - template - void make_regs(regs_t&, int&, base_classes_tag, bases) { - static_assert(!meta::any_same::value, "base classes cannot list the original class as part of the bases"); - if (sizeof...(Bases) < 1) { - return; - } - mustindex = true; - (void)detail::swallow{ 0, ((detail::has_derived::value = true), 0)... }; - - static_assert(sizeof(void*) <= sizeof(detail::inheritance_check_function), "The size of this data pointer is too small to fit the inheritance checking function: file a bug report."); - static_assert(sizeof(void*) <= sizeof(detail::inheritance_cast_function), "The size of this data pointer is too small to fit the inheritance checking function: file a bug report."); - baseclasscheck = (void*)&detail::inheritance::type_check; - baseclasscast = (void*)&detail::inheritance::type_cast; - indexbaseclasspropogation = usertype_detail::walk_all_bases; - newindexbaseclasspropogation = usertype_detail::walk_all_bases; - } - - template , base_classes_tag, call_construction>::value>> - void make_regs(regs_t& l, int& index, N&& n, F&&) { - if (is_variable_binding>::value) { - return; - } - luaL_Reg reg = usertype_detail::make_reg(std::forward(n), make_func()); - // Returnable scope - // That would be a neat keyword for C++ - // returnable { ... }; - if (reg.name == to_string(meta_function::equal_to)) { - hasequals = true; - } - if (reg.name == to_string(meta_function::less_than)) { - hasless = true; - } - if (reg.name == to_string(meta_function::less_than_or_equal_to)) { - haslessequals = true; - } - if (reg.name == to_string(meta_function::garbage_collect)) { - destructfunc = reg.func; - return; - } - else if (reg.name == to_string(meta_function::index)) { - indexfunc = reg.func; - mustindex = true; - return; - } - else if (reg.name == to_string(meta_function::new_index)) { - newindexfunc = reg.func; - mustindex = true; - return; - } - l[index] = reg; - ++index; - } - - template > - usertype_metatable(Args&&... args) : usertype_metatable_core(&usertype_detail::indexing_fail, &usertype_detail::metatable_newindex), usertype_detail::registrar(), - functions(std::forward(args)...), - destructfunc(nullptr), callconstructfunc(nullptr), - indexbase(&core_indexing_call), newindexbase(&core_indexing_call), - indexbaseclasspropogation(usertype_detail::walk_all_bases), newindexbaseclasspropogation(usertype_detail::walk_all_bases), - baseclasscheck(nullptr), baseclasscast(nullptr), - secondarymeta(contains_variable()), - hasequals(false), hasless(false), haslessequals(false) { - std::initializer_list ilist{ { - std::pair( usertype_detail::make_string(std::get(functions)), - usertype_detail::call_information(&usertype_metatable::real_find_call, - &usertype_metatable::real_find_call) - ) - }... }; - this->mapping.insert(ilist); - for (const auto& n : meta_function_names()) { - this->mapping.erase(n); - } - this->mustindex = contains_variable() || contains_index(); - } - - usertype_metatable(const usertype_metatable&) = default; - usertype_metatable(usertype_metatable&&) = default; - usertype_metatable& operator=(const usertype_metatable&) = default; - usertype_metatable& operator=(usertype_metatable&&) = default; - - template - static int real_find_call(lua_State* L, void* um, int) { - auto& f = *static_cast(um); - if (is_variable_binding(f.functions))>::value) { - return real_call_with(L, f); - } - // set up upvalues - // for a chained call - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push(L, light(f)); - auto cfunc = &call; - return stack::push(L, c_closure(cfunc, upvalues)); - } - - template - static int real_meta_call(lua_State* L, void* um, int) { - auto& f = *static_cast(um); - return is_index ? f.indexfunc(L) : f.newindexfunc(L); - } - - template - static int core_indexing_call(lua_State* L) { - usertype_metatable& f = toplevel - ? stack::get>(L, upvalue_index(usertype_detail::metatable_index)) - : stack::pop>(L); - static const int keyidx = -2 + static_cast(is_index); - if (toplevel && stack::get(L, keyidx) != type::string) { - return is_index ? f.indexfunc(L) : f.newindexfunc(L); - } - std::string name = stack::get(L, keyidx); - auto memberit = f.mapping.find(name); - if (memberit != f.mapping.cend()) { - const usertype_detail::call_information& ci = memberit->second; - const usertype_detail::member_search& member = is_index ? ci.index: ci.new_index; - return (member)(L, static_cast(&f), ci.runtime_target); - } - string_detail::string_shim accessor = name; - int ret = 0; - bool found = false; - // Otherwise, we need to do propagating calls through the bases - if (is_index) - f.indexbaseclasspropogation(L, found, ret, accessor); - else - f.newindexbaseclasspropogation(L, found, ret, accessor); - if (found) { - return ret; - } - return toplevel ? (is_index ? f.indexfunc(L) : f.newindexfunc(L)) : -1; - } - - static int real_index_call(lua_State* L) { - return core_indexing_call(L); - } - - static int real_new_index_call(lua_State* L) { - return core_indexing_call(L); - } - - template - static int real_call(lua_State* L) { - usertype_metatable& f = stack::get>(L, upvalue_index(usertype_detail::metatable_index)); - return real_call_with(L, f); - } - - template - static int real_call_with(lua_State* L, usertype_metatable& um) { - typedef meta::unqualified_tuple_element_t K; - typedef meta::unqualified_tuple_element_t F; - static const int boost = - !usertype_detail::is_non_factory_constructor::value - && std::is_same::value ? - 1 : 0; - auto& f = std::get(um.functions); - return call_detail::call_wrapped(L, f); - } - - template - static int call(lua_State* L) { - return detail::static_trampoline<(&real_call)>(L); - } - - template - static int call_with(lua_State* L) { - return detail::static_trampoline<(&real_call_with)>(L); - } - - static int index_call(lua_State* L) { - return detail::static_trampoline<(&real_index_call)>(L); - } - - static int new_index_call(lua_State* L) { - return detail::static_trampoline<(&real_new_index_call)>(L); - } - - virtual int push_um(lua_State* L) override { - return stack::push(L, std::move(*this)); - } - - ~usertype_metatable() override { - - } - }; - - namespace stack { - - template - struct pusher, Args...>> { - typedef usertype_metatable, Args...> umt_t; - typedef typename umt_t::regs_t regs_t; - - static umt_t& make_cleanup(lua_State* L, umt_t&& umx) { - // ensure some sort of uniqueness - static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); - // std::to_string doesn't exist in android still, with NDK, so this bullshit - // is necessary - // thanks, Android :v - int appended = snprintf(nullptr, 0, "%d", uniqueness); - std::size_t insertionpoint = uniquegcmetakey.length() - 1; - uniquegcmetakey.append(appended, '\0'); - char* uniquetarget = &uniquegcmetakey[insertionpoint]; - snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); - ++uniqueness; - - const char* gcmetakey = &usertype_traits::gc_table()[0]; - // Make sure userdata's memory is properly in lua first, - // otherwise all the light userdata we make later will become invalid - stack::push>(L, metatable_key, uniquegcmetakey, std::move(umx)); - // Create the top level thing that will act as our deleter later on - stack_reference umt(L, -1); - stack::set_field(L, gcmetakey, umt); - umt.pop(); - - stack::get_field(L, gcmetakey); - return stack::pop>(L); - } - - static int push(lua_State* L, umt_t&& umx) { - - umt_t& um = make_cleanup(L, std::move(umx)); - usertype_metatable_core& umc = um; - regs_t value_table{ {} }; - int lastreg = 0; - (void)detail::swallow{ 0, (um.template make_regs<(I * 2)>(value_table, lastreg, std::get<(I * 2)>(um.functions), std::get<(I * 2 + 1)>(um.functions)), 0)... }; - um.finish_regs(value_table, lastreg); - value_table[lastreg] = { nullptr, nullptr }; - regs_t ref_table = value_table; - regs_t unique_table = value_table; - bool hasdestructor = !value_table.empty() && to_string(meta_function::garbage_collect) == value_table[lastreg - 1].name; - if (hasdestructor) { - ref_table[lastreg - 1] = { nullptr, nullptr }; - unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; - } - - // Now use um - const bool& mustindex = umc.mustindex; - for (std::size_t i = 0; i < 3; ++i) { - // Pointer types, AKA "references" from C++ - const char* metakey = nullptr; - luaL_Reg* metaregs = nullptr; - switch (i) { - case 0: - metakey = &usertype_traits::metatable()[0]; - metaregs = ref_table.data(); - break; - case 1: - metakey = &usertype_traits>::metatable()[0]; - metaregs = unique_table.data(); - break; - case 2: - default: - metakey = &usertype_traits::metatable()[0]; - metaregs = value_table.data(); - break; - } - luaL_newmetatable(L, metakey); - stack_reference t(L, -1); - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push(L, make_light(um)); - luaL_setfuncs(L, metaregs, upvalues); - - if (um.baseclasscheck != nullptr) { - stack::set_field(L, detail::base_class_check_key(), um.baseclasscheck, t.stack_index()); - } - if (um.baseclasscast != nullptr) { - stack::set_field(L, detail::base_class_cast_key(), um.baseclasscast, t.stack_index()); - } - - stack::set_field(L, detail::base_class_index_propogation_key(), make_closure(um.indexbase, nullptr, make_light(um), make_light(umc)), t.stack_index()); - stack::set_field(L, detail::base_class_new_index_propogation_key(), make_closure(um.newindexbase, nullptr, make_light(um), make_light(umc)), t.stack_index()); - - if (mustindex) { - // Basic index pushing: specialize - // index and newindex to give variables and stuff - stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc)), t.stack_index()); - stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc)), t.stack_index()); - } - else { - // If there's only functions, we can use the fast index version - stack::set_field(L, meta_function::index, t, t.stack_index()); - } - // metatable on the metatable - // for call constructor purposes and such - lua_createtable(L, 0, 3); - stack_reference metabehind(L, -1); - if (um.callconstructfunc != nullptr) { - stack::set_field(L, meta_function::call_function, make_closure(um.callconstructfunc, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); - } - if (um.secondarymeta) { - stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); - stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); - } - stack::set_field(L, metatable_key, metabehind, t.stack_index()); - metabehind.pop(); - // We want to just leave the table - // in the registry only, otherwise we return it - t.pop(); - } - - // Now for the shim-table that actually gets assigned to the name - luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); - stack_reference t(L, -1); - int upvalues = 0; - upvalues += stack::push(L, nullptr); - upvalues += stack::push(L, make_light(um)); - luaL_setfuncs(L, value_table.data(), upvalues); - { - lua_createtable(L, 0, 3); - stack_reference metabehind(L, -1); - if (um.callconstructfunc != nullptr) { - stack::set_field(L, meta_function::call_function, make_closure(um.callconstructfunc, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); - } - - stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index()); - stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index()); - - stack::set_field(L, metatable_key, metabehind, t.stack_index()); - metabehind.pop(); - } - - return 1; - } - }; - - } // stack - -} // sol - -// end of sol/usertype_metatable.hpp - -// beginning of sol/simple_usertype_metatable.hpp - -namespace sol { - - namespace usertype_detail { - inline int call_indexing_object(lua_State* L, object& f) { - int before = lua_gettop(L); - f.push(); - for (int i = 1; i <= before; ++i) { - lua_pushvalue(L, i); - } - lua_callk(L, before, LUA_MULTRET, 0, nullptr); - int after = lua_gettop(L); - return after - before; - } - - template - inline int simple_core_indexing_call(lua_State* L) { - simple_map& sm = toplevel - ? stack::get>(L, upvalue_index(simple_metatable_index)) - : stack::pop>(L); - variable_map& variables = sm.variables; - function_map& functions = sm.functions; - static const int keyidx = -2 + static_cast(is_index); - if (toplevel) { - if (stack::get(L, keyidx) != type::string) { - if (has_indexing) { - object& indexingfunc = is_index - ? sm.index - : sm.newindex; - return call_indexing_object(L, indexingfunc); - } - else { - return is_index - ? indexing_fail(L) - : metatable_newindex(L); - } - } - } - string_detail::string_shim accessor = stack::get(L, keyidx); - std::string accessorkey = accessor.c_str(); - auto vit = variables.find(accessorkey); - if (vit != variables.cend()) { - auto& varwrap = *(vit->second); - if (is_index) { - return varwrap.index(L); - } - return varwrap.new_index(L); - } - auto fit = functions.find(accessorkey); - if (fit != functions.cend()) { - sol::object& func = fit->second; - if (is_index) { - return stack::push(L, func); - } - else { - if (has_indexing && !is_toplevel(L)) { - object& indexingfunc = is_index - ? sm.index - : sm.newindex; - return call_indexing_object(L, indexingfunc); - } - else { - return is_index - ? indexing_fail(L) - : metatable_newindex(L); - } - } - } - /* Check table storage first for a method that works - luaL_getmetatable(L, sm.metakey); - if (type_of(L, -1) != type::lua_nil) { - stack::get_field(L, accessor.c_str(), lua_gettop(L)); - if (type_of(L, -1) != type::lua_nil) { - // Woo, we found it? - lua_remove(L, -2); - return 1; - } - lua_pop(L, 1); - } - lua_pop(L, 1); - */ - - int ret = 0; - bool found = false; - // Otherwise, we need to do propagating calls through the bases - if (is_index) { - sm.indexbaseclasspropogation(L, found, ret, accessor); - } - else { - sm.newindexbaseclasspropogation(L, found, ret, accessor); - } - if (found) { - return ret; - } - if (toplevel) { - if (has_indexing && !is_toplevel(L)) { - object& indexingfunc = is_index - ? sm.index - : sm.newindex; - return call_indexing_object(L, indexingfunc); - } - else { - return is_index - ? indexing_fail(L) - : metatable_newindex(L); - } - } - return -1; - } - - template - inline int simple_real_index_call(lua_State* L) { - return simple_core_indexing_call(L); - } - - template - inline int simple_real_new_index_call(lua_State* L) { - return simple_core_indexing_call(L); - } - - template - inline int simple_index_call(lua_State* L) { -#if defined(__clang__) - return detail::trampoline(L, &simple_real_index_call); -#else - return detail::static_trampoline<(&simple_real_index_call)>(L); -#endif - } - - template - inline int simple_new_index_call(lua_State* L) { -#if defined(__clang__) - return detail::trampoline(L, &simple_real_new_index_call); -#else - return detail::static_trampoline<(&simple_real_new_index_call)>(L); -#endif - } - } - - struct simple_tag {} const simple{}; - - template - struct simple_usertype_metatable : usertype_detail::registrar { - public: - usertype_detail::function_map registrations; - usertype_detail::variable_map varmap; - object callconstructfunc; - object indexfunc; - object newindexfunc; - lua_CFunction indexbase; - lua_CFunction newindexbase; - usertype_detail::base_walk indexbaseclasspropogation; - usertype_detail::base_walk newindexbaseclasspropogation; - void* baseclasscheck; - void* baseclasscast; - bool mustindex; - bool secondarymeta; - - template - void insert(N&& n, object&& o) { - std::string key = usertype_detail::make_string(std::forward(n)); - int is_indexer = static_cast(usertype_detail::is_indexer(n)); - if (is_indexer == 1) { - indexfunc = o; - mustindex = true; - } - else if (is_indexer == 2) { - newindexfunc = o; - mustindex = true; - } - auto hint = registrations.find(key); - if (hint == registrations.cend()) { - registrations.emplace_hint(hint, std::move(key), std::move(o)); - return; - } - hint->second = std::move(o); - } - - template - void insert_prepare(std::true_type, lua_State* L, N&&, F&& f, Args&&... args) { - object o = make_object(L, std::forward(f), function_detail::call_indicator(), std::forward(args)...); - callconstructfunc = std::move(o); - } - - template - void insert_prepare(std::false_type, lua_State* L, N&& n, F&& f, Args&&... args) { - object o = make_object(L, std::forward(f), std::forward(args)...); - insert(std::forward(n), std::move(o)); - } - - template - void add_member_function(std::true_type, lua_State* L, N&& n, F&& f) { - insert_prepare(std::is_same, call_construction>(), L, std::forward(n), std::forward(f), function_detail::class_indicator()); - } - - template - void add_member_function(std::false_type, lua_State* L, N&& n, F&& f) { - insert_prepare(std::is_same, call_construction>(), L, std::forward(n), std::forward(f)); - } - - template >> = meta::enabler> - void add_function(lua_State* L, N&& n, F&& f) { - object o = make_object(L, as_function_reference(std::forward(f))); - if (std::is_same, call_construction>::value) { - callconstructfunc = std::move(o); - return; - } - insert(std::forward(n), std::move(o)); - } - - template >> = meta::enabler> - void add_function(lua_State* L, N&& n, F&& f) { - add_member_function(std::is_member_pointer>(), L, std::forward(n), std::forward(f)); - } - - template >> = meta::enabler> - void add(lua_State* L, N&& n, F&& f) { - add_function(L, std::forward(n), std::forward(f)); - } - - template >> = meta::enabler> - void add(lua_State*, N&& n, F&& f) { - mustindex = true; - secondarymeta = true; - std::string key = usertype_detail::make_string(std::forward(n)); - auto o = std::make_unique>>(std::forward(f)); - auto hint = varmap.find(key); - if (hint == varmap.cend()) { - varmap.emplace_hint(hint, std::move(key), std::move(o)); - return; - } - hint->second = std::move(o); - } - - template - void add(lua_State* L, N&& n, constructor_wrapper c) { - object o(L, in_place>>, std::move(c)); - if (std::is_same, call_construction>::value) { - callconstructfunc = std::move(o); - return; - } - insert(std::forward(n), std::move(o)); - } - - template - void add(lua_State* L, N&& n, constructor_list c) { - object o(L, in_place>>, std::move(c)); - if (std::is_same, call_construction>::value) { - callconstructfunc = std::move(o); - return; - } - insert(std::forward(n), std::move(o)); - } - - template - void add(lua_State* L, N&& n, destructor_wrapper c) { - object o(L, in_place>>, std::move(c)); - if (std::is_same, call_construction>::value) { - callconstructfunc = std::move(o); - return; - } - insert(std::forward(n), std::move(o)); - } - - template - void add(lua_State* L, N&& n, destructor_wrapper c) { - object o(L, in_place>>, std::move(c)); - if (std::is_same, call_construction>::value) { - callconstructfunc = std::move(o); - return; - } - insert(std::forward(n), std::move(o)); - } - - template - void add(lua_State*, base_classes_tag, bases) { - static_assert(sizeof(usertype_detail::base_walk) <= sizeof(void*), "size of function pointer is greater than sizeof(void*); cannot work on this platform. Please file a bug report."); - static_assert(!meta::any_same::value, "base classes cannot list the original class as part of the bases"); - if (sizeof...(Bases) < 1) { - return; - } - mustindex = true; - (void)detail::swallow{ 0, ((detail::has_derived::value = true), 0)... }; - - static_assert(sizeof(void*) <= sizeof(detail::inheritance_check_function), "The size of this data pointer is too small to fit the inheritance checking function: Please file a bug report."); - static_assert(sizeof(void*) <= sizeof(detail::inheritance_cast_function), "The size of this data pointer is too small to fit the inheritance checking function: Please file a bug report."); - baseclasscheck = (void*)&detail::inheritance::type_check; - baseclasscast = (void*)&detail::inheritance::type_cast; - indexbaseclasspropogation = usertype_detail::walk_all_bases; - newindexbaseclasspropogation = usertype_detail::walk_all_bases; - } - - private: - template - simple_usertype_metatable(usertype_detail::verified_tag, std::index_sequence, lua_State* L, Tuple&& args) - : callconstructfunc(lua_nil), - indexfunc(lua_nil), newindexfunc(lua_nil), - indexbase(&usertype_detail::simple_core_indexing_call), newindexbase(&usertype_detail::simple_core_indexing_call), - indexbaseclasspropogation(usertype_detail::walk_all_bases), newindexbaseclasspropogation(&usertype_detail::walk_all_bases), - baseclasscheck(nullptr), baseclasscast(nullptr), - mustindex(false), secondarymeta(false) { - (void)detail::swallow{ 0, - (add(L, detail::forward_get(args), detail::forward_get(args)),0)... - }; - } - - template - simple_usertype_metatable(lua_State* L, usertype_detail::verified_tag v, Args&&... args) : simple_usertype_metatable(v, std::make_index_sequence(), L, std::forward_as_tuple(std::forward(args)...)) {} - - template - simple_usertype_metatable(lua_State* L, usertype_detail::add_destructor_tag, Args&&... args) : simple_usertype_metatable(L, usertype_detail::verified, std::forward(args)..., "__gc", default_destructor) {} - - template - simple_usertype_metatable(lua_State* L, usertype_detail::check_destructor_tag, Args&&... args) : simple_usertype_metatable(L, meta::condition, meta::neg>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward(args)...) {} - - public: - simple_usertype_metatable(lua_State* L) : simple_usertype_metatable(L, meta::condition>, decltype(default_constructor), usertype_detail::check_destructor_tag>()) {} - - template, - usertype_detail::verified_tag, - usertype_detail::add_destructor_tag, - usertype_detail::check_destructor_tag - >, - meta::is_specialization_of>, - meta::is_specialization_of> - > = meta::enabler> - simple_usertype_metatable(lua_State* L, Arg&& arg, Args&&... args) : simple_usertype_metatable(L, meta::condition, meta::neg>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward(arg), std::forward(args)...) {} - - template - simple_usertype_metatable(lua_State* L, constructors constructorlist, Args&&... args) : simple_usertype_metatable(L, usertype_detail::check_destructor_tag(), std::forward(args)..., "new", constructorlist) {} - - template - simple_usertype_metatable(lua_State* L, constructor_wrapper constructorlist, Args&&... args) : simple_usertype_metatable(L, usertype_detail::check_destructor_tag(), std::forward(args)..., "new", constructorlist) {} - - simple_usertype_metatable(const simple_usertype_metatable&) = default; - simple_usertype_metatable(simple_usertype_metatable&&) = default; - simple_usertype_metatable& operator=(const simple_usertype_metatable&) = default; - simple_usertype_metatable& operator=(simple_usertype_metatable&&) = default; - - virtual int push_um(lua_State* L) override { - return stack::push(L, std::move(*this)); - } - }; - - namespace stack { - template - struct pusher> { - typedef simple_usertype_metatable umt_t; - - static usertype_detail::simple_map& make_cleanup(lua_State* L, umt_t& umx) { - static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); - // std::to_string doesn't exist in android still, with NDK, so this bullshit - // is necessary - // thanks, Android :v - int appended = snprintf(nullptr, 0, "%d", uniqueness); - std::size_t insertionpoint = uniquegcmetakey.length() - 1; - uniquegcmetakey.append(appended, '\0'); - char* uniquetarget = &uniquegcmetakey[insertionpoint]; - snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); - ++uniqueness; - - const char* gcmetakey = &usertype_traits::gc_table()[0]; - stack::push>(L, metatable_key, uniquegcmetakey, &usertype_traits::metatable()[0], - umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, - std::move(umx.indexfunc), std::move(umx.newindexfunc), - std::move(umx.varmap), std::move(umx.registrations) - ); - stack_reference stackvarmap(L, -1); - stack::set_field(L, gcmetakey, stackvarmap); - stackvarmap.pop(); - - stack::get_field(L, gcmetakey); - usertype_detail::simple_map& varmap = stack::pop>(L); - return varmap; - } - - static int push(lua_State* L, umt_t&& umx) { - bool hasindex = umx.indexfunc.valid(); - bool hasnewindex = umx.newindexfunc.valid(); - auto& varmap = make_cleanup(L, umx); - auto sic = hasindex ? &usertype_detail::simple_index_call : &usertype_detail::simple_index_call; - auto snic = hasnewindex ? &usertype_detail::simple_new_index_call : &usertype_detail::simple_new_index_call; - bool hasequals = false; - bool hasless = false; - bool haslessequals = false; - auto register_kvp = [&](std::size_t i, stack_reference& t, const std::string& first, object& second) { - if (first == to_string(meta_function::equal_to)) { - hasequals = true; - } - else if (first == to_string(meta_function::less_than)) { - hasless = true; - } - else if (first == to_string(meta_function::less_than_or_equal_to)) { - haslessequals = true; - } - else if (first == to_string(meta_function::index)) { - umx.indexfunc = second; - } - else if (first == to_string(meta_function::new_index)) { - umx.newindexfunc = second; - } - switch (i) { - case 0: - if (first == to_string(meta_function::garbage_collect)) { - return; - } - break; - case 1: - if (first == to_string(meta_function::garbage_collect)) { - stack::set_field(L, first, detail::unique_destruct, t.stack_index()); - return; - } - break; - case 2: - default: - break; - } - stack::set_field(L, first, second, t.stack_index()); - }; - for (std::size_t i = 0; i < 3; ++i) { - const char* metakey = nullptr; - switch (i) { - case 0: - metakey = &usertype_traits::metatable()[0]; - break; - case 1: - metakey = &usertype_traits>::metatable()[0]; - break; - case 2: - default: - metakey = &usertype_traits::metatable()[0]; - break; - } - luaL_newmetatable(L, metakey); - stack_reference t(L, -1); - for (auto& kvp : varmap.functions) { - auto& first = std::get<0>(kvp); - auto& second = std::get<1>(kvp); - register_kvp(i, t, first, second); - } - luaL_Reg opregs[4]{}; - int opregsindex = 0; - if (!hasless) { - const char* name = to_string(meta_function::less_than).c_str(); - usertype_detail::make_reg_op, meta::supports_op_less>(opregs, opregsindex, name); - } - if (!haslessequals) { - const char* name = to_string(meta_function::less_than_or_equal_to).c_str(); - usertype_detail::make_reg_op, meta::supports_op_less_equal>(opregs, opregsindex, name); - } - if (!hasequals) { - const char* name = to_string(meta_function::equal_to).c_str(); - usertype_detail::make_reg_op::value, std::equal_to<>, usertype_detail::no_comp>, std::true_type>(opregs, opregsindex, name); - } - t.push(); - luaL_setfuncs(L, opregs, 0); - t.pop(); - - if (umx.baseclasscheck != nullptr) { - stack::set_field(L, detail::base_class_check_key(), umx.baseclasscheck, t.stack_index()); - } - if (umx.baseclasscast != nullptr) { - stack::set_field(L, detail::base_class_cast_key(), umx.baseclasscast, t.stack_index()); - } - - // Base class propagation features - stack::set_field(L, detail::base_class_index_propogation_key(), umx.indexbase, t.stack_index()); - stack::set_field(L, detail::base_class_new_index_propogation_key(), umx.newindexbase, t.stack_index()); - - if (umx.mustindex) { - // use indexing function - stack::set_field(L, meta_function::index, - make_closure(sic, - nullptr, - make_light(varmap) - ), t.stack_index()); - stack::set_field(L, meta_function::new_index, - make_closure(snic, - nullptr, - make_light(varmap) - ), t.stack_index()); - } - else { - // Metatable indexes itself - stack::set_field(L, meta_function::index, t, t.stack_index()); - } - // metatable on the metatable - // for call constructor purposes and such - lua_createtable(L, 0, 2 * static_cast(umx.secondarymeta) + static_cast(umx.callconstructfunc.valid())); - stack_reference metabehind(L, -1); - if (umx.callconstructfunc.valid()) { - stack::set_field(L, sol::meta_function::call_function, umx.callconstructfunc, metabehind.stack_index()); - } - if (umx.secondarymeta) { - stack::set_field(L, meta_function::index, - make_closure(sic, - nullptr, - make_light(varmap) - ), metabehind.stack_index()); - stack::set_field(L, meta_function::new_index, - make_closure(snic, - nullptr, - make_light(varmap) - ), metabehind.stack_index()); - } - stack::set_field(L, metatable_key, metabehind, t.stack_index()); - metabehind.pop(); - - t.pop(); - } - - // Now for the shim-table that actually gets pushed - luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); - stack_reference t(L, -1); - for (auto& kvp : varmap.functions) { - auto& first = std::get<0>(kvp); - auto& second = std::get<1>(kvp); - register_kvp(2, t, first, second); - } - { - lua_createtable(L, 0, 2 + static_cast(umx.callconstructfunc.valid())); - stack_reference metabehind(L, -1); - if (umx.callconstructfunc.valid()) { - stack::set_field(L, sol::meta_function::call_function, umx.callconstructfunc, metabehind.stack_index()); - } - // use indexing function - stack::set_field(L, meta_function::index, - make_closure(sic, - nullptr, - make_light(varmap), - nullptr, - nullptr, - usertype_detail::toplevel_magic - ), metabehind.stack_index()); - stack::set_field(L, meta_function::new_index, - make_closure(snic, - nullptr, - make_light(varmap), - nullptr, - nullptr, - usertype_detail::toplevel_magic - ), metabehind.stack_index()); - stack::set_field(L, metatable_key, metabehind, t.stack_index()); - metabehind.pop(); - } - - // Don't pop the table when we're done; - // return it - return 1; - } - }; - } // stack -} // sol - -// end of sol/simple_usertype_metatable.hpp - -// beginning of sol/container_usertype_metatable.hpp - -namespace sol { - - namespace detail { - - template - struct has_find { - private: - typedef std::array one; - typedef std::array two; - - template static one test(decltype(std::declval().find(std::declval>()))*); - template static two test(...); - - public: - static const bool value = sizeof(test(0)) == sizeof(char); - }; - - template - struct has_push_back { - private: - typedef std::array one; - typedef std::array two; - - template static one test(decltype(std::declval().push_back(std::declval>()))*); - template static two test(...); - - public: - static const bool value = sizeof(test(0)) == sizeof(char); - }; - - template - struct has_clear { - private: - typedef std::array one; - typedef std::array two; - - template static one test(decltype(&C::clear)); - template static two test(...); - - public: - static const bool value = sizeof(test(0)) == sizeof(char); - }; - - template - struct has_insert { - private: - typedef std::array one; - typedef std::array two; - - template static one test(decltype(std::declval().insert(std::declval>(), std::declval>()))*); - template static two test(...); - - public: - static const bool value = sizeof(test(0)) == sizeof(char); - }; - - template - T& get_first(const T& t) { - return std::forward(t); - } - - template - decltype(auto) get_first(const std::pair& t) { - return t.first; - } - - template >> = meta::enabler> - auto find(C& c, I&& i) { - return c.find(std::forward(i)); - } - - template >> = meta::enabler> - auto find(C& c, I&& i) { - using std::begin; - using std::end; - return std::find_if(begin(c), end(c), [&i](auto&& x) { - return i == get_first(x); - }); - } - - } - - template - struct container_usertype_metatable { - typedef meta::has_key_value_pair> is_associative; - typedef meta::unqualified_t T; - typedef typename T::iterator I; - typedef std::conditional_t> KV; - typedef typename KV::first_type K; - typedef typename KV::second_type V; - typedef std::remove_reference_t())> IR; - typedef typename meta::iterator_tag::type tag_t; - typedef std::conditional_t::value, - V, - std::conditional_t()) - > - > push_type; - - struct iter { - T& source; - I it; - - iter(T& source, I it) : source(source), it(std::move(it)) {} - }; - - static auto& get_src(lua_State* L) { -#ifdef SOL_SAFE_USERTYPE - auto p = stack::check_get(L, 1); - if (!p || p.value() == nullptr) { - luaL_error(L, "sol: 'self' argument is not the proper type (pass 'self' as first argument with ':' or call on proper type)"); - } - return *p.value(); -#else - return stack::get(L, 1); -#endif // Safe getting with error - } - - static int real_index_call_associative(std::true_type, lua_State* L) { - auto k = stack::check_get(L, 2); - if (k) { - auto& src = get_src(L); - using std::end; - auto it = detail::find(src, *k); - if (it != end(src)) { - auto& v = *it; - return stack::stack_detail::push_reference(L, v.second); - } - } - else { - auto maybename = stack::check_get(L, 2); - if (maybename) { - auto& name = *maybename; - if (name == "add") { - return stack::push(L, &add_call); - } - else if (name == "insert") { - return stack::push(L, &insert_call); - } - else if (name == "clear") { - return stack::push(L, &clear_call); - } - else if (name == "find") { - return stack::push(L, &find_call); - } - } - } - return stack::push(L, lua_nil); - } - - static int real_index_call_associative(std::false_type, lua_State* L) { - auto& src = get_src(L); - auto maybek = stack::check_get(L, 2); - if (maybek) { - using std::begin; - auto it = begin(src); - K k = *maybek; - if (k > src.size() || k < 1) { - return stack::push(L, lua_nil); - } - --k; - std::advance(it, k); - return stack::stack_detail::push_reference(L, *it); - } - else { - auto maybename = stack::check_get(L, 2); - if (maybename) { - auto& name = *maybename; - if (name == "add") { - return stack::push(L, &add_call); - } - else if (name == "insert") { - return stack::push(L, &insert_call); - } - else if (name == "clear") { - return stack::push(L, &clear_call); - } - else if (name == "find") { - return stack::push(L, &find_call); - } - } - } - - return stack::push(L, lua_nil); - } - - static int real_index_call(lua_State* L) { - return real_index_call_associative(is_associative(), L); - } - - static int real_new_index_call_const(std::false_type, std::false_type, lua_State* L) { - return luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); - } - - static int real_new_index_call_const(std::false_type, std::true_type, lua_State* L) { - return luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); - } - - static int real_new_index_call_const(std::true_type, std::true_type, lua_State* L) { - auto& src = get_src(L); -#ifdef SOL_CHECK_ARGUMENTS - auto maybek = stack::check_get(L, 2); - if (!maybek) { - return luaL_error(L, "sol: improper key of type %s to a %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); - } - K& k = *maybek; -#else - K k = stack::get(L, 2); -#endif - using std::end; - auto it = detail::find(src, k); - if (it != end(src)) { - auto& v = *it; - v.second = stack::get(L, 3); - } - else { - src.insert(it, { std::move(k), stack::get(L, 3) }); - } - return 0; - } - - static int real_new_index_call_const(std::true_type, std::false_type, lua_State* L) { - auto& src = get_src(L); -#ifdef SOL_CHECK_ARGUMENTS - auto maybek = stack::check_get(L, 2); - if (!maybek) { - return luaL_error(L, "sol: improper index of type %s to a %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); - } - K& k = *maybek; -#else - K k = stack::get(L, 2); -#endif - using std::begin; - auto it = begin(src); -#ifdef SOL_CHECK_ARGUMENTS - if (k < 1) { - return luaL_error(L, "sol: out of bounds index to a %s", detail::demangle().c_str()); - } -#endif - --k; - if (k == src.size()) { - real_add_call_push(std::integral_constant::value && std::is_copy_constructible::value>(), L, src, 1); - return 0; - } -#ifdef SOL_CHECK_ARGUMENTS - if (k > src.size()) { - return luaL_error(L, "sol: out of bounds index to a %s", detail::demangle().c_str()); - } -#endif - std::advance(it, k); - *it = stack::get(L, 3); - return 0; - } - - static int real_new_index_call(lua_State* L) { - return real_new_index_call_const(meta::neg, std::is_const, meta::neg>>>(), is_associative(), L); - } - - static int real_pairs_next_call_assoc(std::true_type, lua_State* L) { - using std::end; - iter& i = stack::get>(L, 1); - auto& source = i.source; - auto& it = i.it; - if (it == end(source)) { - return 0; - } - int p; - p = stack::push_reference(L, it->first); - p += stack::stack_detail::push_reference(L, it->second); - std::advance(it, 1); - return p; - } - - static int real_pairs_call_assoc(std::true_type, lua_State* L) { - auto& src = get_src(L); - using std::begin; - stack::push(L, pairs_next_call); - stack::push>(L, src, begin(src)); - stack::push(L, 1); - return 3; - } - - static int real_pairs_next_call_assoc(std::false_type, lua_State* L) { - using std::end; - iter& i = stack::get>(L, 1); - auto& source = i.source; - auto& it = i.it; - K k = stack::get(L, 2); - if (it == end(source)) { - return 0; - } - int p; - p = stack::push_reference(L, k + 1); - p += stack::stack_detail::push_reference(L, *it); - std::advance(it, 1); - return p; - } - - static int real_pairs_call_assoc(std::false_type, lua_State* L) { - auto& src = get_src(L); - using std::begin; - stack::push(L, pairs_next_call); - stack::push>(L, src, begin(src)); - stack::push(L, 0); - return 3; - } - - static int real_pairs_next_call(lua_State* L) { - return real_pairs_next_call_assoc(is_associative(), L); - } - - static int real_pairs_call(lua_State* L) { - return real_pairs_call_assoc(is_associative(), L); - } - - static int real_length_call(lua_State*L) { - auto& src = get_src(L); - return stack::push(L, src.size()); - } - - static int real_add_call_insert(std::true_type, lua_State*L, T& src, int boost = 0) { - using std::end; - src.insert(end(src), stack::get(L, 2 + boost)); - return 0; - } - - static int real_add_call_insert(std::false_type, lua_State*L, T&, int = 0) { - static const std::string& s = detail::demangle(); - return luaL_error(L, "sol: cannot call insert on type %s", s.c_str()); - } - - static int real_add_call_push(std::true_type, lua_State*L, T& src, int boost = 0) { - src.push_back(stack::get(L, 2 + boost)); - return 0; - } - - static int real_add_call_push(std::false_type, lua_State*L, T& src, int boost = 0) { - return real_add_call_insert(std::integral_constant::value && std::is_copy_constructible::value>(), L, src, boost); - } - - static int real_add_call_associative(std::true_type, lua_State* L) { - return real_insert_call(L); - } - - static int real_add_call_associative(std::false_type, lua_State* L) { - auto& src = get_src(L); - return real_add_call_push(std::integral_constant::value && std::is_copy_constructible::value>(), L, src); - } - - static int real_add_call_capable(std::true_type, lua_State* L) { - return real_add_call_associative(is_associative(), L); - } - - static int real_add_call_capable(std::false_type, lua_State* L) { - static const std::string& s = detail::demangle(); - return luaL_error(L, "sol: cannot call add on type %s", s.c_str()); - } - - static int real_add_call(lua_State* L) { - return real_add_call_capable(std::integral_constant::value || detail::has_insert::value) && std::is_copy_constructible::value>(), L); - } - - static int real_insert_call_capable(std::false_type, std::false_type, lua_State*L) { - static const std::string& s = detail::demangle(); - return luaL_error(L, "sol: cannot call insert on type %s", s.c_str()); - } - - static int real_insert_call_capable(std::false_type, std::true_type, lua_State*L) { - return real_insert_call_capable(std::false_type(), std::false_type(), L); - } - - static int real_insert_call_capable(std::true_type, std::false_type, lua_State* L) { - using std::begin; - auto& src = get_src(L); - src.insert(std::next(begin(src), stack::get(L, 2)), stack::get(L, 3)); - return 0; - } - - static int real_insert_call_capable(std::true_type, std::true_type, lua_State* L) { - return real_new_index_call(L); - } - - static int real_insert_call(lua_State*L) { - return real_insert_call_capable(std::integral_constant::value && std::is_copy_assignable::value>(), is_associative(), L); - } - - static int real_clear_call_capable(std::false_type, lua_State* L) { - static const std::string& s = detail::demangle(); - return luaL_error(L, "sol: cannot call clear on type %s", s.c_str()); - } - - static int real_clear_call_capable(std::true_type, lua_State* L) { - auto& src = get_src(L); - src.clear(); - return 0; - } - - static int real_clear_call(lua_State*L) { - return real_clear_call_capable(std::integral_constant::value>(), L); - } - - static int real_find_call_capable(std::false_type, std::false_type, lua_State*L) { - static const std::string& s = detail::demangle(); - return luaL_error(L, "sol: cannot call find on type %s", s.c_str()); - } - - static int real_find_call_capable(std::false_type, std::true_type, lua_State*L) { - return real_index_call(L); - } - - static int real_find_call_capable(std::true_type, std::false_type, lua_State* L) { - auto k = stack::check_get(L, 2); - if (k) { - auto& src = get_src(L); - auto it = src.find(*k); - if (it != src.end()) { - auto& v = *it; - return stack::stack_detail::push_reference(L, v); - } - } - return stack::push(L, lua_nil); - } - - static int real_find_call_capable(std::true_type, std::true_type, lua_State* L) { - return real_index_call(L); - } - - static int real_find_call(lua_State*L) { - return real_find_call_capable(std::integral_constant::value>(), is_associative(), L); - } - - static int add_call(lua_State*L) { - return detail::static_trampoline<(&real_add_call)>(L); - } - - static int insert_call(lua_State*L) { - return detail::static_trampoline<(&real_insert_call)>(L); - } - - static int clear_call(lua_State*L) { - return detail::static_trampoline<(&real_clear_call)>(L); - } - - static int find_call(lua_State*L) { - return detail::static_trampoline<(&real_find_call)>(L); - } - - static int length_call(lua_State*L) { - return detail::static_trampoline<(&real_length_call)>(L); - } - - static int pairs_next_call(lua_State*L) { - return detail::static_trampoline<(&real_pairs_next_call)>(L); - } - - static int pairs_call(lua_State*L) { - return detail::static_trampoline<(&real_pairs_call)>(L); - } - - static int index_call(lua_State*L) { - return detail::static_trampoline<(&real_index_call)>(L); - } - - static int new_index_call(lua_State*L) { - return detail::static_trampoline<(&real_new_index_call)>(L); - } - }; - - namespace stack { - namespace stack_detail { - template - inline auto container_metatable() { - typedef container_usertype_metatable> meta_cumt; - std::array reg = { { - { "__index", &meta_cumt::index_call }, - { "__newindex", &meta_cumt::new_index_call }, - { "__pairs", &meta_cumt::pairs_call }, - { "__ipairs", &meta_cumt::pairs_call }, - { "__len", &meta_cumt::length_call }, - { "clear", &meta_cumt::clear_call }, - { "insert", &meta_cumt::insert_call }, - { "add", &meta_cumt::add_call }, - { "find", &meta_cumt::find_call }, - std::is_pointer::value ? luaL_Reg{ nullptr, nullptr } : luaL_Reg{ "__gc", &detail::usertype_alloc_destroy }, - { nullptr, nullptr } - } }; - return reg; - } - - template - inline auto container_metatable_behind() { - typedef container_usertype_metatable> meta_cumt; - std::array reg = { { - { "__index", &meta_cumt::index_call }, - { "__newindex", &meta_cumt::new_index_call }, - { nullptr, nullptr } - } }; - return reg; - } - - template - struct metatable_setup { - lua_State* L; - - metatable_setup(lua_State* L) : L(L) {} - - void operator()() { - static const auto reg = container_metatable(); - static const auto containerreg = container_metatable_behind(); - static const char* metakey = &usertype_traits::metatable()[0]; - - if (luaL_newmetatable(L, metakey) == 1) { - stack_reference metatable(L, -1); - luaL_setfuncs(L, reg.data(), 0); - - lua_createtable(L, 0, static_cast(containerreg.size())); - stack_reference metabehind(L, -1); - luaL_setfuncs(L, containerreg.data(), 0); - - stack::set_field(L, metatable_key, metabehind, metatable.stack_index()); - metabehind.pop(); - } - lua_setmetatable(L, -2); - } - }; - } - - template - struct pusher>, meta::neg>, std::is_base_of>>>>::value>> { - static int push(lua_State* L, const T& cont) { - stack_detail::metatable_setup fx(L); - return pusher>{}.push_fx(L, fx, cont); - } - - static int push(lua_State* L, T&& cont) { - stack_detail::metatable_setup fx(L); - return pusher>{}.push_fx(L, fx, std::move(cont)); - } - }; - - template - struct pusher>, meta::neg>, std::is_base_of>>>>::value>> { - static int push(lua_State* L, T* cont) { - stack_detail::metatable_setup>*> fx(L); - return pusher>{}.push_fx(L, fx, cont); - } - }; - } // stack - -} // sol - -// end of sol/container_usertype_metatable.hpp - -namespace sol { - - template - class usertype { - private: - std::unique_ptr metatableregister; - - template - usertype(usertype_detail::verified_tag, Args&&... args) : metatableregister(detail::make_unique_deleter, Args...>, detail::deleter>(std::forward(args)...)) {} - - template - usertype(usertype_detail::add_destructor_tag, Args&&... args) : usertype(usertype_detail::verified, std::forward(args)..., "__gc", default_destructor) {} - - template - usertype(usertype_detail::check_destructor_tag, Args&&... args) : usertype(meta::condition, meta::neg>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward(args)...) {} - - public: - - template - usertype(Args&&... args) : usertype(meta::condition, meta::neg>>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), std::forward(args)...) {} - - template - usertype(constructors constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward(args)..., "new", constructorlist) {} - - template - usertype(constructor_wrapper constructorlist, Args&&... args) : usertype(usertype_detail::check_destructor_tag(), std::forward(args)..., "new", constructorlist) {} - - template - usertype(simple_tag, lua_State* L, Args&&... args) : metatableregister(detail::make_unique_deleter, detail::deleter>(L, std::forward(args)...)) {} - - usertype_detail::registrar* registrar_data() { - return metatableregister.get(); - } - - int push(lua_State* L) { - int r = metatableregister->push_um(L); - metatableregister = nullptr; - return r; - } - }; - - template - class simple_usertype : public usertype { - private: - typedef usertype base_t; - lua_State* state; - - public: - template - simple_usertype(lua_State* L, Args&&... args) : base_t(simple, L, std::forward(args)...), state(L) {} - - template - void set(N&& n, F&& f) { - auto meta = static_cast*>(base_t::registrar_data()); - meta->add(state, n, f); - } - }; - - namespace stack { - template - struct pusher> { - static int push(lua_State* L, usertype& user) { - return user.push(L); - } - }; - } // stack -} // sol - -// end of sol/usertype.hpp - -// beginning of sol/table_iterator.hpp - -namespace sol { - - template - class basic_table_iterator : public std::iterator> { - private: - typedef std::iterator> base_t; - public: - typedef object key_type; - typedef object mapped_type; - typedef base_t::value_type value_type; - typedef base_t::iterator_category iterator_category; - typedef base_t::difference_type difference_type; - typedef base_t::pointer pointer; - typedef base_t::reference reference; - typedef const value_type& const_reference; - - private: - std::pair kvp; - reference_type ref; - int tableidx = 0; - int keyidx = 0; - std::ptrdiff_t idx = 0; - - public: - - basic_table_iterator() : keyidx(-1), idx(-1) { - - } - - basic_table_iterator(reference_type x) : ref(std::move(x)) { - ref.push(); - tableidx = lua_gettop(ref.lua_state()); - stack::push(ref.lua_state(), lua_nil); - this->operator++(); - if (idx == -1) { - return; - } - --idx; - } - - basic_table_iterator& operator++() { - if (idx == -1) - return *this; - - if (lua_next(ref.lua_state(), tableidx) == 0) { - idx = -1; - keyidx = -1; - return *this; - } - ++idx; - kvp.first = object(ref.lua_state(), -2); - kvp.second = object(ref.lua_state(), -1); - lua_pop(ref.lua_state(), 1); - // leave key on the stack - keyidx = lua_gettop(ref.lua_state()); - return *this; - } - - basic_table_iterator operator++(int) { - auto saved = *this; - this->operator++(); - return saved; - } - - reference operator*() { - return kvp; - } - - const_reference operator*() const { - return kvp; - } - - bool operator== (const basic_table_iterator& right) const { - return idx == right.idx; - } - - bool operator!= (const basic_table_iterator& right) const { - return idx != right.idx; - } - - ~basic_table_iterator() { - if (keyidx != -1) { - stack::remove(ref.lua_state(), keyidx, 1); - } - if (ref.valid()) { - stack::remove(ref.lua_state(), tableidx, 1); - } - } - }; - -} // sol - -// end of sol/table_iterator.hpp - -namespace sol { - namespace detail { - template - struct clean { lua_State* L; clean(lua_State* luastate) : L(luastate) {} ~clean() { lua_pop(L, static_cast(n)); } }; - struct ref_clean { lua_State* L; int& n; ref_clean(lua_State* luastate, int& n) : L(luastate), n(n) {} ~ref_clean() { lua_pop(L, static_cast(n)); } }; - inline int fail_on_newindex(lua_State* L) { - return luaL_error(L, "sol: cannot modify the elements of an enumeration table"); - } - } - - const new_table create = new_table{}; - - template - class basic_table_core : public basic_object_base { - typedef basic_object_base base_t; - friend class state; - friend class state_view; - - template - using is_global = meta::all, meta::is_c_str...>; - - template - void for_each(std::true_type, Fx&& fx) const { - auto pp = stack::push_pop(*this); - stack::push(base_t::lua_state(), lua_nil); - while (lua_next(base_t::lua_state(), -2)) { - sol::object key(base_t::lua_state(), -2); - sol::object value(base_t::lua_state(), -1); - std::pair keyvalue(key, value); - auto pn = stack::pop_n(base_t::lua_state(), 1); - fx(keyvalue); - } - } - - template - void for_each(std::false_type, Fx&& fx) const { - auto pp = stack::push_pop(*this); - stack::push(base_t::lua_state(), lua_nil); - while (lua_next(base_t::lua_state(), -2)) { - sol::object key(base_t::lua_state(), -2); - sol::object value(base_t::lua_state(), -1); - auto pn = stack::pop_n(base_t::lua_state(), 1); - fx(key, value); - } - } - - template - auto tuple_get(types, std::index_sequence<0, 1, I...>, Keys&& keys) const - -> decltype(stack::pop>(nullptr)) { - typedef decltype(stack::pop>(nullptr)) Tup; - return Tup( - traverse_get_optional(meta::is_optional>(), detail::forward_get<0>(keys)), - traverse_get_optional(meta::is_optional>(), detail::forward_get<1>(keys)), - traverse_get_optional(meta::is_optional>(), detail::forward_get(keys))... - ); - } - - template - decltype(auto) tuple_get(types, std::index_sequence, Keys&& keys) const { - return traverse_get_optional(meta::is_optional>(), detail::forward_get(keys)); - } - - template - void tuple_set(std::index_sequence, Pairs&& pairs) { - auto pp = stack::push_pop(pairs))...>::value)>(*this); - void(detail::swallow{ (stack::set_field(base_t::lua_state(), - detail::forward_get(pairs), - detail::forward_get(pairs), - lua_gettop(base_t::lua_state()) - ), 0)... }); - } - - template - decltype(auto) traverse_get_deep(Key&& key) const { - stack::get_field(base_t::lua_state(), std::forward(key)); - return stack::get(base_t::lua_state()); - } - - template - decltype(auto) traverse_get_deep(Key&& key, Keys&&... keys) const { - stack::get_field(base_t::lua_state(), std::forward(key)); - return traverse_get_deep(std::forward(keys)...); - } - - template - decltype(auto) traverse_get_deep_optional(int& popcount, Key&& key) const { - typedef decltype(stack::get(base_t::lua_state())) R; - auto p = stack::probe_get_field(base_t::lua_state(), std::forward(key), lua_gettop(base_t::lua_state())); - popcount += p.levels; - if (!p.success) - return R(nullopt); - return stack::get(base_t::lua_state()); - } - - template - decltype(auto) traverse_get_deep_optional(int& popcount, Key&& key, Keys&&... keys) const { - auto p = I > 0 ? stack::probe_get_field(base_t::lua_state(), std::forward(key), -1) : stack::probe_get_field(base_t::lua_state(), std::forward(key), lua_gettop(base_t::lua_state())); - popcount += p.levels; - if (!p.success) - return T(nullopt); - return traverse_get_deep_optional(popcount, std::forward(keys)...); - } - - template - decltype(auto) traverse_get_optional(std::false_type, Keys&&... keys) const { - detail::clean c(base_t::lua_state()); - return traverse_get_deep(std::forward(keys)...); - } - - template - decltype(auto) traverse_get_optional(std::true_type, Keys&&... keys) const { - int popcount = 0; - detail::ref_clean c(base_t::lua_state(), popcount); - return traverse_get_deep_optional(popcount, std::forward(keys)...); - } - - template - void traverse_set_deep(Key&& key, Value&& value) const { - stack::set_field(base_t::lua_state(), std::forward(key), std::forward(value)); - } - - template - void traverse_set_deep(Key&& key, Keys&&... keys) const { - stack::get_field(base_t::lua_state(), std::forward(key)); - traverse_set_deep(std::forward(keys)...); - } - - basic_table_core(lua_State* L, detail::global_tag t) noexcept : base_t(L, t) { } - - protected: - basic_table_core(detail::no_safety_tag, lua_State* L, int index) : base_t(L, index) {} - basic_table_core(detail::no_safety_tag, lua_State* L, ref_index index) : base_t(L, index) {} - template , basic_table_core>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_table_core(detail::no_safety_tag, T&& r) noexcept : base_t(std::forward(r)) {} - - public: - typedef basic_table_iterator iterator; - typedef iterator const_iterator; - - basic_table_core() noexcept = default; - basic_table_core(const basic_table_core&) = default; - basic_table_core(basic_table_core&&) = default; - basic_table_core& operator=(const basic_table_core&) = default; - basic_table_core& operator=(basic_table_core&&) = default; - basic_table_core(const stack_reference& r) : basic_table_core(r.lua_state(), r.stack_index()) {} - basic_table_core(stack_reference&& r) : basic_table_core(r.lua_state(), r.stack_index()) {} - template >>, meta::neg, ref_index>>> = meta::enabler> - basic_table_core(lua_State* L, T&& r) : basic_table_core(L, sol::ref_index(r.registry_index())) {} - basic_table_core(lua_State* L, new_table nt) : base_t(L, (lua_createtable(L, nt.sequence_hint, nt.map_hint), -1)) { - if (!std::is_base_of::value) { - lua_pop(L, 1); - } - } - basic_table_core(lua_State* L, int index = -1) : basic_table_core(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_table_core(lua_State* L, ref_index index) : basic_table_core(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, -1, type_panic); -#endif // Safety - } - template , basic_table_core>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_table_core(T&& r) noexcept : basic_table_core(detail::no_safety, std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_table>::value) { - auto pp = stack::push_pop(*this); - stack::check(base_t::lua_state(), -1, type_panic); - } -#endif // Safety - } - - iterator begin() const { - return iterator(*this); - } - - iterator end() const { - return iterator(); - } - - const_iterator cbegin() const { - return begin(); - } - - const_iterator cend() const { - return end(); - } - - template - decltype(auto) get(Keys&&... keys) const { - static_assert(sizeof...(Keys) == sizeof...(Ret), "number of keys and number of return types do not match"); - auto pp = stack::push_pop::value>(*this); - return tuple_get(types(), std::make_index_sequence(), std::forward_as_tuple(std::forward(keys)...)); - } - - template - decltype(auto) get_or(Key&& key, T&& otherwise) const { - typedef decltype(get("")) U; - optional option = get>(std::forward(key)); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) get_or(Key&& key, D&& otherwise) const { - optional option = get>(std::forward(key)); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) traverse_get(Keys&&... keys) const { - auto pp = stack::push_pop::value>(*this); - return traverse_get_optional(meta::is_optional>(), std::forward(keys)...); - } - - template - basic_table_core& traverse_set(Keys&&... keys) { - auto pp = stack::push_pop::value>(*this); - auto pn = stack::pop_n(base_t::lua_state(), static_cast(sizeof...(Keys)-2)); - traverse_set_deep(std::forward(keys)...); - return *this; - } - - template - basic_table_core& set(Args&&... args) { - tuple_set(std::make_index_sequence(), std::forward_as_tuple(std::forward(args)...)); - return *this; - } - - template - basic_table_core& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name(), user); - } - - template - basic_table_core& set_usertype(Key&& key, usertype& user) { - return set(std::forward(key), user); - } - - template - basic_table_core& new_usertype(const std::string& name, Args&&... args) { - usertype utype(std::forward(args)...); - set_usertype(name, utype); - return *this; - } - - template - basic_table_core& new_usertype(const std::string& name, Args&&... args) { - constructors> ctor{}; - return new_usertype(name, ctor, std::forward(args)...); - } - - template - basic_table_core& new_usertype(const std::string& name, constructors ctor, Args&&... args) { - usertype utype(ctor, std::forward(args)...); - set_usertype(name, utype); - return *this; - } - - template - basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) { - simple_usertype utype(base_t::lua_state(), std::forward(args)...); - set_usertype(name, utype); - return *this; - } - - template - basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) { - constructors> ctor{}; - return new_simple_usertype(name, ctor, std::forward(args)...); - } - - template - basic_table_core& new_simple_usertype(const std::string& name, constructors ctor, Args&&... args) { - simple_usertype utype(base_t::lua_state(), ctor, std::forward(args)...); - set_usertype(name, utype); - return *this; - } - - template - simple_usertype create_simple_usertype(Args&&... args) { - simple_usertype utype(base_t::lua_state(), std::forward(args)...); - return utype; - } - - template - simple_usertype create_simple_usertype(Args&&... args) { - constructors> ctor{}; - return create_simple_usertype(ctor, std::forward(args)...); - } - - template - simple_usertype create_simple_usertype(constructors ctor, Args&&... args) { - simple_usertype utype(base_t::lua_state(), ctor, std::forward(args)...); - return utype; - } - - template - basic_table_core& new_enum(const std::string& name, Args&&... args) { - if (read_only) { - table idx = create_with(std::forward(args)...); - table x = create_with( - meta_function::new_index, detail::fail_on_newindex, - meta_function::index, idx - ); - table target = create_named(name); - target[metatable_key] = x; - } - else { - create_named(name, std::forward(args)...); - } - return *this; - } - - template - void for_each(Fx&& fx) const { - typedef meta::is_invokable)> is_paired; - for_each(is_paired(), std::forward(fx)); - } - - size_t size() const { - auto pp = stack::push_pop(*this); - lua_len(base_t::lua_state(), -1); - return stack::pop(base_t::lua_state()); - } - - bool empty() const { - return cbegin() == cend(); - } - - template - proxy operator[](T&& key) & { - return proxy(*this, std::forward(key)); - } - - template - proxy operator[](T&& key) const & { - return proxy(*this, std::forward(key)); - } - - template - proxy operator[](T&& key) && { - return proxy(*this, std::forward(key)); - } - - template - basic_table_core& set_function(Key&& key, Args&&... args) { - set_fx(types(), std::forward(key), std::forward(args)...); - return *this; - } - - template - basic_table_core& set_function(Key&& key, Args&&... args) { - set_fx(types<>(), std::forward(key), std::forward(args)...); - return *this; - } - - template - basic_table_core& add(Args&&... args) { - auto pp = stack::push_pop(*this); - (void)detail::swallow{0, - (stack::set_ref(base_t::lua_state(), std::forward(args)), 0)... - }; - return *this; - } - - private: - template> - void set_fx(types, Key&& key, Fx&& fx) { - set_resolved_function(std::forward(key), std::forward(fx)); - } - - template>> = meta::enabler> - void set_fx(types<>, Key&& key, Fx&& fx) { - set(std::forward(key), std::forward(fx)); - } - - template>> = meta::enabler> - void set_fx(types<>, Key&& key, Fx&& fx, Args&&... args) { - set(std::forward(key), as_function_reference(std::forward(fx), std::forward(args)...)); - } - - template - void set_resolved_function(Key&& key, Args&&... args) { - set(std::forward(key), as_function_reference>(std::forward(args)...)); - } - - public: - static inline table create(lua_State* L, int narr = 0, int nrec = 0) { - lua_createtable(L, narr, nrec); - table result(L); - lua_pop(L, 1); - return result; - } - - template - static inline table create(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - lua_createtable(L, narr, nrec); - table result(L); - result.set(std::forward(key), std::forward(value), std::forward(args)...); - lua_pop(L, 1); - return result; - } - - template - static inline table create_with(lua_State* L, Args&&... args) { - static_assert(sizeof...(Args) % 2 == 0, "You must have an even number of arguments for a key, value ... list."); - static const int narr = static_cast(meta::count_2_for_pack::value); - return create(L, narr, static_cast((sizeof...(Args) / 2) - narr), std::forward(args)...); - } - - table create(int narr = 0, int nrec = 0) { - return create(base_t::lua_state(), narr, nrec); - } - - template - table create(int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - return create(base_t::lua_state(), narr, nrec, std::forward(key), std::forward(value), std::forward(args)...); - } - - template - table create(Name&& name, int narr = 0, int nrec = 0) { - table x = create(base_t::lua_state(), narr, nrec); - this->set(std::forward(name), x); - return x; - } - - template - table create(Name&& name, int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - table x = create(base_t::lua_state(), narr, nrec, std::forward(key), std::forward(value), std::forward(args)...); - this->set(std::forward(name), x); - return x; - } - - template - table create_with(Args&&... args) { - return create_with(base_t::lua_state(), std::forward(args)...); - } - - template - table create_named(Name&& name, Args&&... args) { - static const int narr = static_cast(meta::count_2_for_pack::value); - return create(std::forward(name), narr, sizeof...(Args) / 2 - narr, std::forward(args)...); - } - - ~basic_table_core() { - - } - }; -} // sol - -// end of sol/table_core.hpp - -namespace sol { - typedef table_core table; - - namespace stack { - template <> - struct getter { - static table get(lua_State* L, int index = -1) { - if (lua_getmetatable(L, index) == 0) { - return table(L, ref_index(LUA_REFNIL)); - } - return table(L, -1); - } - }; - } // stack -} // sol - -// end of sol/table.hpp - -// beginning of sol/environment.hpp - -namespace sol { - - template - struct basic_environment : basic_table { - private: - typedef basic_table base_t; - - public: - basic_environment() noexcept = default; - basic_environment(const basic_environment&) = default; - basic_environment(basic_environment&&) = default; - basic_environment& operator=(const basic_environment&) = default; - basic_environment& operator=(basic_environment&&) = default; - basic_environment(const stack_reference& r) : basic_environment(r.lua_state(), r.stack_index()) {} - basic_environment(stack_reference&& r) : basic_environment(r.lua_state(), r.stack_index()) {} - - basic_environment(lua_State* L, new_table nt) : base_t(L, std::move(nt)) {} - basic_environment(lua_State* L, new_table t, const reference& fallback) : basic_environment(L, std::move(t)) { - sol::stack_table mt(L, sol::new_table(0, 1)); - mt.set(sol::meta_function::index, fallback); - this->set(metatable_key, mt); - mt.pop(); - } - - basic_environment(env_t, const stack_reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(this->lua_state(), -1, type_panic); -#endif // Safety - lua_pop(this->lua_state(), 2); - } - basic_environment(env_t, const reference& extraction_target) : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(this->lua_state(), -1, type_panic); -#endif // Safety - lua_pop(this->lua_state(), 2); - } - basic_environment(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_environment(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, -1, type_panic); -#endif // Safety - } - template , basic_environment>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_environment(T&& r) noexcept : base_t(detail::no_safety, std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_environment>::value) { - auto pp = stack::push_pop(*this); - stack::check(base_t::lua_state(), -1, type_panic); - } -#endif // Safety - } - - template - void set_on(const T& target) const { - lua_State* L = target.lua_state(); - auto pp = stack::push_pop(target); -#if SOL_LUA_VERSION < 502 - // Use lua_setfenv - this->push(); - lua_setfenv(L, -2); -#else - // Use upvalues as explained in Lua 5.2 and beyond's manual - this->push(); - const char* name = lua_setupvalue(L, -2, 1); - if (name == nullptr) { - this->pop(); - } -#endif - } - }; - - template - void set_environment(const basic_environment& env, const T& target) { - env.set_on(target); - } - - template - basic_environment get_environment(const T& target) { - lua_State* L = target.lua_state(); - auto pp = stack::pop_n(L, stack::push_environment_of(target)); - return basic_environment(L, -1); - } - - struct this_environment { - optional env; - - this_environment() : env(nullopt) {} - this_environment(sol::environment e) : env(std::move(e)) {} - this_environment(const this_environment&) = default; - this_environment(this_environment&&) = default; - this_environment& operator=(const this_environment&) = default; - this_environment& operator=(this_environment&&) = default; - - explicit operator bool() const { - return static_cast(env); - } - - operator optional& () { - return env; - } - - operator const optional& () const { - return env; - } - - operator environment& () { - return env.value(); - } - - operator const environment& () const { - return env.value(); - } - }; - - namespace stack { - template <> - struct getter { - static environment get(lua_State* L, int index, record& tracking) { - tracking.use(1); - return get_environment(stack_reference(L, raw_index(index))); - } - }; - - template <> - struct getter { - static this_environment get(lua_State* L, int, record& tracking) { - tracking.use(0); - lua_Debug info; - // Level 0 means current function (this C function, which may or may not be useful for us?) - // Level 1 means next call frame up the stack. (Can be nothing if function called directly from C++ with lua_p/call) - int pre_stack_size = lua_gettop(L); - if (lua_getstack(L, 1, &info) != 1) { - if (lua_getstack(L, 0, &info) != 1) { - lua_settop(L, pre_stack_size); - return this_environment(); - } - } - if (lua_getinfo(L, "f", &info) == 0) { - lua_settop(L, pre_stack_size); - return this_environment(); - } - - sol::stack_reference f(L, -1); - sol::environment env(sol::env_key, f); - if (!env.valid()) { - lua_settop(L, pre_stack_size); - return this_environment(); - } - return this_environment(std::move(env)); - } - }; - } // stack -} // sol - -// end of sol/environment.hpp - -// beginning of sol/load_result.hpp - -namespace sol { - struct load_result : public proxy_base { - private: - lua_State* L; - int index; - int returncount; - int popcount; - load_status err; - - template - decltype(auto) tagged_get(types>) const { - if (!valid()) { - return optional(nullopt); - } - return stack::get>(L, index); - } - - template - decltype(auto) tagged_get(types) const { -#ifdef SOL_CHECK_ARGUMENTS - if (!valid()) { - type_panic(L, index, type_of(L, index), type::none); - } -#endif // Check Argument Safety - return stack::get(L, index); - } - - optional tagged_get(types>) const { - if (valid()) { - return nullopt; - } - return error(detail::direct_error, stack::get(L, index)); - } - - error tagged_get(types) const { -#ifdef SOL_CHECK_ARGUMENTS - if (valid()) { - type_panic(L, index, type_of(L, index), type::none); - } -#endif // Check Argument Safety - return error(detail::direct_error, stack::get(L, index)); - } - - public: - load_result() = default; - load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept : L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) { - - } - load_result(const load_result&) = default; - load_result& operator=(const load_result&) = default; - load_result(load_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) { - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but we will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - o.popcount = 0; - o.err = load_status::syntax; - } - load_result& operator=(load_result&& o) noexcept { - L = o.L; - index = o.index; - returncount = o.returncount; - popcount = o.popcount; - err = o.err; - // Must be manual, otherwise destructor will screw us - // return count being 0 is enough to keep things clean - // but we will be thorough - o.L = nullptr; - o.index = 0; - o.returncount = 0; - o.popcount = 0; - o.err = load_status::syntax; - return *this; - } - - load_status status() const noexcept { - return err; - } - - bool valid() const noexcept { - return status() == load_status::ok; - } - - template - T get() const { - return tagged_get(types>()); - } - - template - decltype(auto) call(Args&&... args) { - return get().template call(std::forward(args)...); - } - - template - decltype(auto) operator()(Args&&... args) { - return call<>(std::forward(args)...); - } - - lua_State* lua_state() const noexcept { return L; }; - int stack_index() const noexcept { return index; }; - - ~load_result() { - stack::remove(L, index, popcount); - } - }; -} // sol - -// end of sol/load_result.hpp - -namespace sol { - enum class lib : char { - base, - package, - coroutine, - string, - os, - math, - table, - debug, - bit32, - io, - ffi, - jit, - utf8, - count - }; - - inline std::size_t total_memory_used(lua_State* L) { - std::size_t kb = lua_gc(L, LUA_GCCOUNT, 0); - kb *= 1024; - kb += lua_gc(L, LUA_GCCOUNTB, 0); - return kb; - } - - inline protected_function_result simple_on_error(lua_State*, sol::protected_function_result result) { - return result; - } - - inline protected_function_result default_on_error( lua_State* L, protected_function_result pfr ) { - type t = type_of(L, pfr.stack_index()); - std::string err = to_string(pfr.status()) + " error"; - if (t == type::string) { - err += " "; - err += stack::get(L, pfr.stack_index()); - } -#ifdef SOL_NO_EXCEPTIONS - if (t != type::nil) { - lua_pop(L, 1); - } - stack::push(L, err); - lua_error(L); -#else - throw error(detail::direct_error, err); -#endif - return pfr; - } - - class state_view { - private: - lua_State* L; - table reg; - global_table global; - - optional is_loaded_package(const std::string& key) { - auto loaded = reg.traverse_get>("_LOADED", key); - bool is53mod = loaded && !(loaded->is() && !loaded->as()); - if (is53mod) - return loaded; -#if SOL_LUA_VERSION <= 501 - auto loaded51 = global.traverse_get>("package", "loaded", key); - bool is51mod = loaded51 && !(loaded51->is() && !loaded51->as()); - if (is51mod) - return loaded51; -#endif - return nullopt; - } - - template - void ensure_package(const std::string& key, T&& sr) { -#if SOL_LUA_VERSION <= 501 - auto pkg = global["package"]; - if (!pkg.valid()) { - pkg = create_table_with("loaded", create_table_with(key, sr)); - } - else { - auto ld = pkg["loaded"]; - if (!ld.valid()) { - ld = create_table_with(key, sr); - } - else { - ld[key] = sr; - } - } -#endif - auto loaded = reg["_LOADED"]; - if (!loaded.valid()) { - loaded = create_table_with(key, sr); - } - else { - loaded[key] = sr; - } - } - - template - object require_core(const std::string& key, Fx&& action, bool create_global = true) { - optional loaded = is_loaded_package(key); - if (loaded && loaded->valid()) - return std::move(*loaded); - action(); - auto sr = stack::get(L); - if (create_global) - set(key, sr); - ensure_package(key, sr); - return stack::pop(L); - } - - public: - typedef global_table::iterator iterator; - typedef global_table::const_iterator const_iterator; - - state_view(lua_State* Ls) : - L(Ls), - reg(Ls, LUA_REGISTRYINDEX), - global(Ls, detail::global_) { - - } - - state_view(this_state Ls) : state_view(Ls.L){ - - } - - lua_State* lua_state() const { - return L; - } - - template - void open_libraries(Args&&... args) { - static_assert(meta::all_same::value, "all types must be libraries"); - if (sizeof...(args) == 0) { - luaL_openlibs(L); - return; - } - - lib libraries[1 + sizeof...(args)] = { lib::count, std::forward(args)... }; - - for (auto&& library : libraries) { - switch (library) { -#if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT) - case lib::coroutine: -#endif // luajit opens coroutine base stuff - case lib::base: - luaL_requiref(L, "base", luaopen_base, 1); - lua_pop(L, 1); - break; - case lib::package: - luaL_requiref(L, "package", luaopen_package, 1); - lua_pop(L, 1); - break; -#if !defined(SOL_LUAJIT) - case lib::coroutine: -#if SOL_LUA_VERSION > 501 - luaL_requiref(L, "coroutine", luaopen_coroutine, 1); - lua_pop(L, 1); -#endif // Lua 5.2+ only - break; -#endif // Not LuaJIT - comes builtin - case lib::string: - luaL_requiref(L, "string", luaopen_string, 1); - lua_pop(L, 1); - break; - case lib::table: - luaL_requiref(L, "table", luaopen_table, 1); - lua_pop(L, 1); - break; - case lib::math: - luaL_requiref(L, "math", luaopen_math, 1); - lua_pop(L, 1); - break; - case lib::bit32: -#ifdef SOL_LUAJIT - luaL_requiref(L, "bit32", luaopen_bit, 1); - lua_pop(L, 1); -#elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2) - luaL_requiref(L, "bit32", luaopen_bit32, 1); - lua_pop(L, 1); -#else -#endif // Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags) - break; - case lib::io: - luaL_requiref(L, "io", luaopen_io, 1); - lua_pop(L, 1); - break; - case lib::os: - luaL_requiref(L, "os", luaopen_os, 1); - lua_pop(L, 1); - break; - case lib::debug: - luaL_requiref(L, "debug", luaopen_debug, 1); - lua_pop(L, 1); - break; - case lib::utf8: -#if SOL_LUA_VERSION > 502 && !defined(SOL_LUAJIT) - luaL_requiref(L, "utf8", luaopen_utf8, 1); - lua_pop(L, 1); -#endif // Lua 5.3+ only - break; - case lib::ffi: -#ifdef SOL_LUAJIT - luaL_requiref(L, "ffi", luaopen_ffi, 1); - lua_pop(L, 1); -#endif // LuaJIT only - break; - case lib::jit: -#ifdef SOL_LUAJIT - luaL_requiref(L, "jit", luaopen_jit, 1); - lua_pop(L, 1); -#endif // LuaJIT Only - break; - case lib::count: - default: - break; - } - } - } - - object require(const std::string& key, lua_CFunction open_function, bool create_global = true) { - luaL_requiref(L, key.c_str(), open_function, create_global ? 1 : 0); - return stack::pop(L); - } - - object require_script(const std::string& key, const std::string& code, bool create_global = true) { - return require_core(key, [this, &code]() {stack::script(L, code); }, create_global); - } - - object require_file(const std::string& key, const std::string& filename, bool create_global = true) { - return require_core(key, [this, &filename]() {stack::script_file(L, filename); }, create_global); - } - - template - protected_function_result do_string(const std::string& code, const basic_environment& env) { - load_status x = static_cast(luaL_loadstring(L, code.c_str())); - if (x != load_status::ok) { - return protected_function_result(L, -1, 0, 1, static_cast(x)); - } - protected_function pf(L, -1); - pf.pop(); - set_environment(env, pf); - return pf(); - } - - template - protected_function_result do_file(const std::string& filename, const basic_environment& env) { - load_status x = static_cast(luaL_loadfile(L, filename.c_str())); - if (x != load_status::ok) { - return protected_function_result(L, -1, 0, 1, static_cast(x)); - } - protected_function pf(L, -1); - pf.pop(); - set_environment(env, pf); - return pf(); - } - - protected_function_result do_string(const std::string& code) { - load_status x = static_cast(luaL_loadstring(L, code.c_str())); - if (x != load_status::ok) { - return protected_function_result(L, -1, 0, 1, static_cast(x)); - } - protected_function pf(L, -1); - pf.pop(); - return pf(); - } - - protected_function_result do_file(const std::string& filename) { - load_status x = static_cast(luaL_loadfile(L, filename.c_str())); - if (x != load_status::ok) { - return protected_function_result(L, -1, 0, 1, static_cast(x)); - } - protected_function pf(L, -1); - pf.pop(); - return pf(); - } - - protected_function_result script(const std::string& code, const environment& env) { - return script(code, env, sol::default_on_error); - } - - protected_function_result script_file(const std::string& filename, const environment& env) { - return script_file(filename, env, sol::default_on_error); - } - - template >> = meta::enabler> - protected_function_result script(const std::string& code, Fx&& on_error) { - protected_function_result pfr = do_string(code); - if (!pfr.valid()) { - return on_error(L, std::move(pfr)); - } - return pfr; - } - - template >> = meta::enabler> - protected_function_result script_file(const std::string& filename, Fx&& on_error) { - protected_function_result pfr = do_file(filename); - if (!pfr.valid()) { - return on_error(L, std::move(pfr)); - } - return pfr; - } - - template - protected_function_result script(const std::string& code, const basic_environment& env, Fx&& on_error) { - protected_function_result pfr = do_string(code, env); - if (!pfr.valid()) { - return on_error(L, std::move(pfr)); - } - return pfr; - } - - template - protected_function_result script_file(const std::string& filename, const basic_environment& env, Fx&& on_error) { - protected_function_result pfr = do_file(filename, env); - if (!pfr.valid()) { - return on_error(L, std::move(pfr)); - } - return pfr; - } - - function_result script(const std::string& code) { - int index = lua_gettop(L); - stack::script(L, code); - int postindex = lua_gettop(L); - int returns = postindex - index; - return function_result(L, (std::max)(postindex - (returns - 1), 1), returns); - } - - function_result script_file(const std::string& filename) { - int index = lua_gettop(L); - stack::script_file(L, filename); - int postindex = lua_gettop(L); - int returns = postindex - index; - return function_result(L, (std::max)(postindex - (returns - 1), 1), returns); - } - - load_result load(const std::string& code) { - load_status x = static_cast(luaL_loadstring(L, code.c_str())); - return load_result(L, lua_absindex(L, -1), 1, 1, x); - } - - load_result load_file(const std::string& filename) { - load_status x = static_cast(luaL_loadfile(L, filename.c_str())); - return load_result(L, lua_absindex(L, -1), 1, 1, x); - } - - load_result load_buffer(const char *buff, size_t size, const char *name, const char* mode = nullptr) { - load_status x = static_cast(luaL_loadbufferx(L, buff, size, name, mode)); - return load_result(L, lua_absindex(L, -1), 1, 1, x); - } - - iterator begin() const { - return global.begin(); - } - - iterator end() const { - return global.end(); - } - - const_iterator cbegin() const { - return global.cbegin(); - } - - const_iterator cend() const { - return global.cend(); - } - - global_table globals() const { - return global; - } - - table registry() const { - return reg; - } - - std::size_t memory_used() const { - return total_memory_used(lua_state()); - } - - void collect_garbage() { - lua_gc(lua_state(), LUA_GCCOLLECT, 0); - } - - operator lua_State* () const { - return lua_state(); - } - - void set_panic(lua_CFunction panic) { - lua_atpanic(L, panic); - } - - template - decltype(auto) get(Keys&&... keys) const { - return global.get(std::forward(keys)...); - } - - template - decltype(auto) get_or(Key&& key, T&& otherwise) const { - return global.get_or(std::forward(key), std::forward(otherwise)); - } - - template - decltype(auto) get_or(Key&& key, D&& otherwise) const { - return global.get_or(std::forward(key), std::forward(otherwise)); - } - - template - state_view& set(Args&&... args) { - global.set(std::forward(args)...); - return *this; - } - - template - decltype(auto) traverse_get(Keys&&... keys) const { - return global.traverse_get(std::forward(keys)...); - } - - template - state_view& traverse_set(Args&&... args) { - global.traverse_set(std::forward(args)...); - return *this; - } - - template - state_view& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name(), user); - } - - template - state_view& set_usertype(Key&& key, usertype& user) { - global.set_usertype(std::forward(key), user); - return *this; - } - - template - state_view& new_usertype(const std::string& name, Args&&... args) { - global.new_usertype(name, std::forward(args)...); - return *this; - } - - template - state_view& new_usertype(const std::string& name, Args&&... args) { - global.new_usertype(name, std::forward(args)...); - return *this; - } - - template - state_view& new_usertype(const std::string& name, constructors ctor, Args&&... args) { - global.new_usertype(name, ctor, std::forward(args)...); - return *this; - } - - template - state_view& new_simple_usertype(const std::string& name, Args&&... args) { - global.new_simple_usertype(name, std::forward(args)...); - return *this; - } - - template - state_view& new_simple_usertype(const std::string& name, Args&&... args) { - global.new_simple_usertype(name, std::forward(args)...); - return *this; - } - - template - state_view& new_simple_usertype(const std::string& name, constructors ctor, Args&&... args) { - global.new_simple_usertype(name, ctor, std::forward(args)...); - return *this; - } - - template - simple_usertype create_simple_usertype(Args&&... args) { - return global.create_simple_usertype(std::forward(args)...); - } - - template - simple_usertype create_simple_usertype(Args&&... args) { - return global.create_simple_usertype(std::forward(args)...); - } - - template - simple_usertype create_simple_usertype(constructors ctor, Args&&... args) { - return global.create_simple_usertype(ctor, std::forward(args)...); - } - - template - state_view& new_enum(const std::string& name, Args&&... args) { - global.new_enum(name, std::forward(args)...); - return *this; - } - - template - void for_each(Fx&& fx) { - global.for_each(std::forward(fx)); - } - - template - proxy operator[](T&& key) { - return global[std::forward(key)]; - } - - template - proxy operator[](T&& key) const { - return global[std::forward(key)]; - } - - template - state_view& set_function(Key&& key, Args&&... args) { - global.set_function(std::forward(key), std::forward(args)...); - return *this; - } - - template - state_view& set_function(Key&& key, Args&&... args) { - global.set_function(std::forward(key), std::forward(args)...); - return *this; - } - - template - table create_table(Name&& name, int narr = 0, int nrec = 0) { - return global.create(std::forward(name), narr, nrec); - } - - template - table create_table(Name&& name, int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - return global.create(std::forward(name), narr, nrec, std::forward(key), std::forward(value), std::forward(args)...); - } - - template - table create_named_table(Name&& name, Args&&... args) { - table x = global.create_with(std::forward(args)...); - global.set(std::forward(name), x); - return x; - } - - table create_table(int narr = 0, int nrec = 0) { - return create_table(lua_state(), narr, nrec); - } - - template - table create_table(int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - return create_table(lua_state(), narr, nrec, std::forward(key), std::forward(value), std::forward(args)...); - } - - template - table create_table_with(Args&&... args) { - return create_table_with(lua_state(), std::forward(args)...); - } - - static inline table create_table(lua_State* L, int narr = 0, int nrec = 0) { - return global_table::create(L, narr, nrec); - } - - template - static inline table create_table(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) { - return global_table::create(L, narr, nrec, std::forward(key), std::forward(value), std::forward(args)...); - } - - template - static inline table create_table_with(lua_State* L, Args&&... args) { - return global_table::create_with(L, std::forward(args)...); - } - }; -} // sol - -// end of sol/state_view.hpp - -namespace sol { - inline int default_at_panic(lua_State* L) { -#ifdef SOL_NO_EXCEPTIONS - (void)L; - return -1; -#else - const char* message = lua_tostring(L, -1); - if (message) { - std::string err = message; - lua_settop(L, 0); - throw error(err); - } - lua_settop(L, 0); - throw error(std::string("An unexpected error occurred and forced the lua state to call atpanic")); -#endif - } - - inline int default_error_handler(lua_State*L) { - using namespace sol; - std::string msg = "An unknown error has triggered the default error handler"; - optional maybetopmsg = stack::check_get(L, 1); - if (maybetopmsg) { - const string_detail::string_shim& topmsg = maybetopmsg.value(); - msg.assign(topmsg.c_str(), topmsg.size()); - } - luaL_traceback(L, L, msg.c_str(), 1); - optional maybetraceback = stack::check_get(L, -1); - if (maybetraceback) { - const string_detail::string_shim& traceback = maybetraceback.value(); - msg.assign(traceback.c_str(), traceback.size()); - } - return stack::push(L, msg); - } - - class state : private std::unique_ptr, public state_view { - private: - typedef std::unique_ptr unique_base; - public: - state(lua_CFunction panic = default_at_panic) : unique_base(luaL_newstate(), lua_close), - state_view(unique_base::get()) { - set_panic(panic); - stack::luajit_exception_handler(unique_base::get()); - } - - state(lua_CFunction panic, lua_Alloc alfunc, void* alpointer = nullptr) : unique_base(lua_newstate(alfunc, alpointer), lua_close), - state_view(unique_base::get()) { - set_panic(panic); - sol::protected_function::set_default_handler(sol::object(lua_state(), in_place, default_error_handler)); - stack::luajit_exception_handler(unique_base::get()); - } - - state(const state&) = delete; - state(state&&) = default; - state& operator=(const state&) = delete; - state& operator=(state&& that) { - state_view::operator=(std::move(that)); - unique_base::operator=(std::move(that)); - return *this; - } - - using state_view::get; - - ~state() { - auto& handler = protected_function::get_default_handler(); - if (handler.lua_state() == this->lua_state()) { - protected_function::set_default_handler(reference()); - } - } - }; -} // sol - -// end of sol/state.hpp - -// beginning of sol/coroutine.hpp - -// beginning of sol/thread.hpp - -namespace sol { - struct lua_thread_state { - lua_State* L; - operator lua_State* () const { - return L; - } - lua_State* operator-> () const { - return L; - } - }; - - namespace stack { - - template <> - struct pusher { - int push(lua_State*, lua_thread_state lts) { - lua_pushthread(lts.L); - return 1; - } - }; - - template <> - struct getter { - lua_thread_state get(lua_State* L, int index, record& tracking) { - tracking.use(1); - lua_thread_state lts{ lua_tothread(L, index) }; - return lts; - } - }; - - template <> - struct check_getter { - template - optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - lua_thread_state lts{ lua_tothread(L, index) }; - if (lts.L == nullptr) { - handler(L, index, type::thread, type_of(L, index)); - return nullopt; - } - tracking.use(1); - return lts; - } - }; - - } - -#if SOL_LUA_VERSION < 502 - inline lua_State* main_thread(lua_State*, lua_State* backup_if_unsupported = nullptr) { - return backup_if_unsupported; - } -#else - inline lua_State* main_thread(lua_State* L, lua_State* = nullptr) { - lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); - lua_thread_state s = stack::pop(L); - return s.L; - } -#endif // Lua 5.2+ has the main thread getter - - class thread : public reference { - public: - thread() noexcept = default; - thread(const thread&) = default; - thread(thread&&) = default; - template , thread>>, std::is_base_of>> = meta::enabler> - thread(T&& r) : reference(std::forward(r)) {} - thread(const stack_reference& r) : thread(r.lua_state(), r.stack_index()) {}; - thread(stack_reference&& r) : thread(r.lua_state(), r.stack_index()) {}; - thread& operator=(const thread&) = default; - thread& operator=(thread&&) = default; - template >>, meta::neg>> = meta::enabler> - thread(lua_State* L, T&& r) : thread(L, sol::ref_index(r.registry_index())) {} - thread(lua_State* L, int index = -1) : reference(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - type_assert(L, index, type::thread); -#endif // Safety - } - thread(lua_State* L, ref_index index) : reference(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - type_assert(L, -1, type::thread); -#endif // Safety - } - thread(lua_State* L, lua_State* actualthread) : thread(L, lua_thread_state{ actualthread }) {} - thread(lua_State* L, sol::this_state actualthread) : thread(L, lua_thread_state{ actualthread.L }) {} - thread(lua_State* L, lua_thread_state actualthread) : reference(L, -stack::push(L, actualthread)) { -#ifdef SOL_CHECK_ARGUMENTS - type_assert(L, -1, type::thread); -#endif // Safety - lua_pop(L, 1); - } - - state_view state() const { - return state_view(this->thread_state()); - } - - bool is_main_thread() const { - int ismainthread = lua_pushthread(this->thread_state()); - lua_pop(this->thread_state(), 1); - return ismainthread == 1; - } - - lua_State* thread_state() const { - auto pp = stack::push_pop(*this); - lua_State* lthread = lua_tothread(lua_state(), -1); - return lthread; - } - - thread_status status() const { - lua_State* lthread = thread_state(); - thread_status lstat = static_cast(lua_status(lthread)); - if (lstat != thread_status::ok && lua_gettop(lthread) == 0) { - // No thing on the thread's stack means its dead - return thread_status::dead; - } - return lstat; - } - - thread create() { - return create(lua_state()); - } - - static thread create(lua_State* L) { - lua_newthread(L); - thread result(L); - lua_pop(L, 1); - return result; - } - }; -} // sol - -// end of sol/thread.hpp - -namespace sol { - class coroutine : public reference { - private: - call_status stats = call_status::yielded; - - void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) { -#if SOL_LUA_VERSION < 502 - stats = static_cast(lua_resume(lua_state(), static_cast(argcount))); -#else - stats = static_cast(lua_resume(lua_state(), nullptr, static_cast(argcount))); -#endif // Lua 5.1 compat - } - - template - auto invoke(types, std::index_sequence, std::ptrdiff_t n) { - luacall(n, sizeof...(Ret)); - return stack::pop>(lua_state()); - } - - template - Ret invoke(types, std::index_sequence, std::ptrdiff_t n) { - luacall(n, 1); - return stack::pop(lua_state()); - } - - template - void invoke(types, std::index_sequence, std::ptrdiff_t n) { - luacall(n, 0); - } - - protected_function_result invoke(types<>, std::index_sequence<>, std::ptrdiff_t n) { - int stacksize = lua_gettop(lua_state()); - int firstreturn = (std::max)(1, stacksize - static_cast(n)); - luacall(n, LUA_MULTRET); - int poststacksize = lua_gettop(lua_state()); - int returncount = poststacksize - (firstreturn - 1); - if (error()) { - return protected_function_result(lua_state(), lua_absindex(lua_state(), -1), 1, returncount, status()); - } - return protected_function_result(lua_state(), firstreturn, returncount, returncount, status()); - } - - public: - coroutine() noexcept = default; - coroutine(const coroutine&) noexcept = default; - coroutine(coroutine&&) noexcept = default; - coroutine& operator=(const coroutine&) noexcept = default; - coroutine& operator=(coroutine&&) noexcept = default; - template , coroutine>>, std::is_base_of>> = meta::enabler> - coroutine(T&& r) : reference(std::forward(r)) {} - coroutine(lua_nil_t r) : reference(r) {} - coroutine(const stack_reference& r) noexcept : coroutine(r.lua_state(), r.stack_index()) {} - coroutine(stack_reference&& r) noexcept : coroutine(r.lua_state(), r.stack_index()) {} - template >>, meta::neg>> = meta::enabler> - coroutine(lua_State* L, T&& r) : coroutine(L, sol::ref_index(r.registry_index())) {} - coroutine(lua_State* L, int index = -1) : reference(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - coroutine(lua_State* L, ref_index index) : reference(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, -1, type_panic); -#endif // Safety - } - - call_status status() const noexcept { - return stats; - } - - bool error() const noexcept { - call_status cs = status(); - return cs != call_status::ok && cs != call_status::yielded; - } - - bool runnable() const noexcept { - return valid() - && (status() == call_status::yielded); - } - - explicit operator bool() const noexcept { - return runnable(); - } - - template - protected_function_result operator()(Args&&... args) { - return call<>(std::forward(args)...); - } - - template - decltype(auto) operator()(types, Args&&... args) { - return call(std::forward(args)...); - } - - template - decltype(auto) call(Args&&... args) { - push(); - int pushcount = stack::multi_push(lua_state(), std::forward(args)...); - return invoke(types(), std::make_index_sequence(), pushcount); - } - }; -} // sol - -// end of sol/coroutine.hpp - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#elif defined _MSC_VER -#pragma warning( push ) -#endif // g++ - -#ifdef SOL_INSIDE_UNREAL -#ifdef SOL_INSIDE_UNREAL_REMOVED_CHECK -#if DO_CHECK -#define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } } -#else -#define check(expr) { CA_ASSUME(expr); } -#endif -#endif -#endif // Unreal Engine 4 Bullshit - -#endif // SOL_HPP -// end of sol.hpp - -#endif // SOL_SINGLE_INCLUDE_HPP diff --git a/src/deps/sol2-2.20.6/sol/sol.hpp b/src/deps/sol2-2.20.6/sol/sol.hpp new file mode 100644 index 0000000..d582bb8 --- /dev/null +++ b/src/deps/sol2-2.20.6/sol/sol.hpp @@ -0,0 +1,22180 @@ +// The MIT License (MIT) + +// Copyright (c) 2013-2018 Rapptz, ThePhD and contributors + +// 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. + +// This file was generated with a script. +// Generated 2018-11-28 08:50:22.534324 UTC +// This header was generated with sol v2.20.6 (revision 9b782ff) +// https://github.com/ThePhD/sol2 + +#ifndef SOL_SINGLE_INCLUDE_HPP +#define SOL_SINGLE_INCLUDE_HPP + +// beginning of sol.hpp + +#ifndef SOL_HPP +#define SOL_HPP + +#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) +#define SOL_INSIDE_UNREAL 1 +#endif // Unreal Engine 4 bullshit + +#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL +#ifdef check +#define SOL_INSIDE_UNREAL_REMOVED_CHECK 1 +#undef check +#endif +#endif // Unreal Engine 4 Bullshit + +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wconversion" +#if __GNUC__ > 6 +#pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif +#elif defined(__clang__) +#elif defined _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4324 ) // structure was padded due to alignment specifier +#pragma warning( disable : 4503 ) // decorated name horse shit +#pragma warning( disable : 4702 ) // unreachable code +#pragma warning( disable: 4127 ) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk +#pragma warning( disable: 4505 ) // some other nonsense warning +#endif // clang++ vs. g++ vs. VC++ + +// beginning of sol/forward.hpp + +// beginning of sol/feature_test.hpp + +#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) +#ifndef SOL_CXX17_FEATURES +#define SOL_CXX17_FEATURES 1 +#endif // C++17 features macro +#endif // C++17 features check + +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201403L)))) +#ifndef SOL_NOEXCEPT_FUNCTION_TYPE +#define SOL_NOEXCEPT_FUNCTION_TYPE 1 +#endif // noexcept is part of a function's type +#endif // compiler-specific checks +#if defined(__clang__) && defined(__APPLE__) +#if defined(__has_include) +#if __has_include() +#define SOL_STD_VARIANT 1 +#endif // has include nonsense +#endif // __has_include +#else +#define SOL_STD_VARIANT 1 +#endif // Clang screws up variant +#endif // C++17 only + +// beginning of sol/config.hpp + +#ifdef _MSC_VER + #if defined(_DEBUG) && !defined(NDEBUG) + + #ifndef SOL_IN_DEBUG_DETECTED + #define SOL_IN_DEBUG_DETECTED 1 + #endif + + #endif // VC++ Debug macros + + #ifndef _CPPUNWIND + #ifndef SOL_NO_EXCEPTIONS + #define SOL_NO_EXCEPTIONS 1 + #endif + #endif // Automatic Exceptions + + #ifndef _CPPRTTI + #ifndef SOL_NO_RTTI + #define SOL_NO_RTTI 1 + #endif + #endif // Automatic RTTI +#elif defined(__GNUC__) || defined(__clang__) + + #if !defined(NDEBUG) && !defined(__OPTIMIZE__) + + #ifndef SOL_IN_DEBUG_DETECTED + #define SOL_IN_DEBUG_DETECTED 1 + #endif + + #endif // Not Debug && g++ optimizer flag + + #ifndef __EXCEPTIONS + #ifndef SOL_NO_EXCEPTIONS + #define SOL_NO_EXCEPTIONS 1 + #endif + #endif // No Exceptions + + #ifndef __GXX_RTTI + #ifndef SOL_NO_RTII + #define SOL_NO_RTTI 1 + #endif + #endif // No RTTI + +#endif // vc++ || clang++/g++ + +#if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS + + // Checks low-level getter function + // (and thusly, affects nearly entire framework) + #if !defined(SOL_SAFE_GETTER) + #define SOL_SAFE_GETTER 1 + #endif + + // Checks access on usertype functions + // local my_obj = my_type.new() + // my_obj.my_member_function() + // -- bad syntax and crash + #if !defined(SOL_SAFE_USERTYPE) + #define SOL_SAFE_USERTYPE 1 + #endif + + // Checks sol::reference derived boundaries + // sol::function ref(L, 1); + // sol::userdata sref(L, 2); + #if !defined(SOL_SAFE_REFERENCES) + #define SOL_SAFE_REFERENCES 1 + #endif + + // Changes all typedefs of sol::function to point to the + // protected_function version, instead of unsafe_function + #if !defined(SOL_SAFE_FUNCTION) + #define SOL_SAFE_FUNCTION 1 + #endif + + // Checks function parameters and + // returns upon call into/from Lua + // local a = 1 + // local b = "woof" + // my_c_function(a, b) + #if !defined(SOL_SAFE_FUNCTION_CALLS) + #define SOL_SAFE_FUNCTION_CALLS 1 + #endif + + // Checks conversions + // int v = lua["bark"]; + // int v2 = my_sol_function(); + #if !defined(SOL_SAFE_PROXIES) + #define SOL_SAFE_PROXIES 1 + #endif + + // Check overflowing number conversions + // for things like 64 bit integers that don't fit in a typical lua_Number + // for Lua 5.1 and 5.2 + #if !defined(SOL_SAFE_NUMERICS) + #define SOL_SAFE_NUMERICS 1 + #endif + + // Turn off Number Precision Checks + // if this is defined, we do not do range + // checks on integers / unsigned integers that might + // be bigger than what Lua can represent + #if !defined(SOL_NO_CHECK_NUMBER_PRECISION) + // off by default + #define SOL_NO_CHECK_NUMBER_PRECISION 0 + #endif + +#endif // Turn on Safety for all if top-level macro is defined + +#if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED + + #if !defined(SOL_SAFE_REFERENCES) + // Ensure that references are forcefully type-checked upon construction + #define SOL_SAFE_REFERENCES 1 + #endif + + // Safe usertypes checks for errors such as + // obj = my_type.new() + // obj.f() -- note the '.' instead of ':' + // usertypes should be safe no matter what + #if !defined(SOL_SAFE_USERTYPE) + #define SOL_SAFE_USERTYPE 1 + #endif + + #if !defined(SOL_SAFE_FUNCTION_CALLS) + // Function calls from Lua should be automatically safe in debug mode + #define SOL_SAFE_FUNCTION_CALLS 1 + #endif + + // Print any exceptions / errors that occur + // in debug mode to the default error stream / console + #if !defined(SOL_PRINT_ERRORS) + #define SOL_PRINT_ERRORS 1 + #endif + +#endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar + +#if !defined(SOL_PRINT_ERRORS) +#define SOL_PRINT_ERRORS 0 +#endif + +#if !defined(SOL_DEFAULT_PASS_ON_ERROR) +#define SOL_DEFAULT_PASS_ON_ERROR 0 +#endif + +#if !defined(SOL_ENABLE_INTEROP) +#define SOL_ENABLE_INTEROP 0 +#endif + +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) +#if !defined(SOL_NO_NIL) +#define SOL_NO_NIL 1 +#endif +#endif // avoiding nil defines / keywords + +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST +#ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH +#define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1 +#endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH +#endif + +#ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE +#define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024 +#endif // Optimized conversion routines using a KB or so off the stack + +// end of sol/config.hpp + +// beginning of sol/config_setup.hpp + +// end of sol/config_setup.hpp + +// end of sol/feature_test.hpp + +namespace sol { + + template + class basic_reference; + using reference = basic_reference; + using main_reference = basic_reference; + class stack_reference; + + struct proxy_base_tag; + template + struct proxy_base; + template + struct proxy; + + template + class usertype; + template + class simple_usertype; + template + class basic_table_core; + template + using table_core = basic_table_core; + template + using main_table_core = basic_table_core; + template + using stack_table_core = basic_table_core; + template + using basic_table = basic_table_core; + typedef table_core table; + typedef table_core global_table; + typedef main_table_core main_table; + typedef main_table_core main_global_table; + typedef stack_table_core stack_table; + typedef stack_table_core stack_global_table; + template + struct basic_environment; + using environment = basic_environment; + using main_environment = basic_environment; + using stack_environment = basic_environment; + template + class basic_function; + template + class basic_protected_function; + using unsafe_function = basic_function; + using safe_function = basic_protected_function; + using main_unsafe_function = basic_function; + using main_safe_function = basic_protected_function; + using stack_unsafe_function = basic_function; + using stack_safe_function = basic_protected_function; + using stack_aligned_unsafe_function = basic_function; + using stack_aligned_safe_function = basic_protected_function; + using protected_function = safe_function; + using main_protected_function = main_safe_function; + using stack_protected_function = stack_safe_function; + using stack_aligned_protected_function = stack_aligned_safe_function; +#if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION + using function = protected_function; + using main_function = main_protected_function; + using stack_function = stack_protected_function; +#else + using function = unsafe_function; + using main_function = main_unsafe_function; + using stack_function = stack_unsafe_function; +#endif + using stack_aligned_function = stack_aligned_unsafe_function; + using stack_aligned_stack_handler_function = basic_protected_function; + + struct unsafe_function_result; + struct protected_function_result; + using safe_function_result = protected_function_result; +#if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION + using function_result = safe_function_result; +#else + using function_result = unsafe_function_result; +#endif + + template + class basic_object; + template + class basic_userdata; + template + class basic_lightuserdata; + template + class basic_coroutine; + template + class basic_thread; + + using object = basic_object; + using userdata = basic_userdata; + using lightuserdata = basic_lightuserdata; + using thread = basic_thread; + using coroutine = basic_coroutine; + using main_object = basic_object; + using main_userdata = basic_userdata; + using main_lightuserdata = basic_lightuserdata; + using main_coroutine = basic_coroutine; + using stack_object = basic_object; + using stack_userdata = basic_userdata; + using stack_lightuserdata = basic_lightuserdata; + using stack_thread = basic_thread; + using stack_coroutine = basic_coroutine; + + struct stack_proxy_base; + struct stack_proxy; + struct variadic_args; + struct variadic_results; + struct stack_count; + struct this_state; + struct this_main_state; + struct this_environment; + + template + struct as_table_t; + template + struct as_container_t; + template + struct nested; + template + struct light; + template + struct user; + template + struct as_args_t; + template + struct protect_t; + template + struct filter_wrapper; + + template + struct usertype_traits; + template + struct unique_usertype_traits; +} // namespace sol + +// end of sol/forward.hpp + +// beginning of sol/state.hpp + +// beginning of sol/state_view.hpp + +// beginning of sol/error.hpp + +#include +#include + +namespace sol { + namespace detail { + struct direct_error_tag {}; + const auto direct_error = direct_error_tag{}; + } // namespace detail + + class error : public std::runtime_error { + private: + // Because VC++ is upsetting, most of the time! + std::string w; + + public: + error(const std::string& str) + : error(detail::direct_error, "lua: error: " + str) { + } + error(std::string&& str) + : error(detail::direct_error, "lua: error: " + std::move(str)) { + } + error(detail::direct_error_tag, const std::string& str) + : std::runtime_error(""), w(str) { + } + error(detail::direct_error_tag, std::string&& str) + : std::runtime_error(""), w(std::move(str)) { + } + + error(const error& e) = default; + error(error&& e) = default; + error& operator=(const error& e) = default; + error& operator=(error&& e) = default; + + virtual const char* what() const noexcept override { + return w.c_str(); + } + }; + +} // namespace sol + +// end of sol/error.hpp + +// beginning of sol/table.hpp + +// beginning of sol/table_core.hpp + +// beginning of sol/proxy.hpp + +// beginning of sol/traits.hpp + +// beginning of sol/tuple.hpp + +#include +#include + +namespace sol { + namespace detail { + using swallow = std::initializer_list; + } // namespace detail + + template + struct types { + typedef std::make_index_sequence indices; + static constexpr std::size_t size() { + return sizeof...(Args); + } + }; + namespace meta { + namespace detail { + template + struct tuple_types_ { typedef types type; }; + + template + struct tuple_types_> { typedef types type; }; + } // namespace detail + + template + using unqualified = std::remove_cv>; + + template + using unqualified_t = typename unqualified::type; + + template + using tuple_types = typename detail::tuple_types_::type; + + template + struct pop_front_type; + + template + using pop_front_type_t = typename pop_front_type::type; + + template + struct pop_front_type> { + typedef void front_type; + typedef types type; + }; + + template + struct pop_front_type> { + typedef Arg front_type; + typedef types type; + }; + + template + using tuple_element = std::tuple_element>; + + template + using tuple_element_t = std::tuple_element_t>; + + template + using unqualified_tuple_element = unqualified>; + + template + using unqualified_tuple_element_t = unqualified_t>; + + } // namespace meta +} // namespace sol + +// end of sol/tuple.hpp + +// beginning of sol/bind_traits.hpp + +namespace sol { +namespace meta { + namespace meta_detail { + + template + struct check_deducible_signature { + struct nat {}; + template + static auto test(int) -> decltype(&G::operator(), void()); + template + static auto test(...) -> nat; + + using type = std::is_void(0))>; + }; + } // namespace meta_detail + + template + struct has_deducible_signature : meta_detail::check_deducible_signature::type {}; + + namespace meta_detail { + + template + struct void_tuple_element : meta::tuple_element {}; + + template + struct void_tuple_element> { typedef void type; }; + + template + using void_tuple_element_t = typename void_tuple_element::type; + + template + struct basic_traits { + private: + typedef std::conditional_t::value, int, T>& first_type; + + public: + static const bool is_noexcept = it_is_noexcept; + static const bool is_member_function = std::is_void::value; + static const bool has_c_var_arg = has_c_variadic; + static const std::size_t arity = sizeof...(Args); + static const std::size_t free_arity = sizeof...(Args) + static_cast(!std::is_void::value); + typedef types args_list; + typedef std::tuple args_tuple; + typedef T object_type; + typedef R return_type; + typedef tuple_types returns_list; + typedef R(function_type)(Args...); + typedef std::conditional_t::value, args_list, types> free_args_list; + typedef std::conditional_t::value, R(Args...), R(first_type, Args...)> free_function_type; + typedef std::conditional_t::value, R (*)(Args...), R (*)(first_type, Args...)> free_function_pointer_type; + typedef std::remove_pointer_t signature_type; + template + using arg_at = void_tuple_element_t; + }; + + template ::value> + struct fx_traits : basic_traits {}; + + // Free Functions + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...); + }; + + // Member Functions + /* C-Style Variadics */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...); + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile; + }; + + /* Member Function Qualifiers */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&; + }; + +#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) noexcept; + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) & noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) & noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) && noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) && noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; + }; + +#endif // noexcept is part of a function's type + +#if defined(_MSC_VER) && defined(_M_IX86) + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...); + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile; + }; + + /* Member Function Qualifiers */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&; + }; + +#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...) noexcept; + }; + + /* __stdcall cannot be applied to functions with varargs*/ + /*template + struct fx_traits<__stdcall R(Args..., ...) noexcept, false> : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) noexcept; + };*/ + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) & noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) & noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) && noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) && noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const&& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; + };*/ +#endif // noexcept is part of a function's type +#endif // __stdcall x86 VC++ bug + + template + struct fx_traits : fx_traits::function_type, false> {}; + + template ::value> + struct callable_traits : fx_traits> { + }; + + template + struct callable_traits { + typedef std::conditional_t::value, std::add_lvalue_reference_t, R> return_type; + typedef return_type Arg; + typedef T object_type; + using signature_type = R(T::*); + static const bool is_noexcept = false; + static const bool is_member_function = false; + static const std::size_t arity = 1; + static const std::size_t free_arity = 2; + typedef std::tuple args_tuple; + typedef types args_list; + typedef types free_args_list; + typedef meta::tuple_types returns_list; + typedef return_type(function_type)(T&, return_type); + typedef return_type(*function_pointer_type)(T&, Arg); + typedef return_type(*free_function_pointer_type)(T&, Arg); + template + using arg_at = void_tuple_element_t; + }; + + } // namespace meta_detail + + template + struct bind_traits : meta_detail::callable_traits {}; + + template + using function_args_t = typename bind_traits::args_list; + + template + using function_signature_t = typename bind_traits::signature_type; + + template + using function_return_t = typename bind_traits::return_type; +} +} // namespace sol::meta + +// end of sol/bind_traits.hpp + +// beginning of sol/string_view.hpp + +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#include +#endif // C++17 features +#include +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST +#include +#endif + +namespace sol { +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES + template > + using basic_string_view = std::basic_string_view; + typedef std::string_view string_view; + typedef std::wstring_view wstring_view; + typedef std::u16string_view u16string_view; + typedef std::u32string_view u32string_view; + typedef std::hash string_view_hash; +#else + template > + struct basic_string_view { + std::size_t s; + const Char* p; + + basic_string_view(const std::string& r) + : basic_string_view(r.data(), r.size()) { + } + basic_string_view(const Char* ptr) + : basic_string_view(ptr, Traits::length(ptr)) { + } + basic_string_view(const Char* ptr, std::size_t sz) + : s(sz), p(ptr) { + } + + static int compare(const Char* lhs_p, std::size_t lhs_sz, const Char* rhs_p, std::size_t rhs_sz) { + int result = Traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz); + if (result != 0) + return result; + if (lhs_sz < rhs_sz) + return -1; + if (lhs_sz > rhs_sz) + return 1; + return 0; + } + + const Char* begin() const { + return p; + } + + const Char* end() const { + return p + s; + } + + const Char* cbegin() const { + return p; + } + + const Char* cend() const { + return p + s; + } + + const Char* data() const { + return p; + } + + std::size_t size() const { + return s; + } + + std::size_t length() const { + return size(); + } + + operator std::basic_string() const { + return std::basic_string(data(), size()); + } + + bool operator==(const basic_string_view& r) const { + return compare(p, s, r.data(), r.size()) == 0; + } + + bool operator==(const Char* r) const { + return compare(r, Traits::length(r), p, s) == 0; + } + + bool operator==(const std::basic_string& r) const { + return compare(r.data(), r.size(), p, s) == 0; + } + + bool operator!=(const basic_string_view& r) const { + return !(*this == r); + } + + bool operator!=(const char* r) const { + return !(*this == r); + } + + bool operator!=(const std::basic_string& r) const { + return !(*this == r); + } + }; + + template > + struct basic_string_view_hash { + typedef basic_string_view argument_type; + typedef std::size_t result_type; + + template + result_type operator()(const std::basic_string& r) const { + return (*this)(argument_type(r.c_str(), r.size())); + } + + result_type operator()(const argument_type& r) const { +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST + return boost::hash_range(r.begin(), r.end()); +#else + // Modified, from libstdc++ + // An implementation attempt at Fowler No Voll, 1a. + // Supposedly, used in MSVC, + // GCC (libstdc++) uses MurmurHash of some sort for 64-bit though...? + // But, well. Can't win them all, right? + // This should normally only apply when NOT using boost, + // so this should almost never be tapped into... + std::size_t hash = 0; + const unsigned char* cptr = reinterpret_cast(r.data()); + for (std::size_t sz = r.size(); sz != 0; --sz) { + hash ^= static_cast(*cptr++); + hash *= static_cast(1099511628211ULL); + } + return hash; +#endif + } + }; +} // namespace sol + +namespace std { + template + struct hash< ::sol::basic_string_view > : ::sol::basic_string_view_hash {}; +} // namespace std + +namespace sol { + using string_view = basic_string_view; + using wstring_view = basic_string_view; + using u16string_view = basic_string_view; + using u32string_view = basic_string_view; + using string_view_hash = std::hash; +#endif // C++17 Support +} // namespace sol + +// end of sol/string_view.hpp + +#include +#include +#include +#include +#include +#include + +namespace sol { + template + using index_value = std::integral_constant; + + namespace meta { + typedef std::array sfinae_yes_t; + typedef std::array sfinae_no_t; + + template + struct identity { typedef T type; }; + + template + using identity_t = typename identity::type; + + template + struct is_tuple : std::false_type {}; + + template + struct is_tuple> : std::true_type {}; + + template + struct is_builtin_type : std::integral_constant::value || std::is_pointer::value || std::is_array::value> {}; + + template + struct unwrapped { + typedef T type; + }; + + template + struct unwrapped> { + typedef T type; + }; + + template + using unwrapped_t = typename unwrapped::type; + + template + struct unwrap_unqualified : unwrapped> {}; + + template + using unwrap_unqualified_t = typename unwrap_unqualified::type; + + template + struct remove_member_pointer; + + template + struct remove_member_pointer { + typedef R type; + }; + + template + struct remove_member_pointer { + typedef R type; + }; + + template + using remove_member_pointer_t = remove_member_pointer; + + namespace meta_detail { + template class Templ> + struct is_specialization_of : std::false_type {}; + template class Templ> + struct is_specialization_of, Templ> : std::true_type {}; + } + + template class Templ> + using is_specialization_of = meta_detail::is_specialization_of, Templ>; + + template + struct all_same : std::true_type {}; + + template + struct all_same : std::integral_constant::value && all_same::value> {}; + + template + struct any_same : std::false_type {}; + + template + struct any_same : std::integral_constant::value || any_same::value> {}; + + template + using boolean = std::integral_constant; + + template + using invoke_t = typename T::type; + + template + using invoke_b = boolean; + + template + using neg = boolean; + + template + using condition = std::conditional_t; + + template + struct all : boolean {}; + + template + struct all : condition, boolean> {}; + + template + struct any : boolean {}; + + template + struct any : condition, any> {}; + + enum class enable_t { + _ + }; + + constexpr const auto enabler = enable_t::_; + + template + using disable_if_t = std::enable_if_t; + + template + using enable = std::enable_if_t::value, enable_t>; + + template + using disable = std::enable_if_t>::value, enable_t>; + + template + using enable_any = std::enable_if_t::value, enable_t>; + + template + using disable_any = std::enable_if_t>::value, enable_t>; + + template + struct find_in_pack_v : boolean {}; + + template + struct find_in_pack_v : any, find_in_pack_v> {}; + + namespace meta_detail { + template + struct index_in_pack : std::integral_constant {}; + + template + struct index_in_pack : std::conditional_t::value, std::integral_constant, index_in_pack> {}; + } // namespace meta_detail + + template + struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> {}; + + template + struct index_in : meta_detail::index_in_pack<0, T, List> {}; + + template + struct index_in> : meta_detail::index_in_pack<0, T, Args...> {}; + + template + struct at_in_pack {}; + + template + using at_in_pack_t = typename at_in_pack::type; + + template + struct at_in_pack : std::conditional> {}; + + template + struct at_in_pack<0, Arg, Args...> { typedef Arg type; }; + + namespace meta_detail { + template class Pred, typename... Ts> + struct count_for_pack : std::integral_constant {}; + template class Pred, typename T, typename... Ts> + struct count_for_pack : std::conditional_t < sizeof...(Ts) + == 0 + || Limit<2, + std::integral_constant(Limit != 0 && Pred::value)>, + count_for_pack(Pred::value), Pred, Ts...>> {}; + template class Pred, typename... Ts> + struct count_2_for_pack : std::integral_constant {}; + template class Pred, typename T, typename U, typename... Ts> + struct count_2_for_pack : std::conditional_t(Pred::value)>, + count_2_for_pack(Pred::value), Pred, Ts...>> {}; + } // namespace meta_detail + + template