Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ac5d920

Browse files
committed
[[ Script ]] Add ability to query a handler value bound to an instance
This patch adds a QueryHandlerOfInstance API which allows creation of a handler-ref which will invoke a specified handler within a given instance.
1 parent 9ed29f3 commit ac5d920

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

libscript/include/libscript/script.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ bool MCScriptCallHandlerOfInstance(MCScriptInstanceRef instance, MCNameRef handl
251251
// Call a handler of an instance if found, it doesn't throw an error if not.
252252
bool MCScriptCallHandlerOfInstanceIfFound(MCScriptInstanceRef instance, MCNameRef handler, MCValueRef *arguments, uindex_t argument_count, MCValueRef& r_value);
253253

254+
// Create a handler-ref for the given handler in the instance.
255+
bool MCScriptCopyHandlerOfInstance(MCScriptInstanceRef instance, MCNameRef handler, /* copy */ MCHandlerRef& r_handler);
256+
254257
////////////////////////////////////////////////////////////////////////////////
255258

256259
enum MCScriptBytecodeParameterType

libscript/src/script-instance.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,7 @@ bool MCScriptCallHandlerOfInstance(MCScriptInstanceRef self, MCNameRef p_handler
786786
bool MCScriptCallHandlerOfInstanceIfFound(MCScriptInstanceRef self, MCNameRef p_handler, MCValueRef *p_arguments, uindex_t p_argument_count, MCValueRef& r_value)
787787
{
788788
__MCScriptValidateObjectAndKind__(self, kMCScriptObjectKindInstance);
789-
790-
// Lookup the definition (throws if not found).
789+
791790
MCScriptHandlerDefinition *t_definition;
792791
if (!MCScriptLookupHandlerDefinitionInModule(self -> module, p_handler, t_definition))
793792
{
@@ -798,6 +797,20 @@ bool MCScriptCallHandlerOfInstanceIfFound(MCScriptInstanceRef self, MCNameRef p_
798797
return MCScriptCallHandlerOfInstanceDirect(self, t_definition, p_arguments, p_argument_count, r_value);
799798
}
800799

800+
bool MCScriptCopyHandlerOfInstance(MCScriptInstanceRef self, MCNameRef p_name, MCHandlerRef& r_handler)
801+
{
802+
__MCScriptValidateObjectAndKind__(self, kMCScriptObjectKindInstance);
803+
804+
// Lookup the definition (throws if not found).
805+
MCScriptHandlerDefinition *t_definition;
806+
if (!MCScriptLookupHandlerDefinitionInModule(self -> module, p_name, t_definition))
807+
{
808+
return MCScriptThrowHandlerNotFoundError(self -> module, p_name);
809+
}
810+
811+
return MCScriptEvaluateHandlerOfInstanceInternal(self, t_definition, r_handler);
812+
}
813+
801814
////////////////////////////////////////////////////////////////////////////////
802815

803816
struct MCScriptFrameContext

0 commit comments

Comments
 (0)