@@ -287,4 +287,79 @@ public void Call_CallParametersWithLimitedResults_RestrictsFunctionResults([Valu
287287
288288 Lua . Stack . Pop ( resultCount ) ;
289289 }
290+
291+ [ Test ]
292+ public void Call_CallParametersWithStackArgument_ReturnsExpectedResult ( )
293+ {
294+ // Arrange
295+ using var function = Lua . Load ( "local x = ... return x + 1" ) ;
296+ Lua . Stack . EnsureFreeCapacity ( 1 ) ;
297+ Lua . Stack . Push ( 41 ) ;
298+
299+ var parameters = new LuaFunctionCallParameters
300+ {
301+ ArgumentCount = 1 ,
302+ ResultCount = 1
303+ } ;
304+
305+ // Act
306+ function . Call ( in parameters ) ;
307+
308+ // Assert
309+ Assert . That ( Lua . Stack . Count , Is . EqualTo ( 1 ) ) ;
310+ Assert . That ( Lua . Stack [ - 1 ] . GetValue < int > ( ) , Is . EqualTo ( 42 ) ) ;
311+
312+ Lua . Stack . Pop ( ) ;
313+ }
314+
315+ [ Test ]
316+ public void Call_CallParametersWithChildThreadStackArgument_ReturnsExpectedResult ( )
317+ {
318+ // Arrange
319+ using var thread = Lua . CreateThread ( ) ;
320+ using var function = Lua . Load ( "local x = ... return x + 1" ) ;
321+ thread . Stack . EnsureFreeCapacity ( 1 ) ;
322+ thread . Stack . Push ( 41 ) ;
323+
324+ var parameters = new LuaFunctionCallParameters
325+ {
326+ Caller = thread ,
327+ ArgumentCount = 1 ,
328+ ResultCount = 1
329+ } ;
330+
331+ // Act
332+ function . Call ( in parameters ) ;
333+
334+ // Assert
335+ Assert . That ( thread . Stack . Count , Is . EqualTo ( 1 ) ) ;
336+ Assert . That ( thread . Stack [ - 1 ] . GetValue < int > ( ) , Is . EqualTo ( 42 ) ) ;
337+
338+ thread . Stack . Pop ( ) ;
339+ }
340+
341+ [ Test ]
342+ public void Call_CallParametersWithCallableArgument_CallsTargetFunction ( )
343+ {
344+ // Arrange
345+ using var callableArgument = Lua . Load ( "return 'argument'" ) ;
346+ using var function = Lua . Load ( "return 'target'" ) ;
347+ Lua . Stack . EnsureFreeCapacity ( 1 ) ;
348+ Lua . Stack . Push ( callableArgument ) ;
349+
350+ var parameters = new LuaFunctionCallParameters
351+ {
352+ ArgumentCount = 1 ,
353+ ResultCount = 1
354+ } ;
355+
356+ // Act
357+ function . Call ( in parameters ) ;
358+
359+ // Assert
360+ Assert . That ( Lua . Stack . Count , Is . EqualTo ( 1 ) ) ;
361+ Assert . That ( Lua . Stack [ - 1 ] . GetValue < string > ( ) , Is . EqualTo ( "target" ) ) ;
362+
363+ Lua . Stack . Pop ( ) ;
364+ }
290365}
0 commit comments