Skip to content

Commit d652d07

Browse files
committed
[[ ScriptHandlers ]] Add ability to query script handler info
We need to be able to query things like resolved info from the binding string of a foreign handler from libfoundation. This patch adds a query callback to the MCHandlerRef callbacks struct to enable fetching such data. The only specific info made available in this patch is the objc selector pointer.
1 parent 67c6407 commit d652d07

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

libfoundation/include/foundation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,12 +3060,19 @@ MC_DLLEXPORT bool MCRecordIterate(MCRecordRef record, uintptr_t& x_iterator, MCN
30603060
// HANDLER DEFINITIONS
30613061
//
30623062

3063+
enum MCHandlerQueryType
3064+
{
3065+
kMCHandlerQueryTypeNone,
3066+
kMCHandlerQueryTypeObjcSelector,
3067+
};
3068+
30633069
struct MCHandlerCallbacks
30643070
{
30653071
size_t size;
30663072
void (*release)(void *context);
30673073
bool (*invoke)(void *context, MCValueRef *arguments, uindex_t argument_count, MCValueRef& r_value);
30683074
bool (*describe)(void *context, MCStringRef& r_desc);
3075+
bool (*query)(void *context, MCHandlerQueryType type, void *r_info);
30693076
};
30703077

30713078
MC_DLLEXPORT bool MCHandlerCreate(MCTypeInfoRef typeinfo, const MCHandlerCallbacks *callbacks, void *context, MCHandlerRef& r_handler);

libscript/src/script-instance.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,12 +1558,44 @@ __MCScriptInternalHandlerDescribe(void *p_context,
15581558
return MCStringFormat(r_description, "%@.%@()", t_module_name, t_handler_name);
15591559
}
15601560

1561+
static bool
1562+
__MCScriptInternalHandlerQuery(void *p_context,
1563+
MCHandlerQueryType p_query,
1564+
void *r_info)
1565+
{
1566+
if (p_query != kMCHandlerQueryTypeObjcSelector)
1567+
{
1568+
return false;
1569+
}
1570+
1571+
__MCScriptInternalHandlerContext *context =
1572+
(__MCScriptInternalHandlerContext *)p_context;
1573+
1574+
if (context->definition->kind != kMCScriptDefinitionKindForeignHandler)
1575+
{
1576+
return false;
1577+
}
1578+
1579+
auto t_definition =
1580+
static_cast<MCScriptForeignHandlerDefinition *>(context->definition);
1581+
1582+
if (t_definition->language != kMCScriptForeignHandlerLanguageObjC)
1583+
{
1584+
return false;
1585+
}
1586+
1587+
*(void **)r_info = t_definition->objc.objc_selector;
1588+
1589+
return true;
1590+
}
1591+
15611592
static MCHandlerCallbacks __kMCScriptInternalHandlerCallbacks =
15621593
{
15631594
sizeof(__MCScriptInternalHandlerContext),
15641595
__MCScriptInternalHandlerRelease,
15651596
__MCScriptInternalHandlerInvoke,
1566-
__MCScriptInternalHandlerDescribe
1597+
__MCScriptInternalHandlerDescribe,
1598+
__MCScriptInternalHandlerQuery,
15671599
};
15681600

15691601
static bool

0 commit comments

Comments
 (0)