Re: Lua_tostring weirdness

  • From: Mike Pall <mike-1208@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 7 Aug 2012 13:31:22 +0200

rob wrote:
> Using Lua, lua_tostring returns string pointers and a null pointer
> if the given index in the stack does not exist, e.g. -1 when a
> registered C function passes no arguments from Lua.

There's a difference between 'acceptable' and 'valid' stack
indexes. Please check the Lua 5.1 manual, section 3.1 and 3.2.

Your use of index -1 with no arguments on stack is not ok -- you're
relying on undefined behavior. In fact, it'd trigger an assertion
from the plain Lua VM (if you had enabled them).

> Is there a way to check if a given stack index is empty, i.e. there
> is no passed value, or have a null pointer returned?

Use lua_isnone() with an acceptable index, e.g. +1 for the first


Other related posts: