@@ -828,6 +828,45 @@ bool MCScriptEnsureModuleIsUsable(MCScriptModuleRef self)
828828
829829// //////////////////////////////////////////////////////////////////////////////
830830
831+ static bool
832+ __MCScriptCopyDefinitionsOfModule (MCScriptModuleRef self,
833+ MCScriptDefinitionKind p_kind,
834+ /* copy */ MCProperListRef& r_names)
835+ {
836+ MCAutoProperListRef t_names;
837+ if (!MCProperListCreateMutable (&t_names))
838+ {
839+ return false ;
840+ }
841+
842+ for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
843+ {
844+ MCScriptDefinition *t_definition =
845+ self->definitions [self->exported_definitions [i].index ];
846+
847+ if (p_kind != kMCScriptDefinitionKindNone &&
848+ t_definition->kind != p_kind)
849+ {
850+ continue ;
851+ }
852+
853+ if (!MCProperListPushElementOntoBack (*t_names,
854+ self->exported_definitions [i].name ))
855+ {
856+ return false ;
857+ }
858+ }
859+
860+ if (!t_names.MakeImmutable ())
861+ {
862+ return false ;
863+ }
864+
865+ r_names = t_names.Take ();
866+
867+ return true ;
868+ }
869+
831870bool MCScriptCopyDependenciesOfModule (MCScriptModuleRef self, /* copy */ MCProperListRef& r_module_names)
832871{
833872 MCAutoProperListRef t_modules;
@@ -844,21 +883,33 @@ bool MCScriptCopyDependenciesOfModule(MCScriptModuleRef self, /* copy */ MCPrope
844883 return true ;
845884}
846885
886+ bool MCScriptCopyConstantsOfModule (MCScriptModuleRef self, /* copy */ MCProperListRef& r_constant_names)
887+ {
888+ return __MCScriptCopyDefinitionsOfModule (self,
889+ kMCScriptDefinitionKindConstant ,
890+ r_constant_names);
891+ }
892+
893+ bool MCScriptQueryConstantOfModule (MCScriptModuleRef self, MCNameRef p_constant, MCValueRef& r_constant_value)
894+ {
895+ MCScriptConstantDefinition *t_constant_def = nil;
896+ if (!MCScriptLookupConstantDefinitionInModule (self,
897+ p_constant,
898+ t_constant_def))
899+ {
900+ return false ;
901+ }
902+
903+ r_constant_value = self->values [t_constant_def->value ];
904+
905+ return true ;
906+ }
907+
847908bool MCScriptCopyPropertiesOfModule (MCScriptModuleRef self, /* copy */ MCProperListRef& r_property_names)
848909{
849- MCAutoProperListRef t_props;
850- if (!MCProperListCreateMutable (&t_props))
851- return false ;
852-
853- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
854- if (self -> definitions[self -> exported_definitions[i] . index] -> kind == kMCScriptDefinitionKindProperty )
855- if (!MCProperListPushElementOntoBack (*t_props, self -> exported_definitions[i] . name))
856- return false ;
857-
858- if (!MCProperListCopy (*t_props, r_property_names))
859- return false ;
860-
861- return true ;
910+ return __MCScriptCopyDefinitionsOfModule (self,
911+ kMCScriptDefinitionKindProperty ,
912+ r_property_names);
862913}
863914
864915bool MCScriptQueryPropertyOfModule (MCScriptModuleRef self, MCNameRef p_property, /* get */ MCTypeInfoRef& r_getter, /* get */ MCTypeInfoRef& r_setter)
@@ -902,19 +953,9 @@ bool MCScriptQueryPropertyOfModule(MCScriptModuleRef self, MCNameRef p_property,
902953
903954bool MCScriptCopyEventsOfModule (MCScriptModuleRef self, /* copy */ MCProperListRef& r_event_names)
904955{
905- MCAutoProperListRef t_events;
906- if (!MCProperListCreateMutable (&t_events))
907- return false ;
908-
909- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
910- if (self -> definitions[self -> exported_definitions[i] . index] -> kind == kMCScriptDefinitionKindEvent )
911- if (!MCProperListPushElementOntoBack (*t_events, self -> exported_definitions[i] . name))
912- return false ;
913-
914- if (!MCProperListCopy (*t_events, r_event_names))
915- return false ;
916-
917- return true ;
956+ return __MCScriptCopyDefinitionsOfModule (self,
957+ kMCScriptDefinitionKindEvent ,
958+ r_event_names);
918959}
919960
920961bool MCScriptQueryEventOfModule (MCScriptModuleRef self, MCNameRef p_event, /* get */ MCTypeInfoRef& r_signature)
@@ -934,19 +975,9 @@ bool MCScriptQueryEventOfModule(MCScriptModuleRef self, MCNameRef p_event, /* ge
934975
935976bool MCScriptCopyHandlersOfModule (MCScriptModuleRef self, /* copy */ MCProperListRef& r_handler_names)
936977{
937- MCAutoProperListRef t_handlers;
938- if (!MCProperListCreateMutable (&t_handlers))
939- return false ;
940-
941- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
942- if (self -> definitions[self -> exported_definitions[i] . index] -> kind == kMCScriptDefinitionKindHandler )
943- if (!MCProperListPushElementOntoBack (*t_handlers, self -> exported_definitions[i] . name))
944- return false ;
945-
946- if (!MCProperListCopy (*t_handlers, r_handler_names))
947- return false ;
948-
949- return true ;
978+ return __MCScriptCopyDefinitionsOfModule (self,
979+ kMCScriptDefinitionKindHandler ,
980+ r_handler_names);
950981}
951982
952983bool MCScriptQueryHandlerOfModule (MCScriptModuleRef self, MCNameRef p_handler, /* get */ MCTypeInfoRef& r_signature)
@@ -983,78 +1014,115 @@ void MCScriptReleaseRawModule(MCScriptModule *p_module)
9831014
9841015// //////////////////////////////////////////////////////////////////////////////
9851016
986- bool MCScriptLookupPropertyDefinitionInModule (MCScriptModuleRef self, MCNameRef p_property, MCScriptPropertyDefinition*& r_definition)
1017+ static bool
1018+ __MCScriptLookupDefinitionInModule (MCScriptModuleRef self,
1019+ MCScriptDefinitionKind p_kind,
1020+ MCNameRef p_name,
1021+ MCScriptDefinition*& r_definition)
9871022{
988- __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
989-
990- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
1023+ for (uindex_t i = 0 ; i < self->exported_definition_count ; i++)
9911024 {
992- if (self -> definitions[self -> exported_definitions[i] . index] -> kind != kMCScriptDefinitionKindProperty )
1025+ if (p_kind != kMCScriptDefinitionKindNone &&
1026+ self->definitions [self->exported_definitions [i].index ]->kind != p_kind)
1027+ {
9931028 continue ;
1029+ }
9941030
995- if (!MCNameIsEqualTo (p_property, self -> exported_definitions[i] . name))
1031+ if (!MCNameIsEqualTo (p_name,
1032+ self->exported_definitions [i].name ))
1033+ {
9961034 continue ;
997-
998- r_definition = static_cast <MCScriptPropertyDefinition *>(self -> definitions[self -> exported_definitions[i] . index]);
1035+ }
1036+
1037+ r_definition = self->definitions [self->exported_definitions [i].index ];
1038+
9991039 return true ;
10001040 }
10011041
10021042 return false ;
1043+
1044+ }
1045+
1046+ bool MCScriptLookupConstantDefinitionInModule (MCScriptModuleRef self, MCNameRef p_constant, MCScriptConstantDefinition*& r_definition)
1047+ {
1048+ __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
1049+
1050+ MCScriptDefinition *t_definition = nil;
1051+ if (!__MCScriptLookupDefinitionInModule (self,
1052+ kMCScriptDefinitionKindConstant ,
1053+ p_constant,
1054+ t_definition))
1055+ {
1056+ return false ;
1057+ }
1058+
1059+ r_definition = static_cast <MCScriptConstantDefinition *>(t_definition);
1060+
1061+ return true ;
1062+ }
1063+
1064+ bool MCScriptLookupPropertyDefinitionInModule (MCScriptModuleRef self, MCNameRef p_property, MCScriptPropertyDefinition*& r_definition)
1065+ {
1066+ __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
1067+
1068+ MCScriptDefinition *t_definition = nil;
1069+ if (!__MCScriptLookupDefinitionInModule (self,
1070+ kMCScriptDefinitionKindProperty ,
1071+ p_property,
1072+ t_definition))
1073+ {
1074+ return false ;
1075+ }
1076+
1077+ r_definition = static_cast <MCScriptPropertyDefinition *>(t_definition);
1078+
1079+ return true ;
10031080}
10041081
10051082bool MCScriptLookupEventDefinitionInModule (MCScriptModuleRef self, MCNameRef p_property, MCScriptEventDefinition*& r_definition)
10061083{
10071084 __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
1008-
1009- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
1010- {
1011- if (self -> definitions[self -> exported_definitions[i] . index] -> kind != kMCScriptDefinitionKindEvent )
1012- continue ;
1013-
1014- if (!MCNameIsEqualTo (p_property, self -> exported_definitions[i] . name))
1015- continue ;
1016-
1017- r_definition = static_cast <MCScriptEventDefinition *>(self -> definitions[self -> exported_definitions[i] . index]);
1018- return true ;
1019- }
1020-
1021- return false ;
1085+
1086+ MCScriptDefinition *t_definition = nil;
1087+ if (!__MCScriptLookupDefinitionInModule (self,
1088+ kMCScriptDefinitionKindEvent ,
1089+ p_property,
1090+ t_definition))
1091+ {
1092+ return false ;
1093+ }
1094+
1095+ r_definition = static_cast <MCScriptEventDefinition *>(t_definition);
1096+
1097+ return true ;
10221098}
10231099
10241100bool MCScriptLookupHandlerDefinitionInModule (MCScriptModuleRef self, MCNameRef p_handler, MCScriptHandlerDefinition*& r_definition)
10251101{
10261102 __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
1027-
1028- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
1029- {
1030- if (self -> definitions[self -> exported_definitions[i] . index] -> kind != kMCScriptDefinitionKindHandler &&
1031- self -> definitions[self -> exported_definitions[i] . index] -> kind != kMCScriptDefinitionKindForeignHandler )
1032- continue ;
1033-
1034- if (!MCNameIsEqualTo (p_handler, self -> exported_definitions[i] . name))
1035- continue ;
1036-
1037- r_definition = static_cast <MCScriptHandlerDefinition *>(self -> definitions[self -> exported_definitions[i] . index]);
1038- return true ;
1039- }
1040-
1041- return false ;
1103+
1104+ MCScriptDefinition *t_definition = nil;
1105+ if (!__MCScriptLookupDefinitionInModule (self,
1106+ kMCScriptDefinitionKindHandler ,
1107+ p_handler,
1108+ t_definition))
1109+ {
1110+ return false ;
1111+ }
1112+
1113+ r_definition = static_cast <MCScriptHandlerDefinition *>(t_definition);
1114+
1115+ return true ;
10421116}
10431117
10441118bool MCScriptLookupDefinitionInModule (MCScriptModuleRef self, MCNameRef p_name, MCScriptDefinition*& r_definition)
10451119{
10461120 __MCScriptValidateObjectAndKind__ (self, kMCScriptObjectKindModule );
1047-
1048- for (uindex_t i = 0 ; i < self -> exported_definition_count; i++)
1049- {
1050- if (!MCNameIsEqualTo (p_name, self -> exported_definitions[i] . name))
1051- continue ;
1052-
1053- r_definition = static_cast <MCScriptHandlerDefinition *>(self -> definitions[self -> exported_definitions[i] . index]);
1054- return true ;
1055- }
1056-
1057- return false ;
1121+
1122+ return __MCScriptLookupDefinitionInModule (self,
1123+ kMCScriptDefinitionKindNone ,
1124+ p_name,
1125+ r_definition);
10581126}
10591127
10601128// //////////////////////////////////////////////////////////////////////////////
0 commit comments