Understanding argument indicies

I’m trying to debug an error that reads, “Bad argument #-1 to ‘newJoint’ (Proxy expected, got nil)”

The code looks like:

physics.newJoint( "weld", self, event.other, self.x, self.y)

What is “argument #-1”? Lua tables indicies typically start at 1, so does that mean that issue is with “weld”? (That wouldn’t make much sense since a string won’t be nil.) So then is the issue with the second argument, “self”? And why is it marked with a minus sign, as #-1? Does that minus sign mean “start counting from the end” so the problem is with “self.y”?

You’re correct that Lua tables are 1-based indices. Unfortunately, I don’t think that this error is accurate for your bug. I suspect that ‘self’ is not a valid argument for your second argument and that the error is coming from an internal error within the physics API. Take a close look at the object that your ‘self’ references and maybe try the same call with a different object.

Thanks Horace, you were right that “self” wasn’t nil, but was in fact not a physics body. I’m still curious about the error message though. What does “#-1” mean? 

You hit the nail on the head with the “start counting from the end” thing. On the C side of things, the Lua API uses a stack, and the operations that actually do stuff to things (as opposed to just reading values) primarily operate on the top elements of the stack. So the library code had just pushed a copy of self and was doing some sanity checks before trying to do something with it.

You’re correct that Lua tables are 1-based indices. Unfortunately, I don’t think that this error is accurate for your bug. I suspect that ‘self’ is not a valid argument for your second argument and that the error is coming from an internal error within the physics API. Take a close look at the object that your ‘self’ references and maybe try the same call with a different object.

Thanks Horace, you were right that “self” wasn’t nil, but was in fact not a physics body. I’m still curious about the error message though. What does “#-1” mean? 

You hit the nail on the head with the “start counting from the end” thing. On the C side of things, the Lua API uses a stack, and the operations that actually do stuff to things (as opposed to just reading values) primarily operate on the top elements of the stack. So the library code had just pushed a copy of self and was doing some sanity checks before trying to do something with it.