@@ -1365,29 +1365,33 @@ test "table readonly" {
13651365 try expect (try table .get ("after" , ? i32 ) == null );
13661366}
13671367
1368- fn closureAdd5 (upv : struct { n : i32 } , x : i32 ) i32 {
1369- return x + upv . n ;
1368+ fn closureAdd5 (n : i32 , x : i32 ) i32 {
1369+ return x + n ;
13701370}
13711371
1372- fn closureTransform (upv : struct { a : f32 , b : f32 }, x : f32 ) f32 {
1373- return x * upv . a + upv . b ;
1372+ fn closureTransform (upv : struct { f32 , f32 }, x : f32 ) f32 {
1373+ return x * upv [ 0 ] + upv [ 1 ] ;
13741374}
13751375
1376- fn closureOptAdd (upv : struct { thresh : i32 } , x : i32 , y : ? i32 ) i32 {
1377- return if (x > upv . thresh ) x + (y orelse 0 ) else x ;
1376+ fn closureOptAdd (thresh : i32 , x : i32 , y : ? i32 ) i32 {
1377+ return if (x > thresh ) x + (y orelse 0 ) else x ;
13781378}
13791379
1380- fn closureMultiply (upv : struct { cfg : Lua .Table } , x : i32 ) ! i32 {
1381- const m = try upv . cfg .get ("mult" , i32 ) orelse 1 ;
1380+ fn closureMultiply (cfg : Lua.Table , x : i32 ) ! i32 {
1381+ const m = try cfg .get ("mult" , i32 ) orelse 1 ;
13821382 return x * m ;
13831383}
13841384
1385- fn closureConstant (upv : struct { val : i32 } ) i32 {
1386- return upv . val ;
1385+ fn closureConstant (val : i32 ) i32 {
1386+ return val ;
13871387}
13881388
1389- fn closureSumAll (upv : struct { base : i32 }, a : ? i32 , b : ? i32 ) i32 {
1390- return upv .base + (a orelse 0 ) + (b orelse 0 );
1389+ fn closureSumAll (base : i32 , a : ? i32 , b : ? i32 ) i32 {
1390+ return base + (a orelse 0 ) + (b orelse 0 );
1391+ }
1392+
1393+ fn closureSingle (increment : i32 , x : i32 ) i32 {
1394+ return x + increment ;
13911395}
13921396
13931397test "table setClosure" {
@@ -1418,6 +1422,9 @@ test "table setClosure" {
14181422 // Multiple optionals
14191423 try table .setClosure ("sum" , .{100 }, closureSumAll );
14201424
1425+ // Single upvalue (not wrapped in struct)
1426+ try table .setClosure ("single" , .{42 }, closureSingle );
1427+
14211428 try lua .globals ().set ("f" , table );
14221429 try lua .globals ().set ("config" , config );
14231430
@@ -1431,6 +1438,7 @@ test "table setClosure" {
14311438 try expect (try lua .eval ("return f.const()" , .{}, i32 ) == 42 );
14321439 try expect (try lua .eval ("return f.sum()" , .{}, i32 ) == 100 );
14331440 try expect (try lua .eval ("return f.sum(1, 2)" , .{}, i32 ) == 103 );
1441+ try expect (try lua .eval ("return f.single(8)" , .{}, i32 ) == 50 );
14341442
14351443 // Test config modification
14361444 _ = try lua .eval ("config.mult = 7" , .{}, void );
0 commit comments