@@ -1128,25 +1128,105 @@ test "getstack" {
1128
1128
);
1129
1129
}
1130
1130
1131
+ test "aux check functions" {
1132
+ var lua = try Lua .init (testing .allocator );
1133
+ defer lua .deinit ();
1134
+
1135
+ const function = ziglua .wrap (struct {
1136
+ fn inner (l : * Lua ) i32 {
1137
+ l .checkAny (1 );
1138
+ _ = l .checkInteger (2 );
1139
+ _ = l .checkBytes (3 );
1140
+ _ = l .checkNumber (4 );
1141
+ _ = l .checkString (5 );
1142
+ _ = l .checkType (6 , .boolean );
1143
+ return 0 ;
1144
+ }
1145
+ }.inner );
1146
+
1147
+ lua .pushFunction (function );
1148
+ lua .protectedCall (0 , 0 , 0 ) catch {
1149
+ try expectEqualStrings ("bad argument #1 to '?' (value expected)" , try lua .toBytes (-1 ));
1150
+ lua .pop (-1 );
1151
+ };
1152
+
1153
+ lua .pushFunction (function );
1154
+ lua .pushNil ();
1155
+ lua .protectedCall (1 , 0 , 0 ) catch {
1156
+ try expectEqualStrings ("bad argument #2 to '?' (number expected, got no value)" , try lua .toBytes (-1 ));
1157
+ lua .pop (-1 );
1158
+ };
1159
+
1160
+ lua .pushFunction (function );
1161
+ lua .pushNil ();
1162
+ lua .pushInteger (3 );
1163
+ lua .protectedCall (2 , 0 , 0 ) catch {
1164
+ try expectEqualStrings ("bad argument #3 to '?' (string expected, got no value)" , try lua .toBytes (-1 ));
1165
+ lua .pop (-1 );
1166
+ };
1167
+
1168
+ lua .pushFunction (function );
1169
+ lua .pushNil ();
1170
+ lua .pushInteger (3 );
1171
+ _ = lua .pushBytes ("hello world" );
1172
+ lua .protectedCall (3 , 0 , 0 ) catch {
1173
+ try expectEqualStrings ("bad argument #4 to '?' (number expected, got no value)" , try lua .toBytes (-1 ));
1174
+ lua .pop (-1 );
1175
+ };
1176
+
1177
+ lua .pushFunction (function );
1178
+ lua .pushNil ();
1179
+ lua .pushInteger (3 );
1180
+ _ = lua .pushBytes ("hello world" );
1181
+ lua .pushNumber (4 );
1182
+ lua .protectedCall (4 , 0 , 0 ) catch {
1183
+ try expectEqualStrings ("bad argument #5 to '?' (string expected, got no value)" , try lua .toBytes (-1 ));
1184
+ lua .pop (-1 );
1185
+ };
1186
+
1187
+ lua .pushFunction (function );
1188
+ lua .pushNil ();
1189
+ lua .pushInteger (3 );
1190
+ _ = lua .pushBytes ("hello world" );
1191
+ lua .pushNumber (4 );
1192
+ _ = lua .pushString ("hello world" );
1193
+ lua .protectedCall (5 , 0 , 0 ) catch {
1194
+ try expectEqualStrings ("bad argument #6 to '?' (boolean expected, got no value)" , try lua .toBytes (-1 ));
1195
+ lua .pop (-1 );
1196
+ };
1197
+
1198
+ lua .pushFunction (function );
1199
+ lua .pushNil ();
1200
+ lua .pushInteger (3 );
1201
+ _ = lua .pushBytes ("hello world" );
1202
+ lua .pushNumber (4 );
1203
+ _ = lua .pushString ("hello world" );
1204
+ lua .pushBoolean (true );
1205
+ lua .protectedCall (6 , 0 , 0 ) catch {
1206
+ try expectEqualStrings ("bad argument #6 to '?' (boolean expected, got no value)" , try lua .toBytes (-1 ));
1207
+ lua .pop (-1 );
1208
+ };
1209
+
1210
+ lua .pushFunction (function );
1211
+ lua .pushNil ();
1212
+ lua .pushInteger (3 );
1213
+ _ = lua .pushBytes ("hello world" );
1214
+ lua .pushNumber (4 );
1215
+ _ = lua .pushString ("hello world" );
1216
+ lua .pushBoolean (true );
1217
+ try lua .protectedCall (6 , 0 , 0 );
1218
+ }
1219
+
1131
1220
test "refs" {
1132
1221
// temporary test that includes a reference to all functions so
1133
1222
// they will be type-checked
1134
1223
1135
- // debug
1136
- _ = Lua .getStack ;
1137
-
1138
1224
// auxlib
1139
1225
_ = Lua .argCheck ;
1140
1226
_ = Lua .argError ;
1141
1227
_ = Lua .argExpected ;
1142
1228
_ = Lua .callMeta ;
1143
- _ = Lua .checkAny ;
1144
- _ = Lua .checkInteger ;
1145
- _ = Lua .checkLString ;
1146
- _ = Lua .checkNumber ;
1147
1229
_ = Lua .checkOption ;
1148
- _ = Lua .checkString ;
1149
- _ = Lua .checkType ;
1150
1230
_ = Lua .checkUserdata ;
1151
1231
_ = Lua .checkVersion ;
1152
1232
_ = Lua .doFile ;
0 commit comments