Skip to content

Commit 2a3d91f

Browse files
committed
[[ Script ]] Add the ability to query the parameter names of a handler
This patch adds CopyHandlerParametersOfModule API which allows fetching the list of parameter names of the specified handler (as long as debug information hasn't been stripped from the module). It also renames CopyHandlerOfModule to CopyHandlerSignatureOfModule and updates uses of the function.
1 parent ac5d920 commit 2a3d91f

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

engine/src/exec-extension.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Exec_stat MCEngineHandleLibraryMessage(MCNameRef p_message, MCParameter *p_param
345345
t_ext = *(MCLoadedExtension **)MCForeignValueGetContentsPtr(t_ptr);
346346

347347
MCTypeInfoRef t_signature;
348-
MCScriptQueryHandlerOfModule(t_ext -> module, p_message, t_signature);
348+
MCScriptQueryHandlerSignatureOfModule(t_ext -> module, p_message, t_signature);
349349

350350
uindex_t t_arg_count;
351351
t_arg_count = MCHandlerTypeInfoGetParameterCount(t_signature);

engine/src/widget-ref.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bool MCWidgetBase::HasProperty(MCNameRef p_property)
148148
bool MCWidgetBase::HasHandler(MCNameRef p_handler)
149149
{
150150
MCTypeInfoRef t_signature;
151-
return MCScriptQueryHandlerOfModule(MCScriptGetModuleOfInstance(m_instance), p_handler, t_signature);
151+
return MCScriptQueryHandlerSignatureOfModule(MCScriptGetModuleOfInstance(m_instance), p_handler, t_signature);
152152
}
153153

154154
bool MCWidgetBase::SetProperty(MCNameRef p_property, MCValueRef p_value)
@@ -223,7 +223,7 @@ bool MCWidgetBase::QueryPropertyOfChunk(MCNameRef p_property, MCNameRef p_chunk_
223223
return false;
224224

225225
MCTypeInfoRef t_handler_typeinfo;
226-
if (!MCScriptQueryHandlerOfModule(MCScriptGetModuleOfInstance(m_instance), *t_handler, t_handler_typeinfo))
226+
if (!MCScriptQueryHandlerSignatureOfModule(MCScriptGetModuleOfInstance(m_instance), *t_handler, t_handler_typeinfo))
227227
return false;
228228

229229
if (p_is_getter)

libscript/include/libscript/script.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ bool MCScriptQueryEventOfModule(MCScriptModuleRef module, MCNameRef event, /* ge
206206
bool MCScriptCopyHandlersOfModule(MCScriptModuleRef module, /* copy */ MCProperListRef& r_handler_names);
207207

208208
// Query the signature of the given handler.
209-
bool MCScriptQueryHandlerOfModule(MCScriptModuleRef module, MCNameRef handler, /* get */ MCTypeInfoRef& r_signature);
209+
bool MCScriptQueryHandlerSignatureOfModule(MCScriptModuleRef module, MCNameRef handler, /* get */ MCTypeInfoRef& r_signature);
210+
211+
// Copy the names of the parameters in the signature of the given handler.
212+
// Note: If the module has had debugging info stripped, the list will be all
213+
// empty names.
214+
bool MCScriptCopyHandlerParametersOfModule(MCScriptModuleRef module, MCNameRef handler, /* copy */ MCProperListRef& r_names);
210215

211216
// Emit an interface definition for the module.
212217
bool MCScriptWriteInterfaceOfModule(MCScriptModuleRef module, MCStreamRef stream);

libscript/src/script-module.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ bool MCScriptCopyHandlersOfModule(MCScriptModuleRef self, /* copy */ MCProperLis
980980
r_handler_names);
981981
}
982982

983-
bool MCScriptQueryHandlerOfModule(MCScriptModuleRef self, MCNameRef p_handler, /* get */ MCTypeInfoRef& r_signature)
983+
bool MCScriptQueryHandlerSignatureOfModule(MCScriptModuleRef self, MCNameRef p_handler, /* get */ MCTypeInfoRef& r_signature)
984984
{
985985
MCScriptHandlerDefinition *t_def;
986986

@@ -995,6 +995,42 @@ bool MCScriptQueryHandlerOfModule(MCScriptModuleRef self, MCNameRef p_handler, /
995995
return true;
996996
}
997997

998+
bool MCScriptCopyHandlerParametersOfModule(MCScriptModuleRef self, MCNameRef p_handler, /* copy */ MCProperListRef& r_names)
999+
{
1000+
MCScriptHandlerDefinition *t_def;
1001+
1002+
if (!self -> is_usable)
1003+
{
1004+
return false; // TODO - throw error
1005+
}
1006+
1007+
if (!MCScriptLookupHandlerDefinitionInModule(self, p_handler, t_def))
1008+
{
1009+
return false; // TODO - throw error
1010+
}
1011+
1012+
MCAutoProperListRef t_names;
1013+
if (!MCProperListCreateMutable(&t_names))
1014+
{
1015+
return false;
1016+
}
1017+
1018+
for(uindex_t i = 0; i < MCHandlerTypeInfoGetParameterCount(self->types[t_def->type]->typeinfo); i++)
1019+
{
1020+
if (!MCProperListPushElementOntoBack(*t_names,
1021+
MCScriptGetNameOfParameterInModule(self,
1022+
t_def,
1023+
i)))
1024+
{
1025+
return false;
1026+
}
1027+
}
1028+
1029+
r_names = t_names.Take();
1030+
1031+
return true;
1032+
}
1033+
9981034
////////////////////////////////////////////////////////////////////////////////
9991035

10001036
bool MCScriptWriteRawModule(MCStreamRef stream, MCScriptModule *p_module)

toolchain/lc-compile/src/lc-run.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ MCRunListHandlers (MCScriptModuleRef p_module)
450450
kMCNameTypeInfo));
451451
t_handler_name = (MCNameRef) t_handler_val;
452452

453-
if (!MCScriptQueryHandlerOfModule (p_module, t_handler_name,
454-
t_signature))
453+
if (!MCScriptQueryHandlerSignatureOfModule (p_module, t_handler_name,
454+
t_signature))
455455
return false;
456456

457457
/* Only accept handlers with arity 0 */

0 commit comments

Comments
 (0)