Bugfix #1542466 added code to allow mapping Lua nil's <-> C/C++ NULL's
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9256 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ebeee6b93b
commit
a8451e7c69
4 changed files with 83 additions and 8 deletions
|
|
@ -96,7 +96,15 @@
|
|||
%{ lua_pushfstring(L,"%c",*$1); SWIG_arg++;%}
|
||||
|
||||
// pointers and references
|
||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE*,SWIGTYPE&,SWIGTYPE[]
|
||||
// under SWIG rules, it is ok, to have a pass in a lua nil,
|
||||
// it should be converted to a SWIG NULL.
|
||||
// This will only be allowed for pointers & arrays, not refs or by value
|
||||
// the checkfn lua_isuserdata will only work for userdata
|
||||
// the checkfn SWIG_isptrtype will work for both userdata and nil's
|
||||
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[]
|
||||
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
||||
|
||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&
|
||||
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
||||
|
||||
%typemap(out) SWIGTYPE*,SWIGTYPE&
|
||||
|
|
@ -138,9 +146,13 @@
|
|||
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)
|
||||
but if its an output, then it should be wrappered like any other SWIG object (using default typemap)
|
||||
*/
|
||||
%typemap(in,checkfn="lua_isuserdata") void*
|
||||
%{$1=((swig_lua_userdata*)(lua_touserdata(L,$input)))->ptr;%}
|
||||
//%typemap(in,checkfn="lua_isuserdata") void*
|
||||
//%typemap(in,checkfn="SWIG_isptrtype") void*
|
||||
//%{$1=((swig_lua_userdata*)(lua_touserdata(L,$input)))->ptr;%}
|
||||
|
||||
%typemap(in,checkfn="SWIG_isptrtype") void*
|
||||
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,0,0,$argnum,"$symname");%}
|
||||
//%{SWIG_ConvertPtr(L,$input, (void **) &ptr, 0, 0)); %}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* constants typemaps
|
||||
|
|
@ -206,7 +218,16 @@ parmeters match which function
|
|||
$1 = lua_isstring(L,$input);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE, SWIGTYPE & {
|
||||
void *ptr;
|
||||
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $1_descriptor, 0)) {
|
||||
$1 = 0;
|
||||
|
|
@ -217,7 +238,7 @@ parmeters match which function
|
|||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, 0, 0)) {
|
||||
if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, 0, 0)) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
|
|
|
|||
|
|
@ -109,6 +109,9 @@ typedef struct {
|
|||
lua_pushcfunction(L, f), \
|
||||
lua_rawset(L,-3))
|
||||
|
||||
/* special helper for allowing 'nil' for usertypes */
|
||||
#define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* global variable support code: modules
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -507,10 +510,16 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type
|
|||
{
|
||||
swig_lua_userdata* usr;
|
||||
swig_cast_info *cast;
|
||||
if (lua_isnil(L,index)){*ptr=0; return 0;} /* special case: lua nil => NULL pointer */
|
||||
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
|
||||
if (usr)
|
||||
{
|
||||
cast=SWIG_TypeCheckStruct(usr->type,type);
|
||||
if (!type) /* special cast void*, no casting fn */
|
||||
{
|
||||
*ptr=usr->ptr;
|
||||
return 0; /* ok */
|
||||
}
|
||||
cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
|
||||
if (cast)
|
||||
{
|
||||
*ptr=SWIG_TypeCast(cast,usr->ptr);
|
||||
|
|
@ -553,8 +562,9 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
|
|||
return 0; /* nil reply */
|
||||
usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
||||
usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
|
||||
result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type);
|
||||
lua_pushboolean(L,result);
|
||||
/*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
|
||||
result=(usr1->ptr==usr2->ptr);
|
||||
lua_pushboolean(L,result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue