[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: manual error (C function upvalues)
- From: "John Belmonte" <jvb@...>
- Date: Wed, 11 Oct 2000 15:18:57 +0900
>From the 4.0b manual:
>>>>
Then, whenever the C function is called, these upvalues are inserted as the
last arguments to the function, after the actual arguments provided in the
call. This makes it easy to get the upvalues without knowing how many
arguments the function received (recall that functions in Lua can receive
any number of arguments): The i-th upvalue is in the stack at index i-n+1,
where n is the number of upvalues.
<<<<
Believing that "i-n+1" equation cost me a couple hours of debugging (yes, a
little embarrassing). It should be "i-n-1". For example, upvalue 1 of 3 is
at index 1-3-1 = -3.
I don't understand the reasoning about making upvalues the last arguments.
If they were first, you could still access them without knowing how many
arguments the function received (as positive index 1, 2, 3 etc.). The
current design is error-prone, as I had naively demonstrated.
-John