@@ -8,6 +8,7 @@ pub(crate) fn run_tests() -> bool {
8
8
9
9
status &= test_register_property ( ) ;
10
10
status &= test_advanced_methods ( ) ;
11
+ status &= test_varargs_to_tuple ( ) ;
11
12
12
13
status
13
14
}
@@ -16,6 +17,7 @@ pub(crate) fn register(handle: InitHandle) {
16
17
handle. add_class :: < RegisterSignal > ( ) ;
17
18
handle. add_class :: < RegisterProperty > ( ) ;
18
19
handle. add_class :: < AdvancedMethods > ( ) ;
20
+ handle. add_class :: < VarargsToTuple > ( ) ;
19
21
}
20
22
21
23
#[ derive( Copy , Clone , Debug , Default ) ]
@@ -232,3 +234,57 @@ fn test_advanced_methods() -> bool {
232
234
233
235
ok
234
236
}
237
+
238
+ #[ derive( NativeClass ) ]
239
+ #[ inherit( Reference ) ]
240
+ #[ register_with( VarargsToTuple :: register) ]
241
+ struct VarargsToTuple { }
242
+
243
+ #[ methods]
244
+ impl VarargsToTuple {
245
+ fn new ( _owner : TRef < Reference > ) -> Self {
246
+ VarargsToTuple { }
247
+ }
248
+
249
+ fn register ( builder : & ClassBuilder < VarargsToTuple > ) {
250
+ builder. method ( "calc" , CalcMethod ) . done ( ) ;
251
+ }
252
+ }
253
+
254
+ struct CalcMethod ;
255
+
256
+ impl Method < VarargsToTuple > for CalcMethod {
257
+ fn call (
258
+ & self ,
259
+ _this : TInstance < ' _ , VarargsToTuple > ,
260
+ args : gdnative:: export:: Varargs < ' _ > ,
261
+ ) -> Variant {
262
+ let ( a, b, c) : ( i64 , i64 , i64 ) =
263
+ std:: convert:: TryInto :: try_into ( args) . expect ( "Must be able to convert" ) ;
264
+ let ret = a * b - c;
265
+ ret. to_variant ( )
266
+ }
267
+ }
268
+
269
+ fn test_varargs_to_tuple ( ) -> bool {
270
+ println ! ( " -- test_varargs_to_tuple" ) ;
271
+
272
+ let ok = std:: panic:: catch_unwind ( || {
273
+ let thing = Instance :: < VarargsToTuple , _ > :: new ( ) ;
274
+ let base = thing. base ( ) ;
275
+
276
+ assert_eq ! ( Some ( 7 ) , unsafe {
277
+ base. call(
278
+ "calc" ,
279
+ & [ 3_i64 . to_variant( ) , 4_i64 . to_variant( ) , 5_i64 . to_variant( ) ] ,
280
+ )
281
+ . to( )
282
+ } ) ;
283
+ } )
284
+ . is_ok ( ) ;
285
+
286
+ if !ok {
287
+ godot_error ! ( " !! Test test_varargs_to_tuple failed" ) ;
288
+ }
289
+ ok
290
+ }
0 commit comments