Hi fellow haxers,
I am using a python scripting mod that supports ironpython 2.7.5 and one that supports ironpython 3.0.0.0.
I am having the following issue when I run haxe generated python 3 code within ironpython 3 mode, issues which i dont have with a vanilla python 3.0.
haxe code:
package;
class Main
{
static function main()
{
var someB:B = new B(1);
trace(someB.id);
}
}
class A{
public var id:Int;
public function new(id:Int = 0){
this.id = id;
}
}
class B extends A{
public function new(id:Int=1){
super(id);
}
}
generated python code
# Generated by Haxe 3.4.0
# coding: utf-8
class Main:
__slots__ = ()
@staticmethod
def main():
print(str(B(1).id))
class A:
__slots__ = ("id",)
def __init__(self,id = 0):
if (id is None):
id = 0
self.id = id
class B(A):
__slots__ = ()
def __init__(self,id = 1):
if (id is None):
id = 1
super().__init__(id)
Main.main()
output in ironpython 3.0.0.0
TypeError: __init__() takes at least 1 argument (0 given)
output in python 3.4
C:\Python30\python.exe C:/Users/simon/PycharmProjects/untitled3/Test.py
1
Process finished with exit code 0
However if it would look the folowing way it would run just fine with both python vanilla and iron:
class Main:
__slots__ = ()
@staticmethod
def main():
print(str(B(1).id))
class A:
__slots__ = ("id",)
def __init__(self,id = 0):
if (id is None):
id = 0
self.id = id
class B(A):
__slots__ = ()
def __init__(self,id = 1):
if (id is None):
id = 1
A.__init__(self, id)
Main.main()
So can I use macro's to generate different constructor code for python?
So instead of default super(), have it generate A.__init__(self, id)?
Cheers, Simon