@@ -46,6 +46,13 @@ void __MCScriptHandlerRelease(void *context);
4646
4747// //////////////////////////////////////////////////////////////////////////////
4848
49+ // This is the module of the most recent LCB stack frame on the current thread's
50+ // stack. It is set before and after a foreign handler call so that the native
51+ // code can get some element of context.
52+ static MCScriptModuleRef s_current_module = nil;
53+
54+ // //////////////////////////////////////////////////////////////////////////////
55+
4956bool MCScriptCreateInstanceOfModule (MCScriptModuleRef p_module, MCScriptInstanceRef& r_instance)
5057{
5158 bool t_success;
@@ -1604,7 +1611,16 @@ static bool MCScriptPerformInvoke(MCScriptFrame*& x_frame, byte_t*& x_next_bytec
16041611 MCScriptForeignHandlerDefinition *t_foreign_handler;
16051612 t_foreign_handler = MCScriptDefinitionAsForeignHandler (p_handler);
16061613
1607- return MCScriptPerformForeignInvoke (x_frame, p_instance, t_foreign_handler, p_arguments, p_arity);
1614+ MCScriptModuleRef t_previous_module;
1615+ t_previous_module = s_current_module;
1616+ s_current_module = x_frame -> instance -> module ;
1617+
1618+ bool t_success;
1619+ t_success = MCScriptPerformForeignInvoke (x_frame, p_instance, t_foreign_handler, p_arguments, p_arity);
1620+
1621+ s_current_module = t_previous_module;
1622+
1623+ return t_success;
16081624 }
16091625
16101626 /* LOAD CHECK */ __MCScriptUnreachable__ (" non-handler definition passed to invoke" );
@@ -2307,6 +2323,13 @@ bool MCScriptCallHandlerOfInstanceInternal(MCScriptInstanceRef self, MCScriptHan
23072323
23082324// //////////////////////////////////////////////////////////////////////////////
23092325
2326+ MCScriptModuleRef MCScriptGetCurrentModule (void )
2327+ {
2328+ return s_current_module;
2329+ }
2330+
2331+ // //////////////////////////////////////////////////////////////////////////////
2332+
23102333MCHandlerCallbacks __kMCScriptHandlerCallbacks =
23112334{
23122335 sizeof (__MCScriptHandlerContext),
0 commit comments