[lua] Fix a bug in SWIG_ALLOC_ARRAY()
improved the error messages for incorrect arguments. Changed the output of swig_type() to use the human readable form of the type, rather than the raw swig type. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9863 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d269f9cd16
commit
c3ec8fdce3
8 changed files with 58 additions and 14 deletions
|
|
@ -106,11 +106,13 @@ typedef struct {
|
|||
|
||||
/* helper #defines */
|
||||
#define SWIG_fail {goto fail;}
|
||||
#define SWIG_fail_arg(I) {lua_pushfstring(L,"argument %d incorrect/missing",I);goto fail;}
|
||||
#define SWIG_fail_ptr(func_name,argnum,type) \
|
||||
{lua_pushfstring(L,"Error in %s, expected a %s at argument number %d\n",\
|
||||
func_name,(type && type->str)?type->str:"void*",argnum);\
|
||||
#define SWIG_fail_arg(func_name,argnum,type) \
|
||||
{lua_pushfstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\
|
||||
func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
|
||||
goto fail;}
|
||||
#define SWIG_fail_ptr(func_name,argnum,type) \
|
||||
SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*")
|
||||
|
||||
|
||||
#define SWIG_Lua_get_table(L,n) \
|
||||
(lua_pushstring(L, n), lua_rawget(L,-2))
|
||||
|
|
@ -639,14 +641,30 @@ SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t
|
|||
return SWIG_ERROR; /* error */
|
||||
}
|
||||
|
||||
/* a function to get the typestring of a piece of data */
|
||||
SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
|
||||
{
|
||||
swig_lua_userdata* usr;
|
||||
if (lua_isuserdata(L,tp))
|
||||
{
|
||||
usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
||||
if (usr && usr->type && usr->type->str)
|
||||
return usr->type->str;
|
||||
return "userdata (unknown type)";
|
||||
}
|
||||
return lua_typename(L,lua_type(L,tp));
|
||||
}
|
||||
|
||||
/* lua callable function to get the userdata's type */
|
||||
SWIGRUNTIME int SWIG_Lua_type(lua_State* L)
|
||||
{
|
||||
swig_lua_userdata* usr;
|
||||
/* swig_lua_userdata* usr;
|
||||
if (!lua_isuserdata(L,1)) /* just in case */
|
||||
return 0; /* nil reply */
|
||||
usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
||||
lua_pushstring(L,usr->type->name);
|
||||
/* return 0; /* nil reply */
|
||||
/*usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
|
||||
/*lua_pushstring(L,usr->type->name);
|
||||
return 1;*/
|
||||
lua_pushstring(L,SWIG_Lua_typename(L,1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -668,6 +686,8 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* global variable support code: class/struct typemap functions
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -348,3 +348,21 @@ $1=&temp;%}
|
|||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Specials
|
||||
* ----------------------------------------------------------------------------- */
|
||||
// swig::LANGUAGE_OBJ was added to allow containers of native objects
|
||||
// however its rather difficult to do this in lua, as you cannot hold pointers
|
||||
// to native objects (they are held in the interpreter)
|
||||
// therefore for now: just ignoring this feature
|
||||
#ifdef __cplusplus
|
||||
%ignore swig::LANGUAGE_OBJ;
|
||||
|
||||
%inline %{
|
||||
namespace swig {
|
||||
typedef struct{} LANGUAGE_OBJ;
|
||||
//typedef void* LANGUAGE_OBJ;
|
||||
}
|
||||
%}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
|
@ -175,7 +175,7 @@ int SWIG_read_NAME_num_array(lua_State* L,int index,TYPE *array,int size);
|
|||
%{
|
||||
|
||||
#ifdef __cplusplus /* generic alloc/dealloc fns*/
|
||||
#define SWIG_ALLOC_ARRAY(TYPE,LEN) new (TYPE)[LEN]
|
||||
#define SWIG_ALLOC_ARRAY(TYPE,LEN) new TYPE[LEN]
|
||||
#define SWIG_FREE_ARRAY(PTR) if(PTR){delete[] PTR;}
|
||||
#else
|
||||
#define SWIG_ALLOC_ARRAY(TYPE,LEN) (TYPE *)malloc(LEN*sizeof(TYPE))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue