Your message dated Mon, 04 Feb 2008 22:36:56 +0100
with message-id <[EMAIL PROTECTED]>
has caused the Debian Bug report #461494,
regarding swig: Lua backend doesn't handle unary minus (__unm) correctly
to be marked as having been forwarded to the upstream software
author(s) [EMAIL PROTECTED]

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Hello List, 

Miles Bader reported a bug in the Debian package of SWIG 1.3.33. Basically, it 
is not possible to wrap unary minus for LUA. 

This seems even to be a known problem, as the test suite for LUA has the tests 
for unary minus commented out. 

I tried to implement a patch to fix this, however, I am not sure if it meets 
your quality requirements. I did not made it too deep into the SWIG sources yet 
so there will probably a better and cleaner way to do this.

But please consider applying the attached patch until a better fix comes up. 

Comments appreciated, Torsten
Index: Source/Modules/lua.cxx
===================================================================
--- Source/Modules/lua.cxx      (revision 10233)
+++ Source/Modules/lua.cxx      (working copy)
@@ -386,6 +386,16 @@
     int num_required = emit_num_required(l);
     int varargs = emit_isvarargs(l);
 
+    // Check if we have to ignore arguments that are passed by LUA.
+    // Needed for unary minus, where lua passes two arguments and 
+    // we have to ignore the second.
+
+    int args_to_ignore = 0;
+    if (Getattr(n, "lua:ignore_args")) {
+        args_to_ignore = GetInt(n, "lua:ignore_args");
+    }
+
+
     /* Which input argument to start with? */
 //    int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current 
== DESTRUCTOR) ? 1 : 0;
 
@@ -412,7 +422,8 @@
 //    String *numoutputs=NULL;
     char source[64];
     //Printf(argument_check, "//args must be 
%d..%d\n",num_required,num_arguments);
-    Printf(argument_check, 
"SWIG_check_num_args(\"%s\",%d,%d)\n",name,num_required,num_arguments);
+    Printf(argument_check, "SWIG_check_num_args(\"%s\",%d,%d)\n",
+        name,num_required + args_to_ignore,num_arguments + args_to_ignore);
     for (i = 0, p = l; i < num_arguments; i++) {
 
       while (checkAttribute(p, "tmap:in:numinputs", "0")) {
@@ -963,6 +974,15 @@
     String *iname = GetChar(n, "sym:name");
 //Printf(stdout,"memberfunctionHandler %s %s\n",name,iname);
 
+    // Special case unary minus: LUA passes two parameters for the 
+    // wrapper function while we want only one. Tell our 
+    // functionWrapper to ignore a parameter.
+
+    if (Cmp(Getattr(n, "sym:name"), "__unm") == 0) {
+       Printf(stdout, "unary minus: ignore one argument\n");
+       SetInt(n, "lua:ignore_args", 1);
+    }
+
     String *realname, *rname;
 
     current = MEMBER_FUNC;
Index: Examples/test-suite/lua/operator_overload_runme.lua
===================================================================
--- Examples/test-suite/lua/operator_overload_runme.lua (revision 10233)
+++ Examples/test-suite/lua/operator_overload_runme.lua (working copy)
@@ -48,13 +48,10 @@
 
 --lua 5.0.2 defines that unary - is __unm(self,nil)
 --lua 5.1.2 defines that unary - is __unm(self,self)
+--SWIG handles this by ignoring the last argument to the wrapper function
 --C++ expectes unary - as operator-()
---however the latest version of SWIG strictly checks the number of args
---and will complain if too many args are provided
---therefore disabling these tests for now
--- (solution will to be not to check args for this test case)
---assert(-a==a)
---assert(-b==Op(-5))
+assert(-a==a)
+assert(-b==Op(-5))
 
 -- test []
 h=Op(3)

--- End Message ---

Reply via email to