Merge branch 'master' into gsoc2009-matevz

parser.y still to be fixed up

Conflicts:
	Doc/Devel/engineering.html
	Examples/Makefile.in
	Lib/allegrocl/allegrocl.swg
	Lib/csharp/csharp.swg
	Lib/csharp/enums.swg
	Lib/csharp/enumsimple.swg
	Lib/csharp/enumtypesafe.swg
	Lib/java/java.swg
	Lib/python/pydocs.swg
	Lib/r/rtype.swg
	Source/Include/swigwarn.h
	Source/Modules/octave.cxx
	Source/Modules/python.cxx
	Source/Modules/ruby.cxx
	Source/Swig/scanner.c
	Source/Swig/stype.c
	Source/Swig/swig.h
	configure.ac
This commit is contained in:
William S Fulton 2013-01-28 07:01:37 +00:00
commit e805d5f925
1074 changed files with 54339 additions and 20134 deletions

View file

@ -4,7 +4,7 @@
* std::helpers for LUA
* ----------------------------------------------------------------------------- */
%include <std_except.i> // the general exepctions
%include <std_except.i> // the general exceptions
/*
The basic idea here, is instead of trying to feed SWIG all the
@ -16,9 +16,9 @@ so the class declarations become just a set of %defines
*/
/* #define for basic container features
note: I allow front(), back() & pop_back() to throw execptions
note: I allow front(), back() & pop_back() to throw exceptions
upon empty containers, rather than coredump
(as we have'nt defined the methods, we can use %extend to add with
(as we haven't defined the methods, we can use %extend to add with
new features)
*/

View file

@ -1,5 +1,5 @@
/* Small change to the standard carrays.i
renaming the field to __getitem__ & __setitem__
renaming the field to __getitem & __setitem
for operator[] access
*/
%rename(__getitem) *::getitem; // the v=X[i] (get operator)

23
Lib/lua/factory.i Normal file
View file

@ -0,0 +1,23 @@
/*
A modification of factory.swg from the generic UTL library.
*/
%include <typemaps/swigmacros.swg>
%define %_factory_dispatch(Type)
if (!dcast) {
Type *dobj = dynamic_cast<Type *>($1);
if (dobj) {
dcast = 1;
SWIG_NewPointerObj(L, dobj, $descriptor(Type *), $owner); SWIG_arg++;
}
}%enddef
%define %factory(Method,Types...)
%typemap(out) Method {
int dcast = 0;
%formacro(%_factory_dispatch, Types)
if (!dcast) {
SWIG_NewPointerObj(L, $1, $descriptor, $owner); SWIG_arg++;
}
}%enddef

View file

@ -18,27 +18,27 @@
* ----------------------------------------------------------------------------- */
// this basically adds to a table of constants
%typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
{ SWIG_LUA_INT, (char *)"$symname", (long) $value, 0, 0, 0}
{SWIG_LUA_CONSTTAB_INT("$symname", $value)}
%typemap(consttab) float, double
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) long long, unsigned long long, signed long long
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", $value)}
%typemap(consttab) const long long&, const unsigned long long&, const signed long long&
{ SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) *$value, 0, 0}
{SWIG_LUA_CONSTTAB_FLOAT("$symname", *$value)}
%typemap(consttab) char *, const char *, char [], const char []
{ SWIG_LUA_STRING, (char *)"$symname", 0, 0, (void *)$value, 0}
{SWIG_LUA_CONSTTAB_STRING("$symname", $value)}
// note: char is treated as a seperate special type
// signed char & unsigned char are numbers
%typemap(consttab) char
{ SWIG_LUA_CHAR, (char *)"$symname", (long)$value, 0, 0, 0}
{SWIG_LUA_CONSTTAB_CHAR("$symname", $value)}
%typemap(consttab) long long, unsigned long long
{ SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0}
{SWIG_LUA_CONSTTAB_STRING("$symname", "$value")}
%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE []
{ SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}
@ -142,8 +142,8 @@
/* ------------------------------------------------------------
* Exceptions
* ------------------------------------------------------------ */
/* Confession: I dont really like C++ exceptions
The python/lua ones are great, but C++ ones I dont like
/* Confession: I don't really like C++ exceptions
The python/lua ones are great, but C++ ones I don't like
(mainly because I cannot get the stack trace out of it)
Therefore I have not bothered to try doing much in this
@ -191,7 +191,7 @@ There are a few options:
- return a copy of it: but not all objects are copyable
(see exception_partial_info in the test suite for a case where you cannot do this)
- convert to a string & throw that
its not so useful, but it works (this is more lua like).
it's not so useful, but it works (this is more lua like).
The third option (though not nice) is used
For a more useful solution: see std_except for more details
*/

