On Wed, Aug 8, 2012 at 6:53 PM, Josh Simmons <simmons.44@xxxxxxxxx> wrote: > On Wed, Aug 8, 2012 at 6:48 PM, rob <rob.mail@xxxxxxxxxxx> wrote: >> Hi, >> >> Is this meant to work with a -1 stack index (i.e. from top to bottom)? >> Because whenever I use lua_isstring or lua_isnoneornil with -1 it seems to >> be broken. If I attempt to check the stack using 1, it works fine. >> >> > > Like Mike mentioned earlier, this is not an acceptable index > http://www.lua.org/manual/5.1/manual.html#3.2 > > You should check the stack height with lua_gettop to check the number > of arguments passed to a function. > > Cheers, > Josh. To elaborate some, An acceptable index is different for absolute indices and those relative to the top of the stack. Any positive index less than or equal to the stack space is deemed acceptable. However in the case of negative indices only those with an absolute value less than or equal to the stack top are acceptable. On top of this valid indices are those acceptable indices where the absolute value of the index is always under the stack top. Most functions will work on any acceptable index, though some only work on valid indices. This is indicated per-function in the Lua manual. For example on a stack where the stack space is 21 and the stack top is 10 the index any positive index up to 21 would be acceptable and any positive index up to 10 would be valid. 22 would be unacceptable. Any indices from -10 through -1 would be acceptable (and valid). Hopefully I haven't fucked that up somewhere. :) Cheers, Josh.