From 341a5366ddbbd2bc5747bdeb4c19b9e4ab3bb559 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 24 Jan 2013 19:53:13 +0000 Subject: [PATCH] Add rvalue reference typemaps --- Lib/lua/lua.swg | 2 +- Lib/lua/luatypemaps.swg | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index a15f14148..f425f16a1 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -40,7 +40,7 @@ %typemap(consttab) long long, unsigned long long { SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0} -%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor} // member function pointers diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 13cd66f4c..4852c0e32 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -68,8 +68,12 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // and const refs %typemap(in,checkfn="lua_isnumber") const enum SWIGTYPE &($basetype temp) %{ temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%} +%typemap(in,checkfn="lua_isnumber") const enum SWIGTYPE &&($basetype temp) +%{ temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const enum SWIGTYPE & %{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} +%typemap(out) const enum SWIGTYPE && +%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} // boolean (which is a special type in lua) @@ -147,9 +151,18 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { } %} +%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&& +%{ + if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){ + SWIG_fail_ptr("$symname",$argnum,$descriptor); + } +%} + // out is simple %typemap(out) SWIGTYPE*,SWIGTYPE& %{SWIG_NewPointerObj(L,$1,$descriptor,$owner); SWIG_arg++; %} +%typemap(out) SWIGTYPE*,SWIGTYPE&& +%{SWIG_NewPointerObj(L,$1,$descriptor,$owner); SWIG_arg++; %} // dynamic casts // this uses the SWIG_TypeDynamicCast() which relies on RTTI to find out what the pointer really is @@ -284,7 +297,7 @@ parmeters match which function const unsigned int &, const unsigned short &, const unsigned long &, const signed char&, const unsigned char&, const long long &, const unsigned long long &, - enum SWIGTYPE, const enum SWIGTYPE&, + enum SWIGTYPE, const enum SWIGTYPE&, const enum SWIGTYPE &&, float, double, const float &, const double& { $1 = lua_isnumber(L,$input); @@ -323,6 +336,15 @@ parmeters match which function } } +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && { + void *ptr; + if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) { + $1 = 0; + } else { + $1 = 1; + } +} + %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { void *ptr; if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $&1_descriptor, 0)) { @@ -360,6 +382,7 @@ parmeters match which function // Array reference typemaps %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } /* const pointers */ %apply SWIGTYPE * { SWIGTYPE *const }