How to pass variables into limit()

How would one pass a variable into limit()?

<?php $a = $page->myFieldVar(); ?>
<?php foreach($page->images()->sortBy('sort', 'asc')->limit($a) as $image): ?>

Doesn’t work.

Try

<?php $a = $page->myFieldVar()->int(); ?>

The reason for this is that the variable $a would otherwise be of type Field, but you need the numeric representation to use it as a number.

Worked perfectly, thanks!