View file

@ -8,7 +8,7 @@
* Basic function pointer support
* ----------------------------------------------------------------------------- */
/*
The structure: SWIGLUA_FN provides a simple (local only) wrappering for a function.
The structure: SWIGLUA_FN provides a simple (local only) wrapping for a function.
For example if you wanted to have a C/C++ function take a lua function as a parameter.
You could declare it as:
@ -29,7 +29,7 @@ just push the parameters, call the function and return the result.
return luaL_checknumber(fn.L,-1);
}
SWIG will automatically performs the wrappering of the arguments in and out.
SWIG will automatically performs the wrapping of the arguments in and out.
However: if you wish to store the function between calls, look to the SWIGLUA_REF below.
@ -64,8 +64,8 @@ Then call it later, You could declare it as:
note: it should be passed by value, not byref or as a pointer.
The SWIGLUA_REF holds a pointer to the lua_State, and an integer reference to the object.
Because it holds a permenet ref to an object, the SWIGLUA_REF must be handled with a bit more care.
It should be initalised to {0,0}. The function swiglua_ref_set() should be used to set it.
Because it holds a permanent ref to an object, the SWIGLUA_REF must be handled with a bit more care.
It should be initialised to {0,0}. The function swiglua_ref_set() should be used to set it.
swiglua_ref_clear() should be used to clear it when not in use, and swiglua_ref_get() to get the
data back.
@ -82,7 +82,7 @@ if you need that you must add it yourself.
return luaL_checknumber(fn.L,-1);
}
SWIG will automatically performs the wrappering of the arguments in and out.
SWIG will automatically performs the wrapping of the arguments in and out.
However: if you wish to store the function between calls, look to the SWIGLUA_REF below.

View file

@ -15,6 +15,62 @@ extern "C" {
#include <stdlib.h> /* for malloc */
#include <assert.h> /* for a few sanity tests */
/* -----------------------------------------------------------------------------
* Lua flavors
* ----------------------------------------------------------------------------- */
#define SWIG_LUA_FLAVOR_LUA 1
#define SWIG_LUA_FLAVOR_ELUA 2
#define SWIG_LUA_FLAVOR_ELUAC 3
#if !defined(SWIG_LUA_TARGET)
# error SWIG_LUA_TARGET not defined
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
# define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
#else /* SWIG_LUA_FLAVOR_LUA */
# define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
# define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
# define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
#endif
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
# define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
# define LSTRVAL LRO_STRVAL
#endif
/* -----------------------------------------------------------------------------
* compatibility defines
* ----------------------------------------------------------------------------- */
/* History of Lua C API length functions: In Lua 5.0 (and before?)
there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
but a compatibility define of "lua_strlen" was added. In Lua 5.2,
this function was again renamed, to "lua_rawlen" (to emphasize that
it doesn't call the "__len" metamethod), and the compatibility
define of lua_strlen was removed. All SWIG uses have been updated
to "lua_rawlen", and we add our own defines of that here for older
versions of Lua. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
# define lua_rawlen lua_strlen
#elif LUA_VERSION_NUM == 501
# define lua_rawlen lua_objlen
#endif
/* lua_pushglobaltable is the recommended "future-proof" way to get
the global table for Lua 5.2 and later. Here we define
lua_pushglobaltable ourselves for Lua versions before 5.2. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#endif
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */
@ -65,7 +121,7 @@ typedef struct swig_lua_class {
const char **base_names;
} swig_lua_class;
/* this is the struct for wrappering all pointers in SwigLua
/* this is the struct for wrapping all pointers in SwigLua
*/
typedef struct {
swig_type_info *type;
@ -73,7 +129,7 @@ typedef struct {
void *ptr;
} swig_lua_userdata;
/* this is the struct for wrapping arbitary packed binary data
/* this is the struct for wrapping arbitrary packed binary data
(currently it is only used for member function pointers)
the data ordering is similar to swig_lua_userdata, but it is currently not possible
to tell the two structures apart within SWIG, other than by looking at the type
@ -157,7 +213,7 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
* ----------------------------------------------------------------------------- */
/* this function is called when trying to set an immutable.
default value is to print an error.
default action is to print an error.
This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L)
{
@ -181,12 +237,24 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
lua_tostring(L,2));
*/
/* get the metatable */
assert(lua_istable(L,1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,1)); /* just in case */
#else
assert(lua_istable(L,1)); /* default Lua action */
#endif
lua_getmetatable(L,1); /* get the metatable */
assert(lua_istable(L,-1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,-1)); /* just in case */
#else
assert(lua_istable(L,-1));
#endif
SWIG_Lua_get_table(L,".get"); /* get the .get table */
lua_remove(L,3); /* remove metatable */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
if (lua_isrotable(L,-1))
#else
if (lua_istable(L,-1))
#endif
{
/* look for the key in the .get table */
lua_pushvalue(L,2); /* key */
@ -201,7 +269,7 @@ SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
}
lua_pop(L,1); /* remove the .get */
lua_pushnil(L); /* return a nil */
return 1;
return 1;
}
/* the module.set method used for setting linked data */
@ -213,12 +281,24 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
(3) any for the new value
*/
/* get the metatable */
assert(lua_istable(L,1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,1)); /* just in case */
#else
assert(lua_istable(L,1)); /* default Lua action */
#endif
lua_getmetatable(L,1); /* get the metatable */
assert(lua_istable(L,-1)); /* just in case */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
assert(lua_isrotable(L,-1)); /* just in case */
#else
assert(lua_istable(L,-1));
#endif
SWIG_Lua_get_table(L,".set"); /* get the .set table */
lua_remove(L,4); /* remove metatable */
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
if (lua_isrotable(L,-1))
#else
if (lua_istable(L,-1))
#endif
{
/* look for the key in the .set table */
lua_pushvalue(L,2); /* key */
@ -230,6 +310,11 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
lua_call(L,1,0);
return 0;
}
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA)
else {
return 0; // Exits stoically if an invalid key is initialized.
}
#endif
}
lua_settop(L,3); /* reset back to start */
/* we now have the table, key & new value, so just set directly */
@ -237,7 +322,8 @@ SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
return 0;
}
/* registering a module in lua */
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* registering a module in lua. Pushes the module table on the stack. */
SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
{
assert(lua_istable(L,-1)); /* just in case */
@ -254,8 +340,16 @@ SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
lua_newtable(L); /* the .set table */
lua_rawset(L,-3); /* add .set into metatable */
lua_setmetatable(L,-2); /* sets meta table in module */
#ifdef SWIG_LUA_MODULE_GLOBAL
/* If requested, install the module directly into the global namespace. */
lua_rawset(L,-3); /* add module into parent */
SWIG_Lua_get_table(L,name); /* get the table back out */
#else
/* Do not install the module table as global name. The stack top has
the module table with the name below. We pop the top and replace
the name with it. */
lua_replace(L,-2);
#endif
}
/* ending the register */
@ -283,6 +377,7 @@ SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_C
}
lua_pop(L,1); /* tidy stack (remove meta) */
}
#endif
/* adding a function module */
SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
@ -412,6 +507,39 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
return 0;
}
/* the class.__tostring method called by the interpreter and print */
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
assert(lua_isuserdata(L,1)); /* just in case */
unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
lua_getmetatable(L,1); /* get the meta table */
assert(lua_istable(L,-1)); /* just in case */
lua_getfield(L, -1, ".type");
const char* className = lua_tostring(L, -1);
char output[256];
sprintf(output, "<%s userdata: %lX>", className, userData);
lua_pushstring(L, (const char*)output);
return 1;
}
/* to manually disown some userdata */
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
{
/* there should be 1 params passed in
(1) userdata (not the meta table) */
swig_lua_userdata* usr;
assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
usr->own = 0; /* clear our ownership */
return 0;
}
/* gets the swig class registry (or creates it) */
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
{
@ -506,7 +634,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss)
swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
}
}
}
}
/* performs the entire class registration process */
@ -537,11 +665,15 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
/* add a table called ".fn" */
lua_pushstring(L,".fn");
lua_newtable(L);
/* add manual disown method */
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
lua_rawset(L,-3);
/* add accessor fns for using the .get,.set&.fn */
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
/* add tostring method for better output */
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
/* add it */
lua_rawset(L,-3); /* metatable into registry */
lua_pop(L,1); /* tidy stack (remove registry) */
@ -584,7 +716,9 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *t
usr->ptr=ptr; /* set the ptr */
usr->type=type;
usr->own=own;
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
_SWIG_Lua_AddMetatable(L,type); /* add metatable */
#endif
}
/* takes a object from the lua stack & converts it into an object of the correct type
@ -697,6 +831,7 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
* global variable support code: class/struct typemap functions
* ----------------------------------------------------------------------------- */
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* Install Constants */
SWIGINTERN void
SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
@ -738,6 +873,7 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
}
}
}
#endif
/* -----------------------------------------------------------------------------
* executing lua code from within the wrapper
@ -746,8 +882,8 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
#ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
#define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
#endif
/* Executes a C string in Lua a really simple way of calling lua from C
Unfortunately lua keeps changing its API's, so we need a conditional compile
/* Executes a C string in Lua which is a really simple way of calling lua from C
Unfortunately lua keeps changing its APIs, so we need a conditional compile
In lua 5.0.X its lua_dostring()
In lua 5.1.X its luaL_dostring()
*/

