[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
|
|
@ -1,6 +1,12 @@
|
|||
Version 1.3.32 (in progress)
|
||||
============================
|
||||
|
||||
07/05/2007: mgossage
|
||||
[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.
|
||||
|
||||
07/03/2007: wsfulton
|
||||
[C#] Fix directors for some overloaded methods where the imtype resulted in identical
|
||||
methods being generated in the C# director class, eg void foo(int *) and void foo(double *)
|
||||
|
|
|
|||
|
|
@ -399,7 +399,7 @@ Unlike many scripting languages, Lua has had support for pointers to C/C++ objec
|
|||
> print(f)
|
||||
userdata: 003FDA80
|
||||
> print(swig_type(f))
|
||||
_p_FILE -- its a FILE*
|
||||
FILE * -- its a FILE*
|
||||
</pre></div>
|
||||
<p>
|
||||
Lua enforces the integrity of its userdata, so it is virtually impossible to corrupt the data. But as the user of the pointer, you are responsible for freeing it, or closing any resources associated with it (just as you would in a C program). This does not apply so strictly to classes & structs (see below). One final note: if a function returns a NULL pointer, this is not encoded as a userdata, but as a Lua nil.
|
||||
|
|
@ -1087,7 +1087,7 @@ __index function: 003FB698
|
|||
.fn table: 003FB528
|
||||
</pre></div>
|
||||
<p>
|
||||
The '.type' attribute is the string which is returned from a call to swig_type(). The '.get' and '.set' tables work in a similar manner to the modules, the main difference is the '.fn' table which also holds all the member functions. (The '__gc' function is the classes destructor function)
|
||||
The '.type' attribute is the name of the class. The '.get' and '.set' tables work in a similar manner to the modules, the main difference is the '.fn' table which also holds all the member functions. (The '__gc' function is the classes destructor function)
|
||||
</p>
|
||||
<p>
|
||||
The Lua equivalent of the code for enabling functions looks a little like this
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable
|
|||
|
||||
-- helper to check type
|
||||
function is_std_string(s)
|
||||
return type(s)=='userdata' and swig_type(s)=='_p_std__string'
|
||||
return type(s)=='userdata' and swig_type(s)=='std::string *'
|
||||
end
|
||||
|
||||
-- std::string by value is just a Lua string
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ for i=0,3 do
|
|||
end
|
||||
|
||||
for i=0,3 do
|
||||
assert( swig_type(sv[i]) =='_p_Struct' and sv[i].num==i)
|
||||
assert( swig_type(sv[i]) =='Struct *' and sv[i].num==i)
|
||||
end
|
||||
|
||||
-- range checking
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ NEW LANGUAGE NOTE:END ************************************************/
|
|||
} else {
|
||||
Printf(argument_check, "if(lua_gettop(L)>=%s && !%s(L,%s))", source, checkfn, source);
|
||||
}
|
||||
Printf(argument_check, " SWIG_fail_arg(%s);\n", source);
|
||||
Printf(argument_check, " SWIG_fail_arg(\"%s\",%s,\"%s\");\n", name, source, SwigType_str(pt, 0));
|
||||
}
|
||||
/* NEW LANGUAGE NOTE:***********************************************
|
||||
lua states the number of arguments passed to a function using the fn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue