[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:
Mark Gossage 2007-07-05 01:31:51 +00:00
commit c3ec8fdce3
8 changed files with 58 additions and 14 deletions

View file

@ -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
* ----------------------------------------------------------------------------- */