@@ -10,6 +10,7 @@ pub(crate) fn run_tests() -> bool {
10
10
status &= test_register_property ( ) ;
11
11
status &= test_advanced_methods ( ) ;
12
12
status &= test_varargs_gets ( ) ;
13
+ status &= test_varargs_to_tuple ( ) ;
13
14
14
15
status
15
16
}
@@ -19,6 +20,7 @@ pub(crate) fn register(handle: InitHandle) {
19
20
handle. add_class :: < RegisterProperty > ( ) ;
20
21
handle. add_class :: < AdvancedMethods > ( ) ;
21
22
handle. add_class :: < VarargsGets > ( ) ;
23
+ handle. add_class :: < VarargsToTuple > ( ) ;
22
24
}
23
25
24
26
#[ derive( Copy , Clone , Debug , Default ) ]
@@ -293,3 +295,52 @@ fn test_varargs_gets() -> bool {
293
295
}
294
296
ok
295
297
}
298
+
299
+ #[ derive( NativeClass ) ]
300
+ #[ inherit( Reference ) ]
301
+ #[ register_with( VarargsToTuple :: register) ]
302
+ struct VarargsToTuple { }
303
+
304
+ #[ methods]
305
+ impl VarargsToTuple {
306
+ fn new ( _owner : TRef < Reference > ) -> Self {
307
+ VarargsToTuple { }
308
+ }
309
+
310
+ fn register ( builder : & ClassBuilder < VarargsToTuple > ) {
311
+ builder. method ( "calc" , CalcMethod2 ) . done ( ) ;
312
+ }
313
+ }
314
+
315
+ struct CalcMethod2 ;
316
+
317
+ impl Method < VarargsToTuple > for CalcMethod2 {
318
+ fn call (
319
+ & self ,
320
+ _this : TInstance < ' _ , VarargsToTuple > ,
321
+ args : gdnative:: export:: Varargs < ' _ > ,
322
+ ) -> Variant {
323
+ let ( a, b, c) : ( i64 , i64 , i64 ) =
324
+ std:: convert:: TryInto :: try_into ( args) . expect ( "Must be able to convert" ) ;
325
+ let ret = a * b - c;
326
+ ret. to_variant ( )
327
+ }
328
+ }
329
+
330
+ fn test_varargs_to_tuple ( ) -> bool {
331
+ println ! ( " -- test_varargs_to_tuple" ) ;
332
+
333
+ let ok = std:: panic:: catch_unwind ( || {
334
+ let thing = Instance :: < VarargsToTuple , _ > :: new ( ) ;
335
+ let base = thing. base ( ) ;
336
+
337
+ let args = [ 3_i64 . to_variant ( ) , 4_i64 . to_variant ( ) , 5_i64 . to_variant ( ) ] ;
338
+ assert_eq ! ( unsafe { base. call( "calc" , & args) . to( ) } , Some ( 7 ) ) ;
339
+ } )
340
+ . is_ok ( ) ;
341
+
342
+ if !ok {
343
+ godot_error ! ( " !! Test test_varargs_to_tuple failed" ) ;
344
+ }
345
+ ok
346
+ }
0 commit comments