lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>>>>> "Daniel" == Daniel Silverstone <dsilvers@digital-scurf.org> writes:

 Daniel> For your first example, the stack is [1] on input, so n_items
 Daniel> is set to MIN(1, 1 - 1) which will be 0. We remove the 1, set
 Daniel> top to 0 and return 0 items, matching your limit(1) -->
 Daniel> nothing.

 Daniel> For your second example, the stack is [1 1 2 3] on input, so
 Daniel> n_items is set to MIN(1, 4 - 1) which will be 1. Remove the 1,
 Daniel> truncate to 1 items, return it. Works again.

You don't actually need to remove the count, just truncate the stack to
n+1 items and return n.

-- 
Andrew.