@@ -520,6 +520,12 @@ public virtual void GenerateClassDeclDeclarationList(Class @class, DetachmentOpt
520
520
if ( detachment == DetachmentOption . Off )
521
521
{
522
522
GenerateConstructors ( @class , @class . Constructors ) ;
523
+
524
+ var methods = @class . Methods . Where ( method => ! ( method . IsConstructor || method . IsDestructor || method . IsOperator ) ) ;
525
+ var uniqueMethods = methods . GroupBy ( m => m . Name ) ;
526
+ foreach ( var group in uniqueMethods )
527
+ GenerateMethods ( @class , group . ToList ( ) ) ;
528
+
523
529
GenerateClassDeclFunctions ( @class ) ;
524
530
GenerateClassDeclVariables ( @class ) ;
525
531
}
@@ -906,21 +912,21 @@ public virtual void GenerateConstructors(Class @class, IEnumerable<Method> const
906
912
}
907
913
}
908
914
909
- public virtual bool CanGenerateConstructor ( Method method )
915
+ public virtual bool CanGenerateConstructor ( Method constructor )
910
916
{
911
- if ( AlreadyVisited ( method ) )
917
+ if ( AlreadyVisited ( constructor ) )
912
918
{
913
919
return false ;
914
920
}
915
- else if ( method . Access != AccessSpecifier . Public )
921
+ else if ( constructor . Access != AccessSpecifier . Public )
916
922
{
917
923
return false ;
918
924
}
919
925
else if ( ! NonTemplateAllowed )
920
926
{
921
927
return false ;
922
928
}
923
- return method . IsGenerated ;
929
+ return constructor . IsGenerated ;
924
930
}
925
931
926
932
public virtual void GenerateConstructor ( Class @class , Method constructor , bool doExpand )
@@ -959,5 +965,121 @@ public virtual void GenerateConstructor(Class @class, Method constructor, bool d
959
965
}
960
966
961
967
#endregion
968
+
969
+ #region Method
970
+
971
+ public virtual bool NeedExpansionForMethods ( Class @class , IEnumerable < Method > methods )
972
+ {
973
+ return false ;
974
+ }
975
+
976
+ public virtual void GenerateMethods ( Class @class , IEnumerable < Method > methods )
977
+ {
978
+ var isDetach = GenerationContext . PeekIsDetach ( ) ;
979
+
980
+ List < Method > filteredMethods = methods . Where ( ( method ) => CanGenerateMethod ( method ) ) . ToList ( ) ;
981
+ if ( filteredMethods . Any ( ) )
982
+ {
983
+ Method method = filteredMethods . First ( ) ;
984
+ string methodName = method . Name ;
985
+ string methodNameQuoted = $ "\" { methodName } \" ";
986
+ string methodBindingContext = NamingStrategy . GetBindingContext ( method , GenerationContext ) ;
987
+ string methodContextualName = NamingStrategy . GetContextualName ( method , GenerationContext , FQNOption . IgnoreNone ) ;
988
+
989
+ if ( isDetach == DetachmentOption . Forced || isDetach == Utils . FindDetachmentOption ( method ) )
990
+ {
991
+
992
+ if ( isDetach != DetachmentOption . Off )
993
+ {
994
+ Write ( $ "{ methodBindingContext } [{ methodNameQuoted } ] = ") ;
995
+ }
996
+ else
997
+ {
998
+ WriteLine ( "," ) ;
999
+ Write ( $ "{ methodNameQuoted } , ") ;
1000
+ }
1001
+ if ( filteredMethods . Count == 1 )
1002
+ {
1003
+ GenerateMethod ( @class , filteredMethods . First ( ) ) ;
1004
+ }
1005
+ else
1006
+ {
1007
+ Write ( "::sol::overload(" ) ;
1008
+ Indent ( ) ;
1009
+ for ( int i = 0 ; i < filteredMethods . Count ; i ++ )
1010
+ {
1011
+ if ( i > 0 )
1012
+ {
1013
+ Write ( "," ) ;
1014
+ }
1015
+ NewLine ( ) ;
1016
+ GenerateMethod ( @class , filteredMethods [ i ] ) ;
1017
+ }
1018
+ Unindent ( ) ;
1019
+ NewLine ( ) ;
1020
+ Write ( ")" ) ;
1021
+ }
1022
+ if ( isDetach != DetachmentOption . Off )
1023
+ {
1024
+ WriteLine ( ";" ) ;
1025
+ }
1026
+ }
1027
+ }
1028
+ }
1029
+
1030
+ public virtual bool CanGenerateMethod ( Method method )
1031
+ {
1032
+ if ( AlreadyVisited ( method ) )
1033
+ {
1034
+ return false ;
1035
+ }
1036
+ else if ( method . Access != AccessSpecifier . Public )
1037
+ {
1038
+ return false ;
1039
+ }
1040
+ else if ( ! NonTemplateAllowed )
1041
+ {
1042
+ return false ;
1043
+ }
1044
+ return method . IsGenerated ;
1045
+ }
1046
+
1047
+ public virtual void GenerateMethod ( Class @class , Method method )
1048
+ {
1049
+ {
1050
+ Write ( "static_cast<" ) ;
1051
+ Write ( method . ReturnType . Visit ( new CppTypePrinter ( Context ) ) ) ;
1052
+ Write ( "(" ) ;
1053
+ Write ( "*)" ) ;
1054
+ Write ( "(" ) ;
1055
+ var needsComma = false ;
1056
+ foreach ( var parameter in method . Parameters )
1057
+ {
1058
+ if ( needsComma )
1059
+ {
1060
+ Write ( ", " ) ;
1061
+ }
1062
+ else
1063
+ {
1064
+ needsComma = true ;
1065
+ }
1066
+ Write ( parameter . Type . Visit ( new CppTypePrinter ( Context ) ) ) ;
1067
+ }
1068
+ if ( method . IsVariadic )
1069
+ {
1070
+ if ( needsComma )
1071
+ {
1072
+ Write ( ", " ) ;
1073
+ }
1074
+ Write ( "..." ) ;
1075
+ }
1076
+ Write ( ")" ) ;
1077
+ Write ( ">(&" ) ;
1078
+ Write ( NamingStrategy . GetContextualName ( method , GenerationContext , FQNOption . IgnoreNone ) ) ;
1079
+ Write ( ")" ) ;
1080
+ }
1081
+ }
1082
+
1083
+ #endregion
962
1084
}
963
1085
}
0 commit comments