View file

@ -19,16 +19,24 @@ extern "C" {
#endif
/* this is the initialization function
added at the very end of the code
the function is always called SWIG_init, but an eariler #define will rename it
the function is always called SWIG_init, but an earlier #define will rename it
*/
SWIGEXPORT int SWIG_init(lua_State* L)
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
LUALIB_API int SWIG_init(lua_State* L)
#else
SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#endif
{
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
/* start with global table */
lua_pushvalue(L,LUA_GLOBALSINDEX);
lua_pushglobaltable (L);
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();
#endif
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* add a global fn */
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
@ -42,7 +50,10 @@ SWIGEXPORT int SWIG_init(lua_State* L)
for (i = 0; swig_variables[i].name; i++){
SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
}
/* set up base class pointers (the hierachy) */
#endif
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
/* set up base class pointers (the hierarchy) */
for (i = 0; swig_types[i]; i++){
if (swig_types[i]->clientdata){
SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
@ -54,14 +65,24 @@ SWIGEXPORT int SWIG_init(lua_State* L)
SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
}
}
#endif
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
/* constants */
SWIG_Lua_InstallConstants(L,swig_constants);
#endif
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
/* invoke user-specific initialization */
SWIG_init_user(L);
/* end module */
lua_pop(L,1); /* tidy stack (remove module table)*/
lua_pop(L,1); /* tidy stack (remove global table)*/
/* Note: We do not clean up the stack here (Lua will do this for us). At this
point, we have the globals table and out module table on the stack. Returning
one value makes the module table the result of the require command. */
return 1;
#else
return 0;
#endif
}
#ifdef __cplusplus

View file

@ -13,7 +13,7 @@
the fn call must be of the form
int checkfn(lua_State *L, int index);
and return 1/0 depending upon if this is the correct type
For the typemap(out), an additional SWIG_arg parmeter must be incremented
For the typemap(out), an additional SWIG_arg parameter must be incremented
to reflect the number of values returned (normally SWIG_arg++; will do)
*/
// numbers
@ -33,7 +33,7 @@ $1 = ($type)lua_tonumber(L, $input);%}
float,double
%{ lua_pushnumber(L, (lua_Number) $1); SWIG_arg++;%}
// we must also provide typemaps for privitives by const reference:
// we must also provide typemaps for primitives by const reference:
// given a function:
// int intbyref(const int& i);
// SWIG assumes that this code will need a pointer to int to be passed in
@ -136,7 +136,7 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
// it should be converted to a SWIG NULL.
// This will only be allowed for pointers & arrays, not refs or by value
// the checkfn lua_isuserdata will only work for userdata
// the checkfn SWIG_isptrtype will work for both userdata and nil's
// the checkfn SWIG_isptrtype will work for both userdata and nil
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE*,SWIGTYPE[]
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
@ -232,9 +232,9 @@ $1=($1_ltype)&temp;%}
// member function pointer
// a member fn ptr is not 4 bytes like a normal pointer, but 8 bytes (at least on mingw)
// so the standard wrappering cannot be done
// so the standard wrapping cannot be done
// nor can you cast a member function pointer to a void* (obviously)
// therefore a special wrappering functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
// therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
#ifdef __cplusplus
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*)
%{
@ -254,7 +254,7 @@ $1=($1_ltype)&temp;%}
/* void* is a special case
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)
but if its an output, then it should be wrappered like any other SWIG object (using default typemap)
but if its an output, then it should be wrapped like any other SWIG object (using default typemap)
*/
%typemap(in,checkfn="SWIG_isptrtype") void*
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,0,0,$argnum,"$symname");%}
@ -282,7 +282,7 @@ void fn(int a, float b, lua_State* s) is wrappable as
* ----------------------------------------------------------------------------- */
/* These are needed for the overloaded functions
These define the detection routines which will spot what
parmeters match which function
parameters match which function
*/
// unfortunately lua only considers one type of number
@ -311,7 +311,7 @@ parmeters match which function
// special check for a char (string of length 1)
%typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& {
$1 = SWIG_lua_isnilstring(L,$input) && (lua_strlen(L,$input)==1);
$1 = SWIG_lua_isnilstring(L,$input) && (lua_rawlen(L,$input)==1);
}
%typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] {
@ -363,7 +363,7 @@ parmeters match which function
}
}
// Also needed for object ptrs by const ref
// Also needed for object pointers by const ref
// eg const A* ref_pointer(A* const& a);
// found in mixed_types.i
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&

View file

@ -24,8 +24,8 @@ namespace std
};
}
// normally object which are thrown are returned to interpreter as errors
// (which potentally may have problems if they are not copied)
// normally objects which are thrown are returned to the interpreter as errors
// (which potentially may have problems if they are not copied)
// therefore all classes based upon std::exception are converted to their strings & returned as errors
%typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());"
%typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());"

View file

@ -10,7 +10,7 @@
/*
A really cut down version of the pair class.
this is not useful on its owns is it needs a %template definition with it
this is not useful on its own - it needs a %template definition with it
eg.
namespace std {

View file

@ -5,10 +5,11 @@
* ----------------------------------------------------------------------------- */
%{
#include <string>
#include <string>
%}
/*
Only std::string and const std::string& are typemaped
Only std::string and const std::string& are typemapped
they are converted to the Lua strings automatically
std::string& and std::string* are not
@ -25,14 +26,15 @@ can be used as
s="hello world"
s2=test_value(s)
assert(s==s2)
*/
%naturalvar std::string;
namespace std {
%naturalvar string;
/*
Bug report #1526022 by neomantra
Lua strings and std::string can contain embeded zero's
Bug report #1526022:
Lua strings and std::string can contain embedded zero bytes
Therefore a standard out typemap should not be:
lua_pushstring(L,$1.c_str());
but
@ -41,82 +43,56 @@ but
Similarly for getting the string
$1 = (char*)lua_tostring(L, $input);
becomes
$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));
$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));
Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
*/
%typemap(in,checkfn="lua_isstring") std::string
%{$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));%}
%typemap(out) std::string
%typemap(in,checkfn="lua_isstring") string
%{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%}
%typemap(out) string
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in,checkfn="lua_isstring") const std::string& (std::string temp)
%{temp.assign(lua_tostring(L,$input),lua_strlen(L,$input)); $1=&temp;%}
%typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp)
%{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
%typemap(out) const std::string&
%typemap(out) const string&
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
// for throwing of any kind of string, string ref's and string pointers
// we convert all to lua strings
%typemap(throws) std::string,std::string&,const std::string&
%typemap(throws) string, string&, const string&
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_fail;%}
%typemap(throws) std::string*,const std::string*
%typemap(throws) string*, const string*
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_fail;%}
// and the typechecks
%typecheck(SWIG_TYPECHECK_STRING) std::string,const std::string& {
%typecheck(SWIG_TYPECHECK_STRING) string, const 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 wrapped, but you must inform SWIG if it is in or out
eg:
void fn(std::string& str);
Is this an in/out/inout value?
Therefore you need the usual
%apply (std::string& INOUT) {(std::string& str)};
%apply (std::string& INOUT) {std::string& str};
or
%apply std::string& INOUT {std::string& str};
typemaps to tell SWIG what to do.
*/
%typemap(in) std::string &INPUT=const std::string &;
%typemap(in, numinputs=0) std::string &OUTPUT (std::string temp)
%typemap(in) string &INPUT=const string &;
%typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp)
%{ $1 = &temp; %}
%typemap(argout) std::string &OUTPUT
%typemap(argout) string &OUTPUT
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
%typemap(in) std::string &INOUT =const std::string &;
%typemap(argout) std::string &INOUT = std::string &OUTPUT;
/*
For const std::string* and std::string* is not clear
is this a pointer or an array?
Therefore just leaving it as is
(there is some rough code below which could be used if needed
// SWIG wraps const ref's as pointer
// typemaps to deal with this and const ptrs
%typemap(in,checkfn="lua_isstring")
const std::string& INPUT(std::string temp),
const std::string* INPUT(std::string temp)
%{temp=(char*)lua_tostring(L, $input); $1=&temp;%}
%typemap(out) const std::string&, const std::string*
%{ lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
// the non-const pointer version
%typemap(in) std::string *INPUT=const std::string *INPUT;
%typemap(in, numinputs=0) std::string *OUTPUT (std::string temp)
%{ $1 = &temp; %}
%typemap(argout) std::string *OUTPUT
%{ lua_pushstring(L,$1->c_str()); SWIG_arg++;%}
%typemap(in) std::string *INOUT = std::string *INPUT;
%typemap(argout) std::string *INOUT = std::string *OUTPUT;
*/
%typemap(in) string &INOUT =const string &;
%typemap(argout) string &INOUT = string &OUTPUT;
/*
A really cut down version of the string class
@ -128,25 +104,24 @@ and little else
note: no fn's taking the const string&
as this is overloaded by the const char* version
*/
namespace std {
class string {
public:
string();
string(const char*);
//string(const string&);
unsigned int size() const;
unsigned int length() const;
bool empty() const;
// no support for operator[]
const char* c_str()const;
const char* data()const;
// assign does not return a copy of this object
// (no point in a scripting language)
void assign(const char*);
//void assign(const string&);
// no support for all the other features
// its probably better to do it in lua
};
class string {
public:
string();
string(const char*);
//string(const string&);
unsigned int size() const;
unsigned int length() const;
bool empty() const;
// no support for operator[]
const char* c_str()const;
const char* data()const;
// assign does not return a copy of this object
// (no point in a scripting language)
void assign(const char*);
//void assign(const string&);
// no support for all the other features
// it's probably better to do it in lua
};
}

View file

@ -7,7 +7,7 @@
%{
#include <vector>
%}
%include <std_except.i> // the general exepctions
%include <std_except.i> // the general exceptions
/*
A really cut down version of the vector class.

View file

@ -66,8 +66,10 @@ or provide a %apply statement
%enddef
// now the code
SWIG_NUMBER_TYPEMAP(int); SWIG_NUMBER_TYPEMAP(unsigned int); SWIG_NUMBER_TYPEMAP(signed int);
SWIG_NUMBER_TYPEMAP(unsigned char); SWIG_NUMBER_TYPEMAP(signed char);
SWIG_NUMBER_TYPEMAP(short); SWIG_NUMBER_TYPEMAP(unsigned short); SWIG_NUMBER_TYPEMAP(signed short);
SWIG_NUMBER_TYPEMAP(int); SWIG_NUMBER_TYPEMAP(unsigned int); SWIG_NUMBER_TYPEMAP(signed int);
SWIG_NUMBER_TYPEMAP(long); SWIG_NUMBER_TYPEMAP(unsigned long); SWIG_NUMBER_TYPEMAP(signed long);
SWIG_NUMBER_TYPEMAP(float);
SWIG_NUMBER_TYPEMAP(double);
@ -138,21 +140,21 @@ a few things of note:
so for the above mentioned return_array_5() would look like
arr=return_array_5() -- no parameters passed in
* for INOUT arrays, a table must be passed in, and a new table will be returned
(this is consistant with the way that numbers are processed)
(this is consistent with the way that numbers are processed)
if you want just use
arr={...}
arr=process_var_array_inout(arr) -- arr is replaced by the new version
The following are not yet supported:
* variable length output only array (inout's work ok)
* multidimentional arrays
* variable length output only array (inout works ok)
* multidimensional arrays
* arrays of objects/structs
* arrays of pointers
*/
/*
The internals of the array managment stuff
The internals of the array management stuff
helper fns/macros
SWIG_ALLOC_ARRAY(TYPE,LEN) // returns a typed array TYPE[LEN]
SWIG_FREE_ARRAY(PTR) // delete the ptr (if not zero)
@ -345,6 +347,8 @@ for array handling
// as well as defining typemaps for
// fixed len arrays in & out, & variable length arrays in
SWIG_TYPEMAP_NUM_ARR(schar,signed char);
SWIG_TYPEMAP_NUM_ARR(uchar,unsigned char);
SWIG_TYPEMAP_NUM_ARR(int,int);
SWIG_TYPEMAP_NUM_ARR(uint,unsigned int);
SWIG_TYPEMAP_NUM_ARR(short,short);
@ -363,7 +367,7 @@ SWIG_TYPEMAP_NUM_ARR(double,double);
%typemap(freearg) enum SWIGTYPE INPUT[ANY]
%{ SWIG_FREE_ARRAY($1);%}
// variable size array's
// variable size arrays
%typemap(in) (enum SWIGTYPE *INPUT,int)
%{ $1 = ($ltype)SWIG_get_int_num_array_var(L,$input,&$2);
if (!$1) SWIG_fail;%}
@ -410,7 +414,7 @@ void** SWIG_get_ptr_array_var(lua_State* L, int index, int* size,swig_type_info
// all pointers have the ownership value 'own' (normally 0)
void SWIG_write_ptr_array(lua_State* L,void **array,int size,int own);
// read the specified table, and fills the array with ptrs
// returns 1 of ok (only fails if it doesnt find correct type of ptrs)
// returns 1 of ok (only fails if it doesn't find correct type of ptrs)
// helper fn (called by SWIG_get_ptr_array_*() fns)
int SWIG_read_ptr_array(lua_State* L,int index,void **array,int size,swig_type_info *type);
@ -420,7 +424,7 @@ modification of pointers ownership in the arrays
eg A fn:
void pointers_in(TYPE* arr[],int len);
will make copies of the pointer into a temp array and then pass it into the fn
Lua does not remeber that this fn held the pointers, so it is not safe to keep
Lua does not remember that this fn held the pointers, so it is not safe to keep
these pointers until later
eg A fn:
@ -547,13 +551,14 @@ free(ptr);
With the following SWIG code
%apply SWIGTYPE** OUTPUT{iMath **pptr };
You can get natural wrappering in Lua as follows:
You can get natural wrapping in Lua as follows:
ok,ptr=Create_Math() -- ptr is a iMath* which is returned with the int
ptr=nil -- the iMath* will be GC'ed as normal
*/
%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp)
%{ $1 = &temp; %}
%{ temp = ($*ltype)0;
$1 = &temp; %}
%typemap(argout) SWIGTYPE** OUTPUT
%{SWIG_NewPointerObj(L,*$1,$*descriptor,1); SWIG_arg++; %}

View file

@ -30,7 +30,7 @@ wchar_t* str2wstr(const char *str, int len)
%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t *
%{
$1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input ));
$1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input ));
if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;}
%}