@@ -24,17 +24,17 @@ fn expectEqualStringsSentinel(expected: []const u8, actual: [*:0]const u8) !void
24
24
// until issue #1717 we need to use the struct workaround
25
25
const add = struct {
26
26
fn addInner (l : * Lua ) i32 {
27
- const a = l .toInteger (1 );
28
- const b = l .toInteger (2 );
27
+ const a = l .toInteger (1 ) catch 0 ;
28
+ const b = l .toInteger (2 ) catch 0 ;
29
29
l .pushInteger (a + b );
30
30
return 1 ;
31
31
}
32
32
}.addInner ;
33
33
34
34
const sub = struct {
35
35
fn subInner (l : * Lua ) i32 {
36
- const a = l .toInteger (1 );
37
- const b = l .toInteger (2 );
36
+ const a = l .toInteger (1 ) catch 0 ;
37
+ const b = l .toInteger (2 ) catch 0 ;
38
38
l .pushInteger (a - b );
39
39
return 1 ;
40
40
}
@@ -157,61 +157,61 @@ test "arithmetic (lua_arith)" {
157
157
lua .pushNumber (42 );
158
158
159
159
lua .arith (.add );
160
- try expectEqual (@as (f64 , 52 ), lua .toNumber (1 ));
160
+ try expectEqual (@as (f64 , 52 ), try lua .toNumber (1 ));
161
161
162
162
lua .pushNumber (12 );
163
163
lua .arith (.sub );
164
- try expectEqual (@as (f64 , 40 ), lua .toNumber (1 ));
164
+ try expectEqual (@as (f64 , 40 ), try lua .toNumber (1 ));
165
165
166
166
lua .pushNumber (2 );
167
167
lua .arith (.mul );
168
- try expectEqual (@as (f64 , 80 ), lua .toNumber (1 ));
168
+ try expectEqual (@as (f64 , 80 ), try lua .toNumber (1 ));
169
169
170
170
lua .pushNumber (8 );
171
171
lua .arith (.div );
172
- try expectEqual (@as (f64 , 10 ), lua .toNumber (1 ));
172
+ try expectEqual (@as (f64 , 10 ), try lua .toNumber (1 ));
173
173
174
174
// prep for idiv
175
175
lua .pushNumber (1 );
176
176
lua .arith (.add );
177
177
lua .pushNumber (2 );
178
178
lua .arith (.idiv );
179
- try expectEqual (@as (f64 , 5 ), lua .toNumber (1 ));
179
+ try expectEqual (@as (f64 , 5 ), try lua .toNumber (1 ));
180
180
181
181
lua .pushNumber (2 );
182
182
lua .arith (.mod );
183
- try expectEqual (@as (f64 , 1 ), lua .toNumber (1 ));
183
+ try expectEqual (@as (f64 , 1 ), try lua .toNumber (1 ));
184
184
185
185
lua .arith (.unm );
186
- try expectEqual (@as (f64 , -1 ), lua .toNumber (1 ));
186
+ try expectEqual (@as (f64 , -1 ), try lua .toNumber (1 ));
187
187
188
188
lua .arith (.unm );
189
189
lua .pushNumber (2 );
190
190
lua .arith (.shl );
191
- try expectEqual (@as (i64 , 4 ), lua .toInteger (1 ));
191
+ try expectEqual (@as (i64 , 4 ), try lua .toInteger (1 ));
192
192
193
193
lua .pushNumber (1 );
194
194
lua .arith (.shr );
195
- try expectEqual (@as (i64 , 2 ), lua .toInteger (1 ));
195
+ try expectEqual (@as (i64 , 2 ), try lua .toInteger (1 ));
196
196
197
197
lua .pushNumber (4 );
198
198
lua .arith (.bor );
199
- try expectEqual (@as (i64 , 6 ), lua .toInteger (1 ));
199
+ try expectEqual (@as (i64 , 6 ), try lua .toInteger (1 ));
200
200
201
201
lua .pushNumber (1 );
202
202
lua .arith (.band );
203
- try expectEqual (@as (i64 , 0 ), lua .toInteger (1 ));
203
+ try expectEqual (@as (i64 , 0 ), try lua .toInteger (1 ));
204
204
205
205
lua .pushNumber (1 );
206
206
lua .arith (.bxor );
207
- try expectEqual (@as (i64 , 1 ), lua .toInteger (1 ));
207
+ try expectEqual (@as (i64 , 1 ), try lua .toInteger (1 ));
208
208
209
209
lua .arith (.bnot ); // 0xFFFFFFFFFFFFFFFE which is -2
210
- try expectEqual (@as (i64 , -2 ), lua .toInteger (1 ));
210
+ try expectEqual (@as (i64 , -2 ), try lua .toInteger (1 ));
211
211
212
212
lua .pushNumber (3 );
213
213
lua .arith (.pow );
214
- try expectEqual (@as (i64 , -8 ), lua .toInteger (1 ));
214
+ try expectEqual (@as (i64 , -8 ), try lua .toInteger (1 ));
215
215
}
216
216
217
217
test "compare" {
@@ -292,8 +292,8 @@ test "type of and getting values" {
292
292
try expectEqual (lua .state , (try lua .toThread (7 )).state );
293
293
try expectEqual (@as (ziglua .CFn , ziglua .wrap (add )), try lua .toCFunction (9 ));
294
294
295
- try expectEqual (@as (Number , 0.1 ), try lua .toNumberX (6 ));
296
- try expectEqual (@as (Integer , 1 ), try lua .toIntegerX (3 ));
295
+ try expectEqual (@as (Number , 0.1 ), try lua .toNumber (6 ));
296
+ try expectEqual (@as (Integer , 1 ), try lua .toInteger (3 ));
297
297
}
298
298
299
299
test "typenames" {
@@ -325,7 +325,7 @@ test "executing string contents" {
325
325
try expectEqual (LuaType .function , lua .getGlobal ("f" ));
326
326
lua .pop (1 );
327
327
try expectEqual (LuaType .number , lua .getGlobal ("a" ));
328
- try expectEqual (@as (i64 , 12 ), lua .toInteger (1 ));
328
+ try expectEqual (@as (i64 , 12 ), try lua .toInteger (1 ));
329
329
330
330
try expectError (Error .Syntax , lua .loadString ("bad syntax" ));
331
331
try lua .loadString ("a = g()" );
@@ -394,10 +394,10 @@ test "stack manipulation" {
394
394
try expectEqual (@as (i32 , 10 ), lua .getTop ());
395
395
396
396
lua .copy (1 , 2 );
397
- try expectEqual (@as (i64 , 10 ), lua .toInteger (1 ));
398
- try expectEqual (@as (i64 , 10 ), lua .toInteger (2 ));
399
- try expectEqual (@as (i64 , 1 ), lua .toInteger (3 ));
400
- try expectEqual (@as (i64 , 8 ), lua .toInteger (-1 ));
397
+ try expectEqual (@as (i64 , 10 ), try lua .toInteger (1 ));
398
+ try expectEqual (@as (i64 , 10 ), try lua .toInteger (2 ));
399
+ try expectEqual (@as (i64 , 1 ), try lua .toInteger (3 ));
400
+ try expectEqual (@as (i64 , 8 ), try lua .toInteger (-1 ));
401
401
402
402
lua .setTop (0 );
403
403
try expectEqual (@as (i32 , 0 ), lua .getTop ());
@@ -416,7 +416,7 @@ test "calling a function" {
416
416
// we know it should be safe
417
417
lua .call (2 , 1 );
418
418
419
- try expectEqual (@as (i64 , 42 ), lua .toInteger (1 ));
419
+ try expectEqual (@as (i64 , 42 ), try lua .toInteger (1 ));
420
420
}
421
421
422
422
test "version" {
@@ -482,7 +482,7 @@ test "string buffers" {
482
482
try expectEqualStrings ("abcdefghijklmnopqrstuvwxyz" , try lua .toBytes (-1 ));
483
483
484
484
lua .len (-1 );
485
- try expectEqual (@as (Integer , 26 ), lua .toInteger (-1 ));
485
+ try expectEqual (@as (Integer , 26 ), try lua .toInteger (-1 ));
486
486
}
487
487
488
488
test "global table" {
@@ -532,7 +532,7 @@ test "function registration" {
532
532
lua .pushInteger (42 );
533
533
lua .pushInteger (40 );
534
534
try lua .protectedCall (2 , 1 , 0 );
535
- try expectEqual (@as (Integer , 2 ), lua .toInteger (-1 ));
535
+ try expectEqual (@as (Integer , 2 ), try lua .toInteger (-1 ));
536
536
537
537
// now test the newlib variation to build a library from functions
538
538
// indirectly tests newLibTable
@@ -639,7 +639,7 @@ test "table access" {
639
639
640
640
_ = lua .pushString ("other one" );
641
641
try expectEqual (LuaType .number , lua .rawGetTable (1 ));
642
- try expectEqual (@as (Integer , 1234 ), lua .toInteger (-1 ));
642
+ try expectEqual (@as (Integer , 1234 ), try lua .toInteger (-1 ));
643
643
644
644
// a.name = "ziglua"
645
645
_ = lua .pushString ("name" );
@@ -701,11 +701,11 @@ test "conversions" {
701
701
// string conversion
702
702
try lua .stringToNumber ("1" );
703
703
try expect (lua .isInteger (-1 ));
704
- try expectEqual (@as (Integer , 1 ), lua .toInteger (1 ));
704
+ try expectEqual (@as (Integer , 1 ), try lua .toInteger (1 ));
705
705
706
706
try lua .stringToNumber (" 1.0 " );
707
707
try expect (lua .isNumber (-1 ));
708
- try expectEqual (@as (Number , 1.0 ), lua .toNumber (-1 ));
708
+ try expectEqual (@as (Number , 1.0 ), try lua .toNumber (-1 ));
709
709
710
710
try expectError (Error .Fail , lua .stringToNumber ("a" ));
711
711
try expectError (Error .Fail , lua .stringToNumber ("1.a" ));
@@ -762,7 +762,7 @@ test "dump and load" {
762
762
// now call the new function (which should return the value + 5)
763
763
lua .pushInteger (6 );
764
764
try lua .protectedCall (1 , 1 , 0 );
765
- try expectEqual (@as (Integer , 11 ), lua .toInteger (-1 ));
765
+ try expectEqual (@as (Integer , 11 ), try lua .toInteger (-1 ));
766
766
}
767
767
768
768
test "threads" {
@@ -802,7 +802,7 @@ test "userdata and uservalues" {
802
802
try lua .setIndexUserValue (1 , 2 );
803
803
804
804
try expectEqual (LuaType .number , try lua .getIndexUserValue (1 , 1 ));
805
- try expectEqual (@as (Number , 1234.56 ), lua .toNumber (-1 ));
805
+ try expectEqual (@as (Number , 1234.56 ), try lua .toNumber (-1 ));
806
806
try expectEqual (LuaType .string , try lua .getIndexUserValue (1 , 2 ));
807
807
try expectEqualStrings ("test string" , try lua .toBytes (-1 ));
808
808
@@ -820,7 +820,7 @@ test "upvalues" {
820
820
// counter from PIL
821
821
const counter = struct {
822
822
fn inner (l : * Lua ) i32 {
823
- var counter = l .toInteger (Lua .upvalueIndex (1 ));
823
+ var counter = l .toInteger (Lua .upvalueIndex (1 )) catch 0 ;
824
824
counter += 1 ;
825
825
l .pushInteger (counter );
826
826
l .copy (-1 , Lua .upvalueIndex (1 ));
@@ -838,7 +838,7 @@ test "upvalues" {
838
838
while (expected <= 10 ) : (expected += 1 ) {
839
839
_ = lua .getGlobal ("counter" );
840
840
lua .call (0 , 1 );
841
- try expectEqual (expected , lua .toInteger (-1 ));
841
+ try expectEqual (expected , try lua .toInteger (-1 ));
842
842
lua .pop (1 );
843
843
}
844
844
}
@@ -864,7 +864,7 @@ test "table traversal" {
864
864
},
865
865
.number = > {
866
866
try expectEqualStrings ("third" , try lua .toBytes (-2 ));
867
- try expectEqual (@as (Integer , 1 ), lua .toInteger (-1 ));
867
+ try expectEqual (@as (Integer , 1 ), try lua .toInteger (-1 ));
868
868
},
869
869
else = > unreachable ,
870
870
}
@@ -915,7 +915,7 @@ test "closing vars" {
915
915
916
916
// this should have incremented "closed_vars" to 2
917
917
_ = lua .getGlobal ("closed_vars" );
918
- try expectEqual (@as (Number , 2 ), lua .toNumber (-1 ));
918
+ try expectEqual (@as (Number , 2 ), try lua .toNumber (-1 ));
919
919
}
920
920
921
921
test "raise error" {
@@ -970,7 +970,7 @@ test "yielding" {
970
970
var i : i32 = 0 ;
971
971
while (i < 5 ) : (i += 1 ) {
972
972
try expectEqual (ziglua .ResumeStatus .yield , try thread .resumeThread (lua , 0 , & results ));
973
- try expectEqual (@as (Integer , i ), thread .toInteger (-1 ));
973
+ try expectEqual (@as (Integer , i ), try thread .toInteger (-1 ));
974
974
thread .pop (results );
975
975
}
976
976
try expectEqual (ziglua .ResumeStatus .ok , try thread .resumeThread (lua , 0 , & results ));
0 commit comments