[Lua] Added contract support for requiring that unsigned numbers are >=0
Rewrote much of Examples/Lua/embed3. Added a lot of to the Lua documentation. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11061 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c07efac296
commit
e604e46b17
4 changed files with 309 additions and 27 deletions
|
|
@ -20,11 +20,15 @@
|
|||
to reflect the number of values returned (normally SWIG_arg++; will do)
|
||||
*/
|
||||
// numbers
|
||||
%typemap(in,checkfn="lua_isnumber") int,short,long,
|
||||
unsigned int,unsigned short,unsigned long,
|
||||
signed char,unsigned char,
|
||||
float,double
|
||||
%typemap(in,checkfn="lua_isnumber") int, short, long,
|
||||
signed char, float, double
|
||||
%{$1 = ($type)lua_tonumber(L, $input);%}
|
||||
|
||||
// additional check for unsigned numbers, to not permit negative input
|
||||
%typemap(in,checkfn="lua_isnumber") unsigned int,
|
||||
unsigned short, unsigned long, unsigned char
|
||||
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
|
||||
$1 = ($type)lua_tonumber(L, $input);%}
|
||||
|
||||
%typemap(out) int,short,long,
|
||||
unsigned int,unsigned short,unsigned long,
|
||||
|
|
@ -41,15 +45,20 @@
|
|||
%typemap(in,checkfn="lua_isnumber") const int&($basetype temp)
|
||||
%{ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%}
|
||||
|
||||
%typemap(out) const int&
|
||||
%typemap(in,checkfn="lua_isnumber") const unsigned int&($basetype temp)
|
||||
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
|
||||
temp=($basetype)lua_tonumber(L,$input); $1=&temp;%}
|
||||
|
||||
%typemap(out) const int&, const unsigned int&
|
||||
%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%}
|
||||
|
||||
// for the other numbers we can just use an apply statement to cover them
|
||||
%apply const int & {const short&,const long&,
|
||||
const unsigned int&,const unsigned short&,const unsigned long&,
|
||||
const signed char&,const unsigned char&,
|
||||
%apply const int & {const short&,const long&,const signed char&,
|
||||
const float&,const double&};
|
||||
|
||||
%apply const unsigned int & {const unsigned short&,const unsigned long&,
|
||||
const unsigned char&};
|
||||
|
||||
/* enums have to be handled slightly differently
|
||||
VC++ .net will not allow a cast from lua_Number(double) to enum directly.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue