added correct void* support
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8810 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
aabec2c542
commit
ebbae30d72
4 changed files with 106 additions and 2 deletions
|
|
@ -4,4 +4,6 @@ Version 1.3.29 (In progress)
|
||||||
02/13/2006: mgossage
|
02/13/2006: mgossage
|
||||||
[Documents] updated the extending documents to give a skeleton swigging code
|
[Documents] updated the extending documents to give a skeleton swigging code
|
||||||
with a few typemaps.
|
with a few typemaps.
|
||||||
|
[Lua] added an extra typemap for void* [in], so a function which requires a void*
|
||||||
|
can take any kind of pointer
|
||||||
|
|
||||||
|
|
|
||||||
95
Lib/lua/_std_common.i
Normal file
95
Lib/lua/_std_common.i
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
/***********************************************************************
|
||||||
|
* _std_stl.i
|
||||||
|
*
|
||||||
|
* std::helpers for LUA
|
||||||
|
*
|
||||||
|
* Author : Mark Gossage (mark@gossage.cjb.net)
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
%include <std_except.i> // the general exepctions
|
||||||
|
|
||||||
|
/*
|
||||||
|
The basic idea here, is instead of trying to feed SWIG all the
|
||||||
|
horribly templated STL code, to give it a neatened version.
|
||||||
|
|
||||||
|
These %defines cover some of the more common methods
|
||||||
|
so the class declarations become just a set of %defines
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* #define for basic container features
|
||||||
|
note: I allow front(), back() & pop_back() to throw execptions
|
||||||
|
upon empty containers, rather than coredump
|
||||||
|
(as we have'nt defined the methods, we can use %extend to add with
|
||||||
|
new features)
|
||||||
|
|
||||||
|
*/
|
||||||
|
%define %STD_CONTAINER_METHODS(CLASS,T)
|
||||||
|
public:
|
||||||
|
CLASS();
|
||||||
|
CLASS(const CLASS&);
|
||||||
|
unsigned int size() const;
|
||||||
|
unsigned int max_size() const;
|
||||||
|
bool empty() const;
|
||||||
|
void clear();
|
||||||
|
%extend { // the extra stuff which must be checked
|
||||||
|
T front()const throw (std::out_of_range){ // only read front & back
|
||||||
|
if (self->empty())
|
||||||
|
throw std::out_of_range("in "#CLASS"::front()");
|
||||||
|
return self->front();
|
||||||
|
}
|
||||||
|
T back()const throw (std::out_of_range){ // not write to them
|
||||||
|
if (self->empty())
|
||||||
|
throw std::out_of_range("in "#CLASS"::back()");
|
||||||
|
return self->back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
/* push/pop for front/back
|
||||||
|
also note: front & back are read only methods, not used for writing
|
||||||
|
*/
|
||||||
|
%define %STD_FRONT_ACCESS_METHODS(CLASS,T)
|
||||||
|
public:
|
||||||
|
void push_front(const T& val);
|
||||||
|
%extend { // must check this
|
||||||
|
void pop_front() throw (std::out_of_range){
|
||||||
|
if (self->empty())
|
||||||
|
throw std::out_of_range("in "#CLASS"::pop_front()");
|
||||||
|
self->pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%define %STD_BACK_ACCESS_METHODS(CLASS,T)
|
||||||
|
public:
|
||||||
|
void push_back(const T& val);
|
||||||
|
%extend { // must check this
|
||||||
|
void pop_back() throw (std::out_of_range){
|
||||||
|
if (self->empty())
|
||||||
|
throw std::out_of_range("in "#CLASS"::pop_back()");
|
||||||
|
self->pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
/*
|
||||||
|
Random access methods
|
||||||
|
*/
|
||||||
|
%define %STD_RANDOM_ACCESS_METHODS(CLASS,T)
|
||||||
|
%extend // this is a extra bit of SWIG code
|
||||||
|
{
|
||||||
|
// [] is replaced by __getitem__ & __setitem__
|
||||||
|
// simply throws a string, which causes a lua error
|
||||||
|
T __getitem__(unsigned int idx) throw (std::out_of_range){
|
||||||
|
if (idx>=self->size())
|
||||||
|
throw std::out_of_range("in "#CLASS"::__getitem__()");
|
||||||
|
return (*self)[idx];
|
||||||
|
}
|
||||||
|
void __setitem__(unsigned int idx,const T& val) throw (std::out_of_range){
|
||||||
|
if (idx>=self->size())
|
||||||
|
throw std::out_of_range("in "#CLASS"::__setitem__()");
|
||||||
|
(*self)[idx]=val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
%enddef
|
||||||
|
|
@ -89,7 +89,6 @@
|
||||||
%typemap(out) const char&
|
%typemap(out) const char&
|
||||||
%{ lua_pushfstring(L,"%c",*$1); SWIG_arg++;%}
|
%{ lua_pushfstring(L,"%c",*$1); SWIG_arg++;%}
|
||||||
|
|
||||||
|
|
||||||
// pointers and references
|
// pointers and references
|
||||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE*,SWIGTYPE&,SWIGTYPE[]
|
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE*,SWIGTYPE&,SWIGTYPE[]
|
||||||
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,$descriptor,0,$argnum,"$symname");%}
|
||||||
|
|
@ -129,6 +128,13 @@
|
||||||
// void (must be empty without the SWIG_arg++)
|
// void (must be empty without the SWIG_arg++)
|
||||||
%typemap(out) void "";
|
%typemap(out) void "";
|
||||||
|
|
||||||
|
/* void* is a special case
|
||||||
|
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;%}
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* constants typemaps
|
* constants typemaps
|
||||||
|
|
@ -253,6 +259,7 @@ SWIG_NUMBER_BY_CONST_REF(float);
|
||||||
SWIG_NUMBER_BY_CONST_REF(double);
|
SWIG_NUMBER_BY_CONST_REF(double);
|
||||||
SWIG_NUMBER_BY_CONST_REF(enum SWIGTYPE);
|
SWIG_NUMBER_BY_CONST_REF(enum SWIGTYPE);
|
||||||
|
|
||||||
|
|
||||||
// Also needed for object ptrs by const ref
|
// Also needed for object ptrs by const ref
|
||||||
// eg const A* ref_pointer(A* const& a);
|
// eg const A* ref_pointer(A* const& a);
|
||||||
// found in mixed_types.i
|
// found in mixed_types.i
|
||||||
|
|
|
||||||
|
|
@ -524,7 +524,7 @@ SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *typ
|
||||||
void* result;
|
void* result;
|
||||||
if (SWIG_ConvertPtr(L,index,&result,type,flags)){
|
if (SWIG_ConvertPtr(L,index,&result,type,flags)){
|
||||||
lua_pushfstring(L,"Error in %s, expected a %s at argument number %d\n",
|
lua_pushfstring(L,"Error in %s, expected a %s at argument number %d\n",
|
||||||
func_name,type->str?type->str:"void*",argnum);
|
func_name,(type && type->str)?type->str:"void*",argnum);
|
||||||
lua_error(L);
|
lua_error(L);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue