summaryrefslogtreecommitdiff
path: root/Lib/lua
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2015-01-14 13:45:55 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2015-01-14 13:45:55 +0000
commitefa96eb76d4f1a6b14633ab653699352936fe3d1 (patch)
tree0b13e154013ab12d06cf0eadd4740d9fd9b79731 /Lib/lua
parent6d86fb173915867bd70d6780a174bce3c5b3c1df (diff)
parent4fed2e6690b1486952b0543b6bde28573eb0d132 (diff)
downloadswig-coverity-scan.tar.gz
Merge branch 'master' into coverity-scancoverity-scan
* master: (478 commits) Use -rrbconfig rather than -rmkmf to load rbconfig Add suggestion to check block delimiter Add explanatory comment to pp_unknowndirective2.i Fix PHP crash in director_finalizer Add 3.0.4 release information Fix typo Note 1.8 as the oldest supported version Fix PHP backend for default_args testcase Update html Python 3 default args fix Revert introduction of python:defaultargs feature Ruby: Replace Config::CONFIG with RbConfig::CONFIG in configure.ac Add regression test for #217 [PHP] Fix segfault in director upcall check Fix linux gcc warnings and strtol corrections Tests for Python default arguments and %pythondefaultargs. Python default arg improvements [lua/luarun] change return type from int to void on functions not returning anything Add note about delimiting blocks of Python code Fix python default_args testcase for Python 3 Fix Python default argument handing broken since swig-3.0.3 Python default argument test cases from issue #294 Wording change for missing semicolon error Handle "constexpr explicit" and "constexpr static" Allow C++11 "explicit constexpr" Improve errors for missing ; and unexpected ) Fix typo in old entry Add test coverage for unterminated %{ ... %} block When reporting an error for a construct which hasn't been terminated when the end of the file is reached, report it at the start line rather than "EOF" as then tools like editors and IDEs will take you to a generally more useful place for fixing the problem. Improve error message for extraneous '%}'. Add .gitignore for Examples/test-suite/errors/ Fix testcase name in expected output Improve error message when an unknown SWIG directive is used Update link to point to 3.0 docs Fix links to the online 1.3 docs to instead be relative Drop deprecated warnings for ancient options Fix tab to space in HTML preformatted block Provide -cppext as a general command line option Split -help output into 4 chunks instead of 3 More on Go examples [skip ci] Properly quote parameters in preinst-swig wrapper. Fix typo Bump version to 3.0.4 HTML tweaks Add 3.0.3 release information Minor tweaks to the changes file %constant and structs support for Lua Fix D examples when run 'in-source' Fix D examples clean Revert "Fix D examples clean" Fix javascript clean Let Octave 3.8 fail in Travis Fix D examples clean Fix javascript clean Tidy up Javascript build system Don't delete checked in files with 'make distclean' Reduce scope of template_default_class_parms testcase Fix abort using template default parameters Test suite warning fixes [Perl] tidy "warning: duplicate 'extern' declaration specifier" when building generated code under clang Issue #282 perl5 archlib vs archlibexp [Go] Changed link 'https://github.com/golang/go/tree/master/misc/swig' to 'https://golang.org/misc/swig' in the Go documentation. [Go] Updated Go documentation (examples, runtime.SetFinalizer, object ownership). Added auto-generated 'Examples/d/example.mk' to '.gitignore'. Warning suppressions in tests nested_scope test fixes for clang Fix use of preprocessor null directive Add testcase for nested inner class deriving from a templated base class and defined outside of the outer class. Add in missing constant_directive.i test Improve Python builtin and %constant structs fixed python global object constants Partial support for %constant and structs Ignore E402 (import not on top of file) PEP8 error. Add PEP8_FLAGS variable to the test suite Python makefile. Fix templated constructors regression Correctly detect Go1 during configure Fix regression in introduced in merge of C++11 strongly typed enums support - Guile constants bad casts generated - Go non-public enum value wrappers assert failure Document new C++11 strongly typed enumerations support. Add more docs about _global_ prefix in typemap temporary variables Add clarification on _global_ prefix. Improve Javascript Webkit detection Add c++11 strongly typed enums runtime test for Javascript Add c++11 strongly typed enums runtime test for Octave Add c++11 strongly typed enum support for Guile Add c++11 strongly typed enum support for Go Add c++11 strongly typed enum support for D Add c++11 strongly typed enum support for Lua Fix line endings in lua example Add c++11 strongly typed enums runtime test for Tcl Add c++11 strongly typed enum support for PHP Add c++11 strongly typed enums runtime test for Ruby Add c++11 strongly typed enums runtime test for Perl Enhance C++11 strongly typed enums testcase C++11 strongly typed enums runtime test for python fix for nested template defined out of class (issue #265) C++11 strongly typed enum support Add Java runtime testcases for C++11 strongly typed enums add director_nested_class to list of broken tests Add C# support for wrapping C++11 strongly typed enums Enhance strongly typed enums testcase ... Conflicts: .travis.yml
Diffstat (limited to 'Lib/lua')
-rw-r--r--Lib/lua/lua.swg3
-rw-r--r--Lib/lua/lua_fnptr.i1
-rw-r--r--Lib/lua/luarun.swg276
-rw-r--r--Lib/lua/luaruntime.swg4
-rw-r--r--Lib/lua/typemaps.i2
5 files changed, 166 insertions, 120 deletions
diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg
index 60e418596..892d15798 100644
--- a/Lib/lua/lua.swg
+++ b/Lib/lua/lua.swg
@@ -44,6 +44,9 @@
%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE []
{ SWIG_LUA_CONSTTAB_POINTER("$symname",$value, $1_descriptor) }
+%typemap(consttab) SWIGTYPE
+ { SWIG_LUA_CONSTTAB_POINTER("$symname",&$value, $&1_descriptor) }
+
// member function pointers
%typemap(consttab) SWIGTYPE (CLASS::*)
{ SWIG_LUA_CONSTTAB_BINARY("$symname", sizeof($type),&$value, $1_descriptor) }
diff --git a/Lib/lua/lua_fnptr.i b/Lib/lua/lua_fnptr.i
index 4e2c8dc6a..481cfafa6 100644
--- a/Lib/lua/lua_fnptr.i
+++ b/Lib/lua/lua_fnptr.i
@@ -103,7 +103,6 @@ void swiglua_ref_clear(SWIGLUA_REF* pref){
}
void swiglua_ref_set(SWIGLUA_REF* pref,lua_State* L,int idx){
-// swiglua_ref_clear(pref); /* just in case */
pref->L=L;
lua_pushvalue(L,idx); /* copy obj to top */
pref->ref=luaL_ref(L,LUA_REGISTRYINDEX); /* remove obj from top & put into registry */
diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg
index d038f4af1..d9124887d 100644
--- a/Lib/lua/luarun.swg
+++ b/Lib/lua/luarun.swg
@@ -268,7 +268,7 @@ typedef struct swig_lua_class {
swig_lua_method *methods;
swig_lua_attribute *attributes;
swig_lua_namespace *cls_static;
- swig_lua_method *metatable; // 0 for -eluac
+ swig_lua_method *metatable; /* 0 for -eluac */
struct swig_lua_class **bases;
const char **base_names;
} swig_lua_class;
@@ -392,8 +392,9 @@ static int swig_lua_elua_emulate_unique_key;
/* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */
SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table)
{
+ int i, table_parsed, parsed_tables_array, target_table;
assert(lua_istable(L,-1));
- int target_table = lua_gettop(L);
+ target_table = lua_gettop(L);
/* Get the registry where we put all parsed tables to avoid loops */
lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
if(lua_isnil(L,-1)) {
@@ -402,11 +403,10 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
lua_pushvalue(L,-1);
lua_rawsetp(L,LUA_REGISTRYINDEX,(void*)(&swig_lua_elua_emulate_unique_key));
}
- int parsed_tables_array = lua_gettop(L);
+ parsed_tables_array = lua_gettop(L);
lua_pushvalue(L,target_table);
lua_rawsetp(L, parsed_tables_array, table);
- int i;
- int table_parsed = 0;
+ table_parsed = 0;
const int SWIGUNUSED pairs_start = lua_gettop(L);
for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
{
@@ -606,7 +606,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss);
/* helper function - register namespace methods and attributes into namespace */
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns)
{
- int i = 0;
+ int i;
/* There must be namespace table (not metatable) at the top of the stack */
assert(lua_istable(L,-1));
SWIG_Lua_InstallConstants(L, ns->ns_constants);
@@ -630,10 +630,12 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *
/* Register all classes in the namespace */
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
{
+ swig_lua_class **classes;
+
/* There must be a module/namespace table at the top of the stack */
assert(lua_istable(L,-1));
- swig_lua_class **classes = ns->ns_classes;
+ classes = ns->ns_classes;
if( classes != 0 ) {
while(*classes != 0) {
@@ -650,6 +652,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace
*/
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
{
+ swig_lua_namespace **sub_namespace;
/* 1 argument - table on the top of the stack */
const int SWIGUNUSED begin = lua_gettop(L);
assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
@@ -681,7 +684,7 @@ SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns
/* Register classes */
SWIG_Lua_add_namespace_classes(L,ns);
- swig_lua_namespace **sub_namespace = ns->ns_namespaces;
+ sub_namespace = ns->ns_namespaces;
if( sub_namespace != 0) {
while(*sub_namespace != 0) {
SWIG_Lua_namespace_register(L, *sub_namespace, 1);
@@ -705,46 +708,6 @@ SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns
SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
-/* Macros for iteration among class bases */
-#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
-#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\
- (void)swig_type;\
- SWIG_Lua_get_table(L,".bases");\
- assert(lua_istable(L,-1));\
- bases_count = lua_rawlen(L,-1);\
- const int bases_table = lua_gettop(L);
-#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\
- lua_rawgeti(L,bases_table,i+1);\
- base_swig_type = 0;\
- if(lua_isnil(L,-1)) {\
- valid = 0;\
- lua_pop(L,1);\
- } else\
- valid = 1;
-
-#else /* In elua .bases table doesn't exist. Use table from swig_lua_class */
-
-#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\
- assert(swig_type!=0);\
- swig_module_info *module=SWIG_GetModule(L);\
- swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\
- const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\
- bases_count = 0;\
- for(;base_names[bases_count];bases_count++);/* get length of bases */
-
-#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\
- swig_lua_class *base_class = bases[i];\
- if(!base_class)\
- valid = 0;\
- else {\
- valid = 1;\
- SWIG_Lua_get_class_metatable(L,base_class->fqname);\
- base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]);\
- assert(base_swig_type != 0);\
- }
-
-#endif
-
typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret);
SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED swig_type,
@@ -753,27 +716,70 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
/* first_arg - position of the object in stack. Everything that is above are arguments
* and is passed to every evocation of the func */
int last_arg = lua_gettop(L);/* position of last argument */
- lua_getmetatable(L,first_arg);
int original_metatable = last_arg + 1;
size_t bases_count;
- SWIG_LUA_INIT_BASE_SEARCH(bases_count);
int result = SWIG_ERROR;
+ int bases_table;
+ (void)swig_type;
+ lua_getmetatable(L,first_arg);
+
+ /* initialise base search */
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+ SWIG_Lua_get_table(L,".bases");
+ assert(lua_istable(L,-1));
+ bases_count = lua_rawlen(L,-1);
+ bases_table = lua_gettop(L);
+#else
+ /* In elua .bases table doesn't exist. Use table from swig_lua_class */
+ (void)bases_table;
+ assert(swig_type!=0);
+ swig_module_info *module=SWIG_GetModule(L);
+ swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;
+ const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;
+ bases_count = 0;
+ for(;base_names[bases_count];
+ bases_count++);/* get length of bases */
+#endif
+
if(ret)
*ret = 0;
if(bases_count>0)
{
+ int to_remove;
size_t i;
int j;
+ int subcall_last_arg;
int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
int valid = 1;
+ swig_type_info *base_swig_type = 0;
for(j=first_arg;j<=last_arg;j++)
lua_pushvalue(L,j);
- int subcall_last_arg = lua_gettop(L);
- swig_type_info *base_swig_type = 0;
+ subcall_last_arg = lua_gettop(L);
/* Trick: temporarily replacing original metatable with metatable for base class and call getter */
for(i=0;i<bases_count;i++) {
- SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid);
+ /* Iteration through class bases */
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+ lua_rawgeti(L,bases_table,i+1);
+ base_swig_type = 0;
+ if(lua_isnil(L,-1)) {
+ valid = 0;
+ lua_pop(L,1);
+ } else {
+ valid = 1;
+ }
+#else /* In elua .bases table doesn't exist. Use table from swig_lua_class */
+ swig_lua_class *base_class = bases[i];
+ if(!base_class) {
+ valid = 0;
+ } else {
+ valid = 1;
+ SWIG_Lua_get_class_metatable(L,base_class->fqname);
+ base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]);
+ assert(base_swig_type != 0);
+ }
+#endif
+
if(!valid)
continue;
assert(lua_isuserdata(L, subcall_first_arg));
@@ -789,7 +795,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
lua_pushvalue(L,original_metatable);
lua_setmetatable(L,first_arg);
/* Clear - remove everything between last_arg and subcall_last_arg including */
- const int to_remove = subcall_last_arg - last_arg;
+ to_remove = subcall_last_arg - last_arg;
for(j=0;j<to_remove;j++)
lua_remove(L,last_arg+1);
} else {
@@ -810,6 +816,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
(1) userdata (not the meta table)
(2) string name of the attribute
*/
+ int bases_search_result;
int substack_start = lua_gettop(L)-2;
assert(first_arg == substack_start+1);
lua_checkstack(L,5);
@@ -862,8 +869,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
/* Remove the metatable */
lua_pop(L,1);
/* Search in base classes */
-
- int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
+ bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
return bases_search_result; /* sorry not known */
}
@@ -875,11 +881,14 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State *L)
(1) userdata (not the meta table)
(2) string name of the attribute
*/
- assert(lua_isuserdata(L,1));
- swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
- swig_type_info *type = usr->type;
+ int result;
+ swig_lua_userdata *usr;
+ swig_type_info *type;
int ret = 0;
- int result = SWIG_Lua_class_do_get(L,type,1,&ret);
+ assert(lua_isuserdata(L,1));
+ usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
+ type = usr->type;
+ result = SWIG_Lua_class_do_get(L,type,1,&ret);
if(result == SWIG_OK)
return ret;
@@ -897,6 +906,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
(3) any for the new value
*/
+ int bases_search_result;
int substack_start = lua_gettop(L) - 3;
lua_checkstack(L,5);
assert(lua_isuserdata(L,substack_start+1)); /* just in case */
@@ -940,7 +950,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
lua_pop(L,1); /* remove metatable */
/* Search among bases */
- int bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
+ bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
if(ret)
assert(*ret == 0);
assert(lua_gettop(L) == substack_start + 3);
@@ -957,11 +967,14 @@ SWIGINTERN int SWIG_Lua_class_set(lua_State *L)
(2) string name of the attribute
(3) any for the new value
*/
- assert(lua_isuserdata(L,1));
- swig_lua_userdata *usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
- swig_type_info *type = usr->type;
int ret = 0;
- int result = SWIG_Lua_class_do_set(L,type,1,&ret);
+ int result;
+ swig_lua_userdata *usr;
+ swig_type_info *type;
+ assert(lua_isuserdata(L,1));
+ usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
+ type = usr->type;
+ result = SWIG_Lua_class_do_set(L,type,1,&ret);
if(result != SWIG_OK) {
SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method.");
lua_error(L);
@@ -997,13 +1010,15 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
+ const char *className;
+ void* userData;
assert(lua_isuserdata(L,1)); /* just in case */
- void* userData = lua_touserdata(L,1); /* get the userdata address for later */
+ userData = 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);
+ className = lua_tostring(L, -1);
lua_pushfstring(L, "<%s userdata: %p>", className, userData);
return 1;
@@ -1022,6 +1037,23 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
return 0;
}
+/* lua callable function to compare userdata's value
+the issue is that two userdata may point to the same thing
+but to lua, they are different objects */
+SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L)
+{
+ int result;
+ swig_lua_userdata *usr1,*usr2;
+ if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */
+ return 0; /* nil reply */
+ usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
+ usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
+ /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
+ result=(usr1->ptr==usr2->ptr);
+ lua_pushboolean(L,result);
+ return 1;
+}
+
/* populate table at the top of the stack with metamethods that ought to be inherited */
SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
{
@@ -1129,7 +1161,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
/* Merges two tables */
-SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source)
+SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source)
{
/* iterating */
lua_pushnil(L);
@@ -1145,7 +1177,7 @@ SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int sour
}
/* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
-SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
+SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
{
/* push original[name], then base[name] */
lua_pushstring(L,name);
@@ -1160,7 +1192,7 @@ SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int origina
}
/* Function takes all symbols from base and adds it to derived class. It's just a helper. */
-SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
+SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
{
/* There is one parameter - original, i.e. 'derived' class metatable */
assert(lua_istable(L,-1));
@@ -1174,7 +1206,7 @@ SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls
}
/* Function squashes all symbols from 'clss' bases into itself */
-SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
+SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
{
int i;
SWIG_Lua_get_class_metatable(L,clss->fqname);
@@ -1231,10 +1263,10 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
{
int i;
+ size_t bases_count = 0;
/* Add bases to .bases table */
SWIG_Lua_get_table(L,".bases");
assert(lua_istable(L,-1)); /* just in case */
- size_t bases_count = 0;
for(i=0;clss->bases[i];i++)
{
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
@@ -1289,7 +1321,7 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration
/* The real function that resolves a metamethod.
* Function searches given class and all it's bases(recursively) for first instance of something that is
- * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actuall metamethod implementation
+ * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation
* and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
* answer.
* Returns 1 if found, 0 otherwise.
@@ -1303,6 +1335,9 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
int skip_check)
{
/* This function is called recursively */
+ int result = 0;
+ int i = 0;
+
if (!skip_check) {
SWIG_Lua_get_class_metatable(L, clss->fqname);
lua_pushvalue(L, metamethod_name_idx);
@@ -1319,8 +1354,6 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
}
/* Forwarding calls to bases */
- int result = 0;
- int i = 0;
for(i=0;clss->bases[i];i++)
{
result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
@@ -1335,21 +1368,26 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
* and calls it */
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
{
+ int numargs;
+ int metamethod_name_idx;
+ const swig_lua_class* clss;
+ int result;
+
lua_checkstack(L,5);
- const int numargs = lua_gettop(L); /* number of arguments to pass to actuall metamethod */
+ numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
/* Get upvalues from closure */
lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
- const int metamethod_name_idx = lua_gettop(L);
+ metamethod_name_idx = lua_gettop(L);
lua_pushvalue(L, lua_upvalueindex(2));
- const swig_lua_class* clss = (const swig_lua_class*)(lua_touserdata(L,-1));
+ clss = (const swig_lua_class*)(lua_touserdata(L,-1));
lua_pop(L,1); /* remove lightuserdata with clss from stack */
- /* Actuall work */
- const int result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
+ /* Actual work */
+ result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
if (!result) {
- SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actuall metamethod. Memory corruption is most likely explanation.");
+ SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation.");
lua_error(L);
return 0;
}
@@ -1367,10 +1405,14 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
*/
SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
{
+ int key_index;
+ int success = 0;
+ int i = 0;
+
/* metamethod name - on the top of the stack */
assert(lua_isstring(L,-1));
- const int key_index = lua_gettop(L);
+ key_index = lua_gettop(L);
/* Check whether method is already defined in metatable */
lua_pushvalue(L,key_index); /* copy of the key */
@@ -1382,8 +1424,6 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pop(L,1);
/* Iterating over immediate bases */
- int success = 0;
- int i = 0;
for(i=0;clss->bases[i];i++)
{
const swig_lua_class *base = clss->bases[i];
@@ -1413,11 +1453,16 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
{
+ int metatable_index;
+ int metamethods_info_index;
+ int tostring_undefined;
+ int eq_undefined = 0;
+
SWIG_Lua_get_class_metatable(L, clss->fqname);
- const int metatable_index = lua_gettop(L);
+ metatable_index = lua_gettop(L);
SWIG_Lua_get_inheritable_metamethods(L);
assert(lua_istable(L,-1));
- const int metamethods_info_index = lua_gettop(L);
+ metamethods_info_index = lua_gettop(L);
lua_pushnil(L); /* first key */
while(lua_next(L, metamethods_info_index) != 0 ) {
/* key at index -2, value at index -1 */
@@ -1435,7 +1480,7 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
lua_pushstring(L, "__tostring");
lua_pushvalue(L,-1);
lua_rawget(L,metatable_index);
- const int tostring_undefined = lua_isnil(L,-1);
+ tostring_undefined = lua_isnil(L,-1);
lua_pop(L,1);
if( tostring_undefined ) {
lua_pushcfunction(L, SWIG_Lua_class_tostring);
@@ -1444,6 +1489,18 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
lua_pop(L,1); /* remove copy of the key */
}
+ /* Special handling for __eq method */
+ lua_pushstring(L, "__eq");
+ lua_pushvalue(L,-1);
+ lua_rawget(L,metatable_index);
+ eq_undefined = lua_isnil(L,-1);
+ lua_pop(L,1);
+ if( eq_undefined ) {
+ lua_pushcfunction(L, SWIG_Lua_class_equal);
+ lua_rawset(L, metatable_index);
+ } else {
+ lua_pop(L,1); /* remove copy of the key */
+ }
/* Warning: __index and __newindex are SWIG-defined. For user-defined operator[]
* a __getitem/__setitem method should be defined
*/
@@ -1488,6 +1545,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
{
const int SWIGUNUSED begin = lua_gettop(L);
+ int i;
/* if name already there (class is already registered) then do nothing */
SWIG_Lua_get_class_registry(L); /* get the registry */
lua_pushstring(L,clss->fqname); /* get the name */
@@ -1499,7 +1557,6 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
}
lua_pop(L,2); /* tidy stack */
/* Recursively initialize all bases */
- int i = 0;
for(i=0;clss->bases[i];i++)
{
SWIG_Lua_class_register_instance(L,clss->bases[i]);
@@ -1513,13 +1570,16 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
* It would get us all special methods: __getitem, __add etc.
* This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
*/
- const int new_metatable_index = lua_absindex(L,-1);
- for(i=0;clss->bases[i];i++)
{
- SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
- const int base_metatable = lua_absindex(L,-1);
- SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
- lua_pop(L,1);
+ int new_metatable_index = lua_absindex(L,-1);
+ for(i=0;clss->bases[i];i++)
+ {
+ int base_metatable;
+ SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
+ base_metatable = lua_absindex(L,-1);
+ SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
+ lua_pop(L,1);
+ }
}
/* And now we will overwrite all incorrectly set data */
#endif
@@ -1566,6 +1626,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
{
+ int SWIGUNUSED begin;
assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */
SWIG_Lua_class_register_instance(L,clss);
SWIG_Lua_class_register_static(L,clss);
@@ -1580,7 +1641,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
* | ".set" --> ....
* |=============================== ".instance"
*/
- const int SWIGUNUSED begin = lua_gettop(L);
+ begin = lua_gettop(L);
lua_pushstring(L,clss->cls_static->name);
lua_rawget(L,-2); /* get class static table */
assert(lua_istable(L,-1));
@@ -1604,6 +1665,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss)
{
const int SWIGUNUSED begin = lua_gettop(L);
+ int i;
/* if name already there (class is already registered) then do nothing */
SWIG_Lua_get_class_registry(L); /* get the registry */
lua_pushstring(L,clss->fqname); /* get the name */
@@ -1615,7 +1677,6 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla
}
lua_pop(L,2); /* tidy stack */
/* Recursively initialize all bases */
- int i = 0;
for(i=0;clss->bases[i];i++)
{
SWIG_Lua_elua_class_register_instance(L,clss->bases[i]);
@@ -1629,7 +1690,7 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla
lua_pop(L,1);
assert(lua_gettop(L) == begin);
}
-#endif // elua && eluac
+#endif /* elua && eluac */
/* -----------------------------------------------------------------------------
* Class/structure conversion fns
@@ -1757,23 +1818,6 @@ SWIGRUNTIME int SWIG_Lua_type(lua_State *L)
return 1;
}
-/* lua callable function to compare userdata's value
-the issue is that two userdata may point to the same thing
-but to lua, they are different objects */
-SWIGRUNTIME int SWIG_Lua_equal(lua_State *L)
-{
- int result;
- swig_lua_userdata *usr1,*usr2;
- if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */
- return 0; /* nil reply */
- usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
- usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
- /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
- result=(usr1->ptr==usr2->ptr);
- lua_pushboolean(L,result);
- return 1;
-}
-
/* -----------------------------------------------------------------------------
* global variable support code: class/struct typemap functions
* ----------------------------------------------------------------------------- */
@@ -1831,8 +1875,8 @@ SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
#endif
/* 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()
+In lua 5.0.X it's lua_dostring()
+In lua 5.1.X it's luaL_dostring()
*/
SWIGINTERN int
SWIG_Lua_dostring(lua_State *L, const char *str) {
diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg
index 26dab93f6..8df46e8cb 100644
--- a/Lib/lua/luaruntime.swg
+++ b/Lib/lua/luaruntime.swg
@@ -29,6 +29,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
{
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
+ int globalRegister = 0;
/* start with global table */
lua_pushglobaltable (L);
/* SWIG's internal initialisation */
@@ -39,7 +40,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE)
/* add a global fn */
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
- SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
+ SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_class_equal);
#endif
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
@@ -49,7 +50,6 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
}
}
- int globalRegister = 0;
#ifdef SWIG_LUA_MODULE_GLOBAL
globalRegister = 1;
#endif
diff --git a/Lib/lua/typemaps.i b/Lib/lua/typemaps.i
index 7a095a1e0..c662cd31e 100644
--- a/Lib/lua/typemaps.i
+++ b/Lib/lua/typemaps.i
@@ -296,7 +296,7 @@ This is one giant macro to define the typemaps & the helpers
for array handling
*/
%define SWIG_TYPEMAP_NUM_ARR(NAME,TYPE)
-%{SWIG_DECLARE_TYPEMAP_ARR_FN(NAME,TYPE);%}
+%{SWIG_DECLARE_TYPEMAP_ARR_FN(NAME,TYPE)%}
// fixed size array's
%typemap(in) TYPE INPUT[ANY]