@@ -48,12 +48,6 @@ inline fn toNumber(lua: *Lua, index: i32) !ziglua.Number {
48
48
} else return try lua .toNumber (index );
49
49
}
50
50
51
- /// pushFunction that sets the name for Luau
52
- inline fn pushFunction (lua : * Lua , c_fn : ziglua.CFn ) void {
53
- if (ziglua .lang == .luau ) return lua .pushFunction (c_fn , "" );
54
- lua .pushFunction (c_fn );
55
- }
56
-
57
51
fn alloc (data : ? * anyopaque , ptr : ? * anyopaque , osize : usize , nsize : usize ) callconv (.C ) ? * anyopaque {
58
52
_ = data ;
59
53
@@ -145,7 +139,7 @@ test "Zig allocator access" {
145
139
}
146
140
}.inner ;
147
141
148
- pushFunction (& lua , ziglua .wrap (inner ));
142
+ lua . pushFunction (ziglua .wrap (inner ));
149
143
lua .pushInteger (10 );
150
144
try lua .protectedCall (1 , 1 , 0 );
151
145
@@ -347,7 +341,7 @@ test "type of and getting values" {
347
341
try expectEqual (.string , lua .typeOf (-1 ));
348
342
try expect (lua .isString (-1 ));
349
343
350
- if ( ziglua . lang == .luau ) lua . pushFunction ( ziglua . wrap ( add ), "add" ) else lua .pushFunction (ziglua .wrap (add ));
344
+ lua .pushFunction (ziglua .wrap (add ));
351
345
try expectEqual (.function , lua .typeOf (-1 ));
352
346
try expect (lua .isCFunction (-1 ));
353
347
try expect (lua .isFunction (-1 ));
@@ -875,10 +869,7 @@ test "table access" {
875
869
// create a metatable (it isn't a useful one)
876
870
lua .newTable ();
877
871
878
- if (ziglua .lang == .luau )
879
- lua .pushFunction (ziglua .wrap (add ), "add" )
880
- else
881
- lua .pushFunction (ziglua .wrap (add ));
872
+ lua .pushFunction (ziglua .wrap (add ));
882
873
lua .setField (-2 , "__len" );
883
874
lua .setMetatable (1 );
884
875
@@ -1087,7 +1078,7 @@ test "upvalues" {
1087
1078
1088
1079
// Initialize the counter at 0
1089
1080
lua .pushInteger (0 );
1090
- if ( ziglua . lang == .luau ) lua . pushClosure ( ziglua . wrap ( counter ), "counter" , 1 ) else lua .pushClosure (ziglua .wrap (counter ), 1 );
1081
+ lua .pushClosure (ziglua .wrap (counter ), 1 );
1091
1082
lua .setGlobal ("counter" );
1092
1083
1093
1084
// call the function repeatedly, each time ensuring the result increases by one
@@ -1191,7 +1182,7 @@ test "raise error" {
1191
1182
}
1192
1183
}.inner ;
1193
1184
1194
- if ( ziglua . lang == .luau ) lua . pushFunction ( ziglua . wrap ( makeError ), "makeError" ) else lua .pushFunction (ziglua .wrap (makeError ));
1185
+ lua .pushFunction (ziglua .wrap (makeError ));
1195
1186
try expectError (error .Runtime , lua .protectedCall (0 , 0 , 0 ));
1196
1187
try expectEqualStrings ("makeError made an error" , try lua .toBytes (-1 ));
1197
1188
}
@@ -1307,11 +1298,10 @@ test "yielding no continuation" {
1307
1298
return l .yield (1 );
1308
1299
}
1309
1300
}.inner );
1301
+ thread .pushFunction (func );
1310
1302
if (ziglua .lang == .luau ) {
1311
- thread .pushFunction (func , "yieldfn" );
1312
1303
_ = try thread .resumeThread (null , 0 );
1313
1304
} else {
1314
- thread .pushFunction (func );
1315
1305
_ = try thread .resumeThread (0 );
1316
1306
}
1317
1307
@@ -1367,28 +1357,28 @@ test "aux check functions" {
1367
1357
}
1368
1358
}.inner );
1369
1359
1370
- pushFunction (& lua , function );
1360
+ lua . pushFunction (function );
1371
1361
lua .protectedCall (0 , 0 , 0 ) catch {
1372
1362
try expectStringContains ("argument #1" , try lua .toBytes (-1 ));
1373
1363
lua .pop (-1 );
1374
1364
};
1375
1365
1376
- pushFunction (& lua , function );
1366
+ lua . pushFunction (function );
1377
1367
lua .pushNil ();
1378
1368
lua .protectedCall (1 , 0 , 0 ) catch {
1379
1369
try expectStringContains ("number expected" , try lua .toBytes (-1 ));
1380
1370
lua .pop (-1 );
1381
1371
};
1382
1372
1383
- pushFunction (& lua , function );
1373
+ lua . pushFunction (function );
1384
1374
lua .pushNil ();
1385
1375
lua .pushInteger (3 );
1386
1376
lua .protectedCall (2 , 0 , 0 ) catch {
1387
1377
try expectStringContains ("string expected" , try lua .toBytes (-1 ));
1388
1378
lua .pop (-1 );
1389
1379
};
1390
1380
1391
- pushFunction (& lua , function );
1381
+ lua . pushFunction (function );
1392
1382
lua .pushNil ();
1393
1383
lua .pushInteger (3 );
1394
1384
_ = lua .pushBytes ("hello world" );
@@ -1397,7 +1387,7 @@ test "aux check functions" {
1397
1387
lua .pop (-1 );
1398
1388
};
1399
1389
1400
- pushFunction (& lua , function );
1390
+ lua . pushFunction (function );
1401
1391
lua .pushNil ();
1402
1392
lua .pushInteger (3 );
1403
1393
_ = lua .pushBytes ("hello world" );
@@ -1407,7 +1397,7 @@ test "aux check functions" {
1407
1397
lua .pop (-1 );
1408
1398
};
1409
1399
1410
- pushFunction (& lua , function );
1400
+ lua . pushFunction (function );
1411
1401
lua .pushNil ();
1412
1402
lua .pushInteger (3 );
1413
1403
_ = lua .pushBytes ("hello world" );
@@ -1432,7 +1422,7 @@ test "aux check functions" {
1432
1422
};
1433
1423
}
1434
1424
1435
- pushFunction (& lua , function );
1425
+ lua . pushFunction (function );
1436
1426
// test pushFail here (currently acts the same as pushNil)
1437
1427
if (ziglua .lang == .lua54 ) lua .pushFail () else lua .pushNil ();
1438
1428
lua .pushInteger (3 );
@@ -1460,10 +1450,10 @@ test "aux opt functions" {
1460
1450
}
1461
1451
}.inner );
1462
1452
1463
- pushFunction (& lua , function );
1453
+ lua . pushFunction (function );
1464
1454
try lua .protectedCall (0 , 0 , 0 );
1465
1455
1466
- pushFunction (& lua , function );
1456
+ lua . pushFunction (function );
1467
1457
lua .pushInteger (10 );
1468
1458
_ = lua .pushBytes ("zig" );
1469
1459
lua .pushNumber (1.23 );
@@ -1493,32 +1483,32 @@ test "checkOption" {
1493
1483
}
1494
1484
}.inner );
1495
1485
1496
- pushFunction (& lua , function );
1486
+ lua . pushFunction (function );
1497
1487
_ = lua .pushString ("one" );
1498
1488
try lua .protectedCall (1 , 1 , 0 );
1499
1489
try expectEqual (1 , try toInteger (& lua , -1 ));
1500
1490
lua .pop (1 );
1501
1491
1502
- pushFunction (& lua , function );
1492
+ lua . pushFunction (function );
1503
1493
_ = lua .pushString ("two" );
1504
1494
try lua .protectedCall (1 , 1 , 0 );
1505
1495
try expectEqual (2 , try toInteger (& lua , -1 ));
1506
1496
lua .pop (1 );
1507
1497
1508
- pushFunction (& lua , function );
1498
+ lua . pushFunction (function );
1509
1499
_ = lua .pushString ("three" );
1510
1500
try lua .protectedCall (1 , 1 , 0 );
1511
1501
try expectEqual (3 , try toInteger (& lua , -1 ));
1512
1502
lua .pop (1 );
1513
1503
1514
1504
// try the default now
1515
- pushFunction (& lua , function );
1505
+ lua . pushFunction (function );
1516
1506
try lua .protectedCall (0 , 1 , 0 );
1517
1507
try expectEqual (1 , try toInteger (& lua , -1 ));
1518
1508
lua .pop (1 );
1519
1509
1520
1510
// check the raised error
1521
- pushFunction (& lua , function );
1511
+ lua . pushFunction (function );
1522
1512
_ = lua .pushString ("unknown" );
1523
1513
try expectError (error .Runtime , lua .protectedCall (1 , 1 , 0 ));
1524
1514
try expectStringContains ("(invalid option 'unknown')" , try lua .toBytes (-1 ));
@@ -1569,7 +1559,7 @@ test "where" {
1569
1559
}
1570
1560
}.inner );
1571
1561
1572
- pushFunction (& lua , whereFn );
1562
+ lua . pushFunction (whereFn );
1573
1563
lua .setGlobal ("whereFn" );
1574
1564
1575
1565
try lua .doString (
@@ -1662,7 +1652,7 @@ test "args and errors" {
1662
1652
}
1663
1653
}.inner );
1664
1654
1665
- pushFunction (& lua , argCheck );
1655
+ lua . pushFunction (argCheck );
1666
1656
try expectError (error .Runtime , lua .protectedCall (0 , 0 , 0 ));
1667
1657
1668
1658
const raisesError = ziglua .wrap (struct {
@@ -1672,7 +1662,7 @@ test "args and errors" {
1672
1662
}
1673
1663
}.inner );
1674
1664
1675
- pushFunction (& lua , raisesError );
1665
+ lua . pushFunction (raisesError );
1676
1666
try expectError (error .Runtime , lua .protectedCall (0 , 0 , 0 ));
1677
1667
try expectEqualStrings ("some error zig!" , try lua .toBytes (-1 ));
1678
1668
@@ -1755,7 +1745,7 @@ test "userdata" {
1755
1745
}
1756
1746
}.inner );
1757
1747
1758
- pushFunction (& lua , checkUdata );
1748
+ lua . pushFunction (checkUdata );
1759
1749
1760
1750
{
1761
1751
var t = if (ziglua .lang == .lua54 ) lua .newUserdata (Type , 0 ) else lua .newUserdata (Type );
@@ -1840,7 +1830,7 @@ test "userdata slices" {
1840
1830
}
1841
1831
}.inner ;
1842
1832
1843
- pushFunction (& lua , ziglua .wrap (udataFn ));
1833
+ lua . pushFunction (ziglua .wrap (udataFn ));
1844
1834
lua .pushValue (2 );
1845
1835
1846
1836
try lua .protectedCall (1 , 0 , 0 );
@@ -2387,7 +2377,7 @@ test "namecall" {
2387
2377
2388
2378
try lua .newMetatable ("vector" );
2389
2379
lua .pushString ("__namecall" );
2390
- lua .pushFunction (ziglua .wrap (funcs .vectorNamecall ), "vector_namecall" );
2380
+ lua .pushFunctionNamed (ziglua .wrap (funcs .vectorNamecall ), "vector_namecall" );
2391
2381
lua .setTable (-3 );
2392
2382
2393
2383
lua .setReadonly (-1 , true );
0 commit comments