File tree Expand file tree Collapse file tree 6 files changed +62
-15
lines changed Expand file tree Collapse file tree 6 files changed +62
-15
lines changed Original file line number Diff line number Diff line change 3737 - uses : actions/checkout@v4
3838
3939 - name : Setup emsdk
40- uses : mymindstorm/setup-emsdk@v11
40+ uses : mymindstorm/setup-emsdk@v14
4141 with :
4242 version : ${{ env.EMSCRIPTEN_VERSION }}
4343 actions-cache-folder : emsdk-cache-${{ runner.os }}
Original file line number Diff line number Diff line change @@ -252,7 +252,12 @@ public void SetupPasses(ILibrary library)
252252
253253 passes . AddPass ( new CleanInvalidDeclNamesPass ( ) ) ;
254254 passes . AddPass ( new FastDelegateToDelegatesPass ( ) ) ;
255- passes . AddPass ( new FieldToPropertyPass ( ) ) ;
255+
256+ if ( Options . GeneratorKind != GeneratorKind . Emscripten )
257+ {
258+ passes . AddPass ( new FieldToPropertyPass ( ) ) ;
259+ }
260+
256261 passes . AddPass ( new CheckIgnoredDeclsPass ( ) ) ;
257262 passes . AddPass ( new CheckEnumsPass ( ) ) ;
258263 passes . AddPass ( new MakeProtectedNestedTypesPublicPass ( ) ) ;
@@ -283,9 +288,14 @@ public void SetupPasses(ILibrary library)
283288
284289 passes . AddPass ( new CheckDuplicatedNamesPass ( ) ) ;
285290
286- if ( Options . IsCLIGenerator || Options . IsCSharpGenerator )
291+ if ( Options . IsCLIGenerator || Options . IsCSharpGenerator
292+ || Options . GeneratorKind . ID is GeneratorKind . Emscripten_ID )
287293 {
288294 passes . RenameDeclsUpperCase ( RenameTargets . Any & ~ RenameTargets . Parameter ) ;
295+ }
296+
297+ if ( Options . IsCLIGenerator || Options . IsCSharpGenerator )
298+ {
289299 passes . AddPass ( new CheckKeywordNamesPass ( ) ) ;
290300 }
291301
Original file line number Diff line number Diff line change @@ -117,11 +117,6 @@ public override void VisitClassConstructors(IEnumerable<Method> ctors)
117117 }
118118 }
119119
120- public override bool VisitProperty ( Property property )
121- {
122- return true ;
123- }
124-
125120 public override bool VisitMethodDecl ( Method method )
126121 {
127122 Indent ( ) ;
@@ -130,9 +125,33 @@ public override bool VisitMethodDecl(Method method)
130125 return ret ;
131126 }
132127
128+ public override bool VisitProperty ( Property property )
129+ {
130+ if ( property . Field != null )
131+ return property . Field . Visit ( this ) ;
132+
133+ if ( ! property . GetMethod . IsConst )
134+ {
135+ Console . WriteLine ( $ "Cannot bind non-const property getter method: { property . GetMethod . QualifiedOriginalName } ") ;
136+ return false ;
137+ }
138+
139+ var @class = property . Namespace as Class ;
140+ Indent ( ) ;
141+ Write ( $ ".property(\" { property . Name } \" , &{ @class . QualifiedOriginalName } ::{ property . GetMethod . OriginalName } ") ;
142+
143+ if ( property . HasSetter )
144+ Write ( $ ", &{ @class . QualifiedOriginalName } ::{ property . SetMethod . OriginalName } ") ;
145+
146+ WriteLine ( ")" ) ;
147+ Unindent ( ) ;
148+
149+ return true ;
150+ }
151+
133152 public override bool VisitFieldDecl ( Field field )
134153 {
135- WriteLineIndent ( $ ".field (\" { field . Name } \" , &{ field . Class . QualifiedOriginalName } ::{ field . OriginalName } )") ;
154+ WriteLineIndent ( $ ".property (\" { field . Name } \" , &{ field . Class . QualifiedOriginalName } ::{ field . OriginalName } )") ;
136155 return true ;
137156 }
138157
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ class Class
66{
77public:
88 void ReturnsVoid () {}
9- int ReturnsInt () { return 0 ; }
10- // Class* PassAndReturnsClassPtr(Class* obj) { return obj; }
9+ int ReturnsInt () const { return 0 ; }
10+ Class * PassAndReturnsClassPtr (Class * obj) { return obj; }
1111};
1212
1313class ClassWithField
@@ -18,9 +18,20 @@ class ClassWithField
1818 {
1919 }
2020 int Field;
21- int ReturnsField () { return Field; }
21+ int ReturnsField () const { return Field; }
2222};
2323
24+ class ClassWithProperty
25+ {
26+ public:
27+ ClassWithProperty () : Field(10 ) {}
28+ int GetField () const { return Field; }
29+ void SetField (int value) { Field = value; }
30+ private:
31+ int Field;
32+ };
33+
34+
2435class ClassWithOverloads
2536{
2637public:
Original file line number Diff line number Diff line change @@ -111,7 +111,14 @@ function classes() {
111111
112112 var classWithField = new test . ClassWithField ( ) ;
113113 eq ( classWithField . ReturnsField ( ) , 10 ) ;
114- //eq(classWithField.Field, 10);
114+ eq ( classWithField . Field , 10 ) ;
115+ classWithField . Field = 20 ;
116+ eq ( classWithField . ReturnsField ( ) , 20 ) ;
117+
118+ var classWithProperty = new test . ClassWithProperty ( ) ;
119+ eq ( classWithProperty . Field , 10 ) ;
120+ classWithProperty . Field = 20 ;
121+ eq ( classWithProperty . Field , 20 ) ;
115122}
116123
117124builtins ( ) ;
Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ generate=true
3838
3939if [ $generate = true ]; then
4040 echo " ${green} Generating bindings${reset} "
41- dotnet $rootdir /bin/${dotnet_configuration} /CppSharp.CLI.dll \
42- --gen=emscripten --platform=emscripten --arch=wasm32 \
41+ dotnet $rootdir /bin/${dotnet_configuration} _ ${platform} /CppSharp.CLI.dll \
42+ --gen=emscripten --platform=emscripten --arch=wasm32 --property=keywords \
4343 -I$dir /.. -I$rootdir /include -o $dir /gen -m tests $dir /../* .h
4444fi
4545
You can’t perform that action at this time.
0 commit comments