Skip to content

Commit 07a7be8

Browse files
authored
[cppia] Allow setting callback for script load (#1203)
* [cppia] Allow setting callback for script load Debugger clients may want to do some work if a script is loaded, e.g. adding breakpoints. * Put new api function behind api level 500
1 parent bf2e3aa commit 07a7be8

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

include/hx/Debug.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ class StackCatchable
216216
bool (*mTestFunction)(Dynamic e);
217217
};
218218

219+
#if defined(HXCPP_SCRIPTABLE) && (HXCPP_API_LEVEL >= 500)
220+
// This is the function to call when a new script has been loaded.
221+
// Signature: Void -> Void
222+
extern Dynamic g_onScriptLoadedFunction;
223+
#endif
219224

220225

221226
#endif // HXCPP_DEBUGGER
@@ -298,6 +303,9 @@ void __hxcpp_dbg_setNewStackFrameFunction(Dynamic function);
298303
void __hxcpp_dbg_setNewThreadInfoFunction(Dynamic function);
299304
void __hxcpp_dbg_setAddParameterToStackFrameFunction(Dynamic function);
300305
void __hxcpp_dbg_setAddStackFrameToThreadInfoFunction(Dynamic function);
306+
#if defined(HXCPP_SCRIPTABLE) && (HXCPP_API_LEVEL >= 500)
307+
void __hxcpp_dbg_setOnScriptLoadedFunction(Dynamic function);
308+
#endif
301309

302310
bool __hxcpp_dbg_fix_critical_error(String inErr);
303311

@@ -351,6 +359,9 @@ inline void __hxcpp_dbg_setNewStackFrameFunction(Dynamic) { }
351359
inline void __hxcpp_dbg_setNewThreadInfoFunction(Dynamic) { }
352360
inline void __hxcpp_dbg_setAddParameterToStackFrameFunction(Dynamic) { }
353361
inline void __hxcpp_dbg_setAddStackFrameToThreadInfoFunction(Dynamic) { }
362+
#if defined(HXCPP_SCRIPTABLE) && (HXCPP_API_LEVEL >= 500)
363+
inline void __hxcpp_dbg_setOnScriptLoadedFunction(Dynamic) { }
364+
#endif
354365

355366
// The following functions are called by Thread.cpp to notify of thread
356367
// created and terminated

src/hx/Debugger.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ static Dynamic g_addParameterToStackFrameFunction;
5656
// Signature: inThreadInfo : Dynamic -> inStackFrame : Dynamic -> Void
5757
static Dynamic g_addStackFrameToThreadInfoFunction;
5858

59+
#if defined(HXCPP_SCRIPTABLE) && (HXCPP_API_LEVEL >= 500)
60+
Dynamic g_onScriptLoadedFunction{};
61+
#endif
5962

6063
// This is the thread number of the debugger thread, extracted from
6164
// information about the thread that called
@@ -1454,6 +1457,15 @@ void __hxcpp_dbg_setAddStackFrameToThreadInfoFunction(Dynamic function)
14541457
}
14551458

14561459

1460+
#if defined(HXCPP_SCRIPTABLE) && (HXCPP_API_LEVEL >= 500)
1461+
void __hxcpp_dbg_setOnScriptLoadedFunction(Dynamic function)
1462+
{
1463+
hx::g_onScriptLoadedFunction = function;
1464+
GCAddRoot(&(hx::g_onScriptLoadedFunction.mPtr));
1465+
}
1466+
#endif
1467+
1468+
14571469
Dynamic __hxcpp_dbg_checkedThrow(Dynamic toThrow)
14581470
{
14591471
if (!hx::CanBeCaught(toThrow))

src/hx/cppia/CppiaModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ void CppiaModule::registerDebugger()
111111
for(hx::UnorderedSet<int>::const_iterator i = allFileIds.begin(); i!=allFileIds.end(); ++i)
112112
addScriptableFile(strings[*i]);
113113

114+
#if (HXCPP_API_LEVEL >= 500)
115+
if (hx::g_onScriptLoadedFunction != null{}) {
116+
hx::g_onScriptLoadedFunction();
117+
}
118+
#endif
119+
114120
#endif
115121
}
116122

tools/hxcpp/BuildTool.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef Linkers = Hash<Linker>;
4545

4646
class BuildTool
4747
{
48-
public inline static var SupportedVersion = 430;
48+
public inline static var SupportedVersion = 500;
4949

5050
var mDefines:Hash<String>;
5151
var mCurrentIncludeFile:String;

0 commit comments

Comments
 (0)