@@ -327,9 +327,9 @@ test "executing string contents" {
327
327
try lua .loadString ("a = f(2)" );
328
328
try lua .protectedCall (0 , 0 , 0 );
329
329
330
- try expectEqual (LuaType .function , lua .getGlobal ("f" ));
330
+ try expectEqual (LuaType .function , try lua .getGlobalEx ("f" ));
331
331
lua .pop (1 );
332
- try expectEqual (LuaType .number , lua .getGlobal ("a" ));
332
+ try expectEqual (LuaType .number , try lua .getGlobalEx ("a" ));
333
333
try expectEqual (@as (i64 , 12 ), try lua .toInteger (1 ));
334
334
335
335
try expectError (Error .Syntax , lua .loadString ("bad syntax" ));
@@ -413,7 +413,7 @@ test "calling a function" {
413
413
defer lua .deinit ();
414
414
415
415
lua .register ("zigadd" , ziglua .wrap (add ));
416
- _ = lua .getGlobal ("zigadd" );
416
+ try lua .getGlobal ("zigadd" );
417
417
lua .pushInteger (10 );
418
418
lua .pushInteger (32 );
419
419
@@ -630,7 +630,7 @@ test "table access" {
630
630
defer lua .deinit ();
631
631
632
632
try lua .doString ("a = { [1] = 'first', key = 'value', ['other one'] = 1234 }" );
633
- _ = lua .getGlobal ("a" );
633
+ try lua .getGlobal ("a" );
634
634
635
635
try expectEqual (LuaType .string , lua .getIndex (1 , 1 ));
636
636
try expectEqualStrings ("first" , try lua .toBytes (-1 ));
@@ -672,7 +672,7 @@ test "table access" {
672
672
lua .setField (1 , "bool" );
673
673
674
674
try lua .doString ("b = a.bool" );
675
- try expectEqual (LuaType .boolean , lua .getGlobal ("b" ));
675
+ try expectEqual (LuaType .boolean , try lua .getGlobalEx ("b" ));
676
676
try expect (lua .toBoolean (-1 ));
677
677
678
678
// create array [1, 2, 3, 4, 5]
@@ -728,7 +728,7 @@ test "dump and load" {
728
728
// store a function in a global
729
729
try lua .doString ("f = function(x) return function(n) return n + x end end" );
730
730
// put the function on the stack
731
- _ = lua .getGlobal ("f" );
731
+ try lua .getGlobal ("f" );
732
732
733
733
const writer = struct {
734
734
fn inner (l : * Lua , buf : []const u8 , data : * anyopaque ) bool {
@@ -841,7 +841,7 @@ test "upvalues" {
841
841
// call the function repeatedly, each time ensuring the result increases by one
842
842
var expected : Integer = 1 ;
843
843
while (expected <= 10 ) : (expected += 1 ) {
844
- _ = lua .getGlobal ("counter" );
844
+ try lua .getGlobal ("counter" );
845
845
lua .call (0 , 1 );
846
846
try expectEqual (expected , try lua .toInteger (-1 ));
847
847
lua .pop (1 );
@@ -853,7 +853,7 @@ test "table traversal" {
853
853
defer lua .deinit ();
854
854
855
855
try lua .doString ("t = { key = 'value', second = true, third = 1 }" );
856
- _ = lua .getGlobal ("t" );
856
+ try lua .getGlobal ("t" );
857
857
858
858
lua .pushNil ();
859
859
@@ -905,21 +905,21 @@ test "closing vars" {
905
905
);
906
906
907
907
lua .newTable ();
908
- _ = lua .getGlobal ("mt" );
908
+ try lua .getGlobal ("mt" );
909
909
lua .setMetatable (-2 );
910
910
lua .toClose (-1 );
911
911
lua .closeSlot (-1 );
912
912
lua .pop (1 );
913
913
914
914
lua .newTable ();
915
- _ = lua .getGlobal ("mt" );
915
+ try lua .getGlobal ("mt" );
916
916
lua .setMetatable (-2 );
917
917
lua .toClose (-1 );
918
918
lua .closeSlot (-1 );
919
919
lua .pop (1 );
920
920
921
921
// this should have incremented "closed_vars" to 2
922
- _ = lua .getGlobal ("closed_vars" );
922
+ try lua .getGlobal ("closed_vars" );
923
923
try expectEqual (@as (Number , 2 ), try lua .toNumber (-1 ));
924
924
}
925
925
@@ -993,7 +993,7 @@ test "debug interface" {
993
993
\\ return x + y
994
994
\\end
995
995
);
996
- _ = lua .getGlobal ("f" );
996
+ try lua .getGlobal ("f" );
997
997
998
998
var info : DebugInfo = undefined ;
999
999
lua .getInfo (.{
@@ -1052,7 +1052,7 @@ test "debug interface" {
1052
1052
try expectEqual (@as (? ziglua .CHookFn , ziglua .wrap (hook )), lua .getHook ());
1053
1053
try expectEqual (ziglua.HookMask { .call = true , .line = true , .ret = true }, lua .getHookMask ());
1054
1054
1055
- _ = lua .getGlobal ("f" );
1055
+ try lua .getGlobal ("f" );
1056
1056
lua .pushNumber (3 );
1057
1057
try lua .protectedCall (1 , 1 , 0 );
1058
1058
}
@@ -1069,7 +1069,7 @@ test "debug upvalues" {
1069
1069
\\end
1070
1070
\\addone = f(1)
1071
1071
);
1072
- _ = lua .getGlobal ("addone" );
1072
+ try lua .getGlobal ("addone" );
1073
1073
1074
1074
// index doesn't exist
1075
1075
try expectError (Error .Fail , lua .getUpvalue (1 , 2 ));
@@ -1096,8 +1096,8 @@ test "debug upvalues" {
1096
1096
\\addthree = f(3)
1097
1097
);
1098
1098
1099
- _ = lua .getGlobal ("addone" );
1100
- _ = lua .getGlobal ("addthree" );
1099
+ try lua .getGlobal ("addone" );
1100
+ try lua .getGlobal ("addthree" );
1101
1101
1102
1102
// now addone and addthree share the same upvalue
1103
1103
lua .upvalueJoin (-2 , 1 , -1 , 1 );
@@ -1220,6 +1220,13 @@ test "aux check functions" {
1220
1220
try lua .protectedCall (6 , 0 , 0 );
1221
1221
}
1222
1222
1223
+ test "get global fail" {
1224
+ var lua = try Lua .init (testing .allocator );
1225
+ defer lua .deinit ();
1226
+
1227
+ try expectError (Error .Fail , lua .getGlobal ("foo" ));
1228
+ }
1229
+
1223
1230
test "refs" {
1224
1231
// temporary test that includes a reference to all functions so
1225
1232
// they will be type-checked
0 commit comments