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;
6
6
public class MyWattleData
7
7
{
8
8
public string Value = "" ;
9
- public void SetString ( string value )
10
- {
11
- Value = value ;
12
- }
13
9
14
10
public int Add4 ( int a )
15
11
{
16
12
return a + 4 ;
17
13
}
14
+
15
+ public MyWattleData ( )
16
+ {
17
+ }
18
+
19
+ public MyWattleData ( string value )
20
+ {
21
+ Value = value ;
22
+ }
18
23
}
Original file line number Diff line number Diff line change @@ -12,6 +12,17 @@ public void Setup()
12
12
LuaHardwire_WattleScript_HardwireGen_Test . Initialize ( ) ;
13
13
}
14
14
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
+
15
26
[ Test ]
16
27
public void CallMethod ( )
17
28
{
Original file line number Diff line number Diff line change @@ -166,7 +166,11 @@ static HardwireType FromTypeSymbol(INamedTypeSymbol symbol)
166
166
if ( method . MethodKind == MethodKind . Constructor )
167
167
{
168
168
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
+ }
170
174
methods [ "__new" ] . AddMethod ( 0 , method ) ;
171
175
}
172
176
else
You can’t perform that action at this time.
0 commit comments