bugfix #1356577, changed double=>lua_number in a few places.
added the std::pair wrapping git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8672 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
285aeff366
commit
df022e7354
6 changed files with 103 additions and 12 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
Version 1.3.28 (unreleased).
|
Version 1.3.28 (unreleased).
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
02/02/2006: mgossage
|
||||||
|
bugfix #1356577, changed double=>lua_number in a few places.
|
||||||
|
added the std::pair wrapping
|
||||||
|
|
||||||
01/30/2006: wsfulton
|
01/30/2006: wsfulton
|
||||||
std::string and std::wstring member variables and global variables now use
|
std::string and std::wstring member variables and global variables now use
|
||||||
%naturalvar by default, meaning they will now be wrapped as expected in all languages.
|
%naturalvar by default, meaning they will now be wrapped as expected in all languages.
|
||||||
|
|
|
||||||
34
SWIG/Examples/test-suite/lua/li_std_pair_runme.lua
Normal file
34
SWIG/Examples/test-suite/lua/li_std_pair_runme.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
require("import") -- the import fn
|
||||||
|
import("li_std_pair") -- import code
|
||||||
|
|
||||||
|
for k,v in pairs(li_std_pair) do _G[k]=v end -- move to global
|
||||||
|
|
||||||
|
intPair = makeIntPair(7, 6)
|
||||||
|
assert(intPair.first==7 and intPair.second==6)
|
||||||
|
|
||||||
|
intPairPtr = makeIntPairPtr(7, 6)
|
||||||
|
assert(intPairPtr.first==7 and intPairPtr.second==6)
|
||||||
|
|
||||||
|
intPairRef = makeIntPairRef(7, 6)
|
||||||
|
assert(intPairRef.first == 7 and intPairRef.second == 6)
|
||||||
|
|
||||||
|
intPairConstRef = makeIntPairConstRef(7, 6)
|
||||||
|
assert(intPairConstRef.first == 7 and intPairConstRef.second == 6)
|
||||||
|
|
||||||
|
-- call fns
|
||||||
|
assert(product1(intPair) == 42)
|
||||||
|
assert(product2(intPair) == 42)
|
||||||
|
assert(product3(intPair) == 42)
|
||||||
|
|
||||||
|
-- also use the pointer version
|
||||||
|
assert(product1(intPairPtr) == 42)
|
||||||
|
assert(product2(intPairPtr) == 42)
|
||||||
|
assert(product3(intPairPtr) == 42)
|
||||||
|
|
||||||
|
-- or the other types
|
||||||
|
assert(product1(intPairRef) == 42)
|
||||||
|
assert(product2(intPairRef) == 42)
|
||||||
|
assert(product3(intPairRef) == 42)
|
||||||
|
assert(product1(intPairConstRef) == 42)
|
||||||
|
assert(product2(intPairConstRef) == 42)
|
||||||
|
assert(product3(intPairConstRef) == 42)
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
unsigned int,unsigned short,unsigned long,
|
unsigned int,unsigned short,unsigned long,
|
||||||
signed char,unsigned char,
|
signed char,unsigned char,
|
||||||
float,double
|
float,double
|
||||||
%{ lua_pushnumber(L, (double) $1); SWIG_arg++;%}
|
%{ lua_pushnumber(L, (lua_Number) $1); SWIG_arg++;%}
|
||||||
|
|
||||||
/* enums have to be handled slightly differently
|
/* enums have to be handled slightly differently
|
||||||
VC++ .net will not allow a cast from double to enum directly
|
VC++ .net will not allow a cast from double to enum directly
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
%{$1 = ($type)(int)lua_tonumber(L, $input);%}
|
%{$1 = ($type)(int)lua_tonumber(L, $input);%}
|
||||||
|
|
||||||
%typemap(out) enum SWIGTYPE
|
%typemap(out) enum SWIGTYPE
|
||||||
%{ lua_pushnumber(L, (double)(int)($1)); SWIG_arg++;%}
|
%{ lua_pushnumber(L, (lua_Number)(int)($1)); SWIG_arg++;%}
|
||||||
|
|
||||||
// boolean (which is a special type in lua)
|
// boolean (which is a special type in lua)
|
||||||
// note: 1 & 0 are not booleans in lua, only true & false
|
// note: 1 & 0 are not booleans in lua, only true & false
|
||||||
|
|
@ -234,7 +234,7 @@ parmeters match which function
|
||||||
%typemap(in,checkfn="lua_isnumber") const TYPE &($basetype temp)
|
%typemap(in,checkfn="lua_isnumber") const TYPE &($basetype temp)
|
||||||
%{ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%}
|
%{ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%}
|
||||||
%typemap(out) const TYPE&
|
%typemap(out) const TYPE&
|
||||||
%{ lua_pushnumber(L, (double) *$1); SWIG_arg++;%}
|
%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
SWIG_NUMBER_BY_CONST_REF(int);
|
SWIG_NUMBER_BY_CONST_REF(int);
|
||||||
|
|
@ -260,7 +260,7 @@ SWIG_NUMBER_BY_CONST_REF(enum SWIGTYPE);
|
||||||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE* const &($*ltype temp)
|
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE* const &($*ltype temp)
|
||||||
%{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname");
|
%{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname");
|
||||||
$1=&temp;%}
|
$1=&temp;%}
|
||||||
// and the pytcheck code
|
// and the typecheck code
|
||||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE* const &
|
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE* const &
|
||||||
%{
|
%{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
@ -374,7 +374,7 @@ use %include <std_except.i> instead
|
||||||
long long,unsigned long long,
|
long long,unsigned long long,
|
||||||
char, unsigned char, signed char,
|
char, unsigned char, signed char,
|
||||||
enum SWIGTYPE
|
enum SWIGTYPE
|
||||||
%{lua_pushfstring(L,"exception thrown of value %d",(long)$1);
|
%{lua_pushfstring(L,"exception thrown of value %f",(double)$1);
|
||||||
SWIG_fail; %}
|
SWIG_fail; %}
|
||||||
|
|
||||||
// strings are just sent as errors
|
// strings are just sent as errors
|
||||||
|
|
|
||||||
44
SWIG/Lib/lua/std_pair.i
Normal file
44
SWIG/Lib/lua/std_pair.i
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/***********************************************************************
|
||||||
|
* std_pair.i
|
||||||
|
*
|
||||||
|
* std::pair typemaps for LUA
|
||||||
|
*
|
||||||
|
* Author : Mark Gossage (mark@gossage.cjb.net)
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <utility>
|
||||||
|
%}
|
||||||
|
/*
|
||||||
|
A really cut down version of the pair class.
|
||||||
|
|
||||||
|
this is not useful on its owns is it needs a %template definition with it
|
||||||
|
|
||||||
|
eg.
|
||||||
|
namespace std {
|
||||||
|
%template(IntPair) pair<int, int>;
|
||||||
|
%template(make_IntPair) make_pair<int, int>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template <class T, class U > struct pair {
|
||||||
|
typedef T first_type;
|
||||||
|
typedef U second_type;
|
||||||
|
|
||||||
|
pair();
|
||||||
|
pair(T first, U second);
|
||||||
|
pair(const pair& p);
|
||||||
|
|
||||||
|
T first;
|
||||||
|
U second;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class U >
|
||||||
|
pair<T,U> make_pair(const T&,const U&);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,11 @@ assert(s==s2)
|
||||||
%{lua_pushstring(L,$1.c_str());
|
%{lua_pushstring(L,$1.c_str());
|
||||||
SWIG_fail; %}
|
SWIG_fail; %}
|
||||||
|
|
||||||
|
// and the typechecks
|
||||||
|
%typecheck(SWIG_TYPECHECK_STRING) std::string,const std::string& {
|
||||||
|
$1 = lua_isstring(L,$input);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
std::string& can be wrappered, but you must inform SWIG if it is in or out
|
std::string& can be wrappered, but you must inform SWIG if it is in or out
|
||||||
|
|
||||||
|
|
@ -100,6 +105,8 @@ This provides basic mapping of lua strings <-> std::string
|
||||||
and little else
|
and little else
|
||||||
(the std::string has a lot of unneeded functions anyway)
|
(the std::string has a lot of unneeded functions anyway)
|
||||||
|
|
||||||
|
note: no fn's taking the const string&
|
||||||
|
as this is overloaded by the const char* version
|
||||||
*/
|
*/
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
|
|
@ -107,7 +114,7 @@ namespace std {
|
||||||
public:
|
public:
|
||||||
string();
|
string();
|
||||||
string(const char*);
|
string(const char*);
|
||||||
string(const string&);
|
//string(const string&);
|
||||||
unsigned int size() const;
|
unsigned int size() const;
|
||||||
unsigned int length() const;
|
unsigned int length() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
@ -117,7 +124,7 @@ namespace std {
|
||||||
// assign does not return a copy of this object
|
// assign does not return a copy of this object
|
||||||
// (no point in a scripting language)
|
// (no point in a scripting language)
|
||||||
void assign(const char*);
|
void assign(const char*);
|
||||||
void assign(const string&);
|
//void assign(const string&);
|
||||||
// no support for all the other features
|
// no support for all the other features
|
||||||
// its probably better to do it in lua
|
// its probably better to do it in lua
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,17 @@ or provide a %apply statement
|
||||||
|
|
||||||
|
|
||||||
%define SWIG_NUMBER_TYPEMAP(TYPE)
|
%define SWIG_NUMBER_TYPEMAP(TYPE)
|
||||||
%typemap(in,checkfn="lua_isnumber") TYPE *INPUT($*type temp), TYPE &INPUT($*type temp)
|
%typemap(in,checkfn="lua_isnumber") TYPE *INPUT($*ltype temp), TYPE &INPUT($*ltype temp)
|
||||||
%{ temp = ($*type)lua_tonumber(L,$input);
|
%{ temp = ($*ltype)lua_tonumber(L,$input);
|
||||||
$1 = &temp; %}
|
$1 = &temp; %}
|
||||||
%typemap(in, numinputs=0) TYPE *OUTPUT ($*type temp)
|
%typemap(in, numinputs=0) TYPE *OUTPUT ($*ltype temp)
|
||||||
%{ $1 = &temp; %}
|
%{ $1 = &temp; %}
|
||||||
%typemap(argout) TYPE *OUTPUT
|
%typemap(argout) TYPE *OUTPUT
|
||||||
%{ lua_pushnumber(L, (double) *$1); SWIG_arg++;%}
|
%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%}
|
||||||
%typemap(in) TYPE *INOUT = TYPE *INPUT;
|
%typemap(in) TYPE *INOUT = TYPE *INPUT;
|
||||||
%typemap(argout) TYPE *INOUT = TYPE *OUTPUT;
|
%typemap(argout) TYPE *INOUT = TYPE *OUTPUT;
|
||||||
|
%typemap(in) TYPE &INOUT = TYPE *INPUT;
|
||||||
|
%typemap(argout) TYPE &INOUT = TYPE *OUTPUT;
|
||||||
// const version (the $*ltype is the basic number without ptr or const's)
|
// const version (the $*ltype is the basic number without ptr or const's)
|
||||||
%typemap(in,checkfn="lua_isnumber") const TYPE *INPUT($*ltype temp)
|
%typemap(in,checkfn="lua_isnumber") const TYPE *INPUT($*ltype temp)
|
||||||
%{ temp = ($*ltype)lua_tonumber(L,$input);
|
%{ temp = ($*ltype)lua_tonumber(L,$input);
|
||||||
|
|
@ -253,7 +255,7 @@ int SWIG_table_size(lua_State* L, int index)
|
||||||
int i;\
|
int i;\
|
||||||
lua_newtable(L);\
|
lua_newtable(L);\
|
||||||
for (i = 0; i < size; i++){\
|
for (i = 0; i < size; i++){\
|
||||||
lua_pushnumber(L,(double)array[i]);\
|
lua_pushnumber(L,(lua_Number)array[i]);\
|
||||||
lua_rawseti(L,-2,i+1);/* -1 is the number, -2 is the table*/ \
|
lua_rawseti(L,-2,i+1);/* -1 is the number, -2 is the table*/ \
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue