[lua] Added a typemap DISOWN for SWIGTYPE* and SWIGTYPE[], and support for %delobject feature.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10326 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2008-03-27 01:58:30 +00:00
commit 11647d87e8
14 changed files with 377 additions and 19 deletions

View file

@ -600,11 +600,15 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{
if (!type) /* special cast void*, no casting fn */
{
*ptr=usr->ptr;
return SWIG_OK; /* ok */
}
if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
{
usr->own=0;
}
if (!type) /* special cast void*, no casting fn */
{
*ptr=usr->ptr;
return SWIG_OK; /* ok */
}
cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
if (cast)
{

View file

@ -120,14 +120,14 @@
// the checkfn SWIG_isptrtype will work for both userdata and nil's
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[]
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,0))){
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
}
%}
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,0))){
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
}
%}
@ -165,6 +165,17 @@
%{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname");
$1=&temp;%}
// DISOWN-ing typemaps
// if you have an object pointer which must be disowned, use this typemap
// eg. for void destroy_foo(Foo* toDie);
// use %apply SWIGTYPE* DISOWN {Foo* toDie};
// you could just use %delobject, but this is more flexible
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE* DISOWN,SWIGTYPE DISOWN[]
%{ if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,SWIG_POINTER_DISOWN))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
}
%}
// Primitive types--return by value
// must make a new object, copy the data & return the new object