@@ -25,7 +25,7 @@ public void CancellationTokenLuaHook_CancelsExecutionWithError()
2525 // Act & Assert
2626 Assert . That ( ( ) => Lua . Execute ( "while true do end" ) , Throws . TypeOf < LuaException > ( )
2727 . With . InnerException . TypeOf < OperationCanceledException > ( )
28- . And . InnerException . Property ( nameof ( OperationCanceledException . CancellationToken ) ) . EqualTo ( cts . Token ) ) ;
28+ . And . InnerException . Property ( nameof ( OperationCanceledException . CancellationToken ) ) . EqualTo ( cts . Token ) ) ;
2929 }
3030
3131 [ Test ]
@@ -37,7 +37,7 @@ public void MaxInstructionCountLuaHook_CancelsExecutionWithError()
3737 // Act & Assert
3838 Assert . That ( ( ) => Lua . Execute ( "while true do end" ) , Throws . TypeOf < LuaException > ( )
3939 . With . InnerException . TypeOf < MaxInstructionCountReachedException > ( )
40- . And . InnerException . Property ( nameof ( MaxInstructionCountReachedException . InstructionCount ) ) . EqualTo ( 100 ) ) ;
40+ . And . InnerException . Property ( nameof ( MaxInstructionCountReachedException . InstructionCount ) ) . EqualTo ( 100 ) ) ;
4141 }
4242
4343 private sealed class InstructionCountLuaHook ( int instructionCount ) : LuaHook
@@ -48,7 +48,7 @@ private sealed class InstructionCountLuaHook(int instructionCount) : LuaHook
4848
4949 public int TimesCalled { get ; private set ; }
5050
51- protected override void Execute ( LuaThread lua , LuaDebug debug )
51+ protected override void Execute ( LuaThread lua , ref LuaDebug debug )
5252 {
5353 TimesCalled ++ ;
5454 }
@@ -75,6 +75,42 @@ public void CombinedCountLuaHooks_CallsBothAsExpected()
7575 Assert . That ( fiveInstructionsHook . TimesCalled , Is . EqualTo ( 2 ) ) ;
7676 }
7777
78+ private sealed class FunctionNameGrabberLuaHook : LuaHook
79+ {
80+ protected override LuaEventMask EventMask => LuaEventMask . Call ;
81+
82+ protected override int InstructionCount => 0 ;
83+
84+ public List < string > FunctionNames { get ; } = [ ] ;
85+
86+ protected override void Execute ( LuaThread lua , ref LuaDebug debug )
87+ {
88+ var functionName = debug . FunctionName . ToString ( ) ;
89+ if ( ! string . IsNullOrWhiteSpace ( functionName ) )
90+ {
91+ FunctionNames . Add ( functionName ) ;
92+ }
93+ }
94+ }
95+
96+ [ Test ]
97+ public void FunctionNameGrabberLuaHook_GrabsFunctionNames ( )
98+ {
99+ // Arrange
100+ var hook = new FunctionNameGrabberLuaHook ( ) ;
101+ Lua . State . Hook = hook ;
102+
103+ Lua . SetGlobal ( "func1" , static ( ) => { } ) ;
104+ Lua . SetGlobal ( "func2" , static ( ) => { } ) ;
105+ Lua . Execute ( "function func3() end" ) ;
106+
107+ // Act
108+ Lua . Execute ( "func1() func2() func3()" ) ;
109+
110+ // Assert
111+ Assert . That ( hook . FunctionNames , Is . EqualTo ( new [ ] { "func1" , "func2" , "func3" } ) ) ;
112+ }
113+
78114 [ Test ]
79115 public void GC_IsRunning_ReturnsTrue ( )
80116 {
0 commit comments