Commits

Jérôme Vuarand  committed 8b6c7b3

Fixed the error message when the last argument of interrupt_transfer is missing.

  • Participants
  • Parent commits 2d70d58

Comments (0)

Files changed (1)

 	dev_handle = luausb_check_device_handle(L, 1);
 	endpoint = (unsigned char)luaL_checknumber(L, 2); /* :FIXME: handle overflow */
 	if (endpoint & LIBUSB_ENDPOINT_IN)
+		luaL_checknumber(L, 3);
+	else
+		luaL_checkstring(L, 3);
+	timeout = (unsigned int)luaL_checknumber(L, 4); /* :FIXME: handle overflow */
+	
+	/* extract actual arg 3 value */
+	if (endpoint & LIBUSB_ENDPOINT_IN)
 	{
 		/* in endpoint */
-		length = (int)luaL_checknumber(L, 3); /* :FIXME: handle overflow */
+		length = (int)lua_tonumber(L, 3); /* :FIXME: handle overflow */
 		data = (unsigned char*)lua_newuserdata(L, length);
 	}
 	else
 		/* out endpoint */
 		size_t len;
 		const char* str;
-		str = luaL_checklstring(L, 3, &len);
+		str = lua_tolstring(L, 3, &len);
 		length = (int)len; /* :FIXME: handle overflow */
 		data = (unsigned char*)lua_newuserdata(L, length);
 		memcpy(data, str, len);
 	}
-	timeout = (unsigned int)luaL_checknumber(L, 4); /* :FIXME: handle overflow */
 	
 	result = libusb_interrupt_transfer(dev_handle, endpoint, data, length, &transferred, timeout);
 	if (result < 0 && result != LIBUSB_ERROR_TIMEOUT)