Valmond
Valmond

Reputation: 2959

In C++ called from Lua, lua_type(L,0) returns 9 which isn't documented

I'm using Lua as scripting language in my (C++) game. In one call (from lua to c++) I check what type is on the top of the stack:

if(lua_type(L, (0)) == LUA_TSTRING)

But sometimes lua_type(L, (0)) returns 9.

I can't seem to find any references to this (return values should be between -1 and 8 or LUA_TNONE, LUA_TNIL, ... LUA_TTHREAD).

What's happening?

Upvotes: 7

Views: 505

Answers (1)

lhf
lhf

Reputation: 72312

The top of the stack is at index -1, not 0.

0 can never be used as an index for accessing the stack:

(Note that 0 is never an acceptable index.)

in §4.3 – Valid and Acceptable Indices in the reference manual.

The C API in Lua does not hold the programmer's hand:

As in most C libraries, the Lua API functions do not check their arguments for validity or consistency. However, you can change this behavior by compiling Lua with the macro LUA_USE_APICHECK defined. [§4]

Upvotes: 5

Related Questions