File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed
WattleScript.HardwireGen.Test Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,18 @@ namespace WattleScript.HardwireGen.Test;
66public class MyWattleData
77{
88 public string Value = "" ;
9- public void SetString ( string value )
10- {
11- Value = value ;
12- }
139
1410 public int Add4 ( int a )
1511 {
1612 return a + 4 ;
1713 }
14+
15+ public MyWattleData ( )
16+ {
17+ }
18+
19+ public MyWattleData ( string value )
20+ {
21+ Value = value ;
22+ }
1823}
Original file line number Diff line number Diff line change @@ -12,6 +12,17 @@ public void Setup()
1212 LuaHardwire_WattleScript_HardwireGen_Test . Initialize ( ) ;
1313 }
1414
15+ [ Test ]
16+ public void Constructor ( )
17+ {
18+ var sc = new Script ( CoreModules . None ) ;
19+ sc . Globals [ "MyWattleData" ] = typeof ( MyWattleData ) ;
20+ var r = sc . DoString ( "return MyWattleData.__new('Hello')" ) ;
21+ Assert . IsInstanceOf < MyWattleData > ( r . ToObject ( ) ) ;
22+ var wd = r . ToObject < MyWattleData > ( ) ;
23+ Assert . AreEqual ( "Hello" , wd . Value ) ;
24+ }
25+
1526 [ Test ]
1627 public void CallMethod ( )
1728 {
Original file line number Diff line number Diff line change @@ -166,7 +166,11 @@ static HardwireType FromTypeSymbol(INamedTypeSymbol symbol)
166166 if ( method . MethodKind == MethodKind . Constructor )
167167 {
168168 if ( ! methods . ContainsKey ( "__new" ) )
169- methods . Add ( "__new" , new TypeMethod ( ) { Constructor = true } ) ;
169+ {
170+ var ctor = new TypeMethod ( ) { Constructor = true } ;
171+ ctor . SetName ( "__new" ) ;
172+ methods . Add ( "__new" , ctor ) ;
173+ }
170174 methods [ "__new" ] . AddMethod ( 0 , method ) ;
171175 }
172176 else
You can’t perform that action at this time.
0 commit comments