在从 Lua、lua_type(L,0) returns 9 调用的 C++ 中,未记录
In C++ called from Lua, lua_type(L,0) returns 9 which isn't documented
我在我的 (C++) 游戏中使用 Lua 作为脚本语言。
在一次调用中(从 lua 到 c++)我检查堆栈顶部的类型:
if(lua_type(L, (0)) == LUA_TSTRING)
但有时 lua_type(L, (0)) returns 9.
我似乎找不到对此的任何引用(return 值应介于 -1 和 8 或 LUA_TNONE、LUA_TNIL、... LUA_TTHREAD).
发生了什么事?
栈顶索引为 -1,而不是 0。
0 永远不能用作访问堆栈的索引:
(Note that 0 is never an acceptable index.)
参考手册中的§4.3 – Valid and Acceptable Indices。
Lua中的CAPI不牵程序员的手:
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]
我在我的 (C++) 游戏中使用 Lua 作为脚本语言。 在一次调用中(从 lua 到 c++)我检查堆栈顶部的类型:
if(lua_type(L, (0)) == LUA_TSTRING)
但有时 lua_type(L, (0)) returns 9.
我似乎找不到对此的任何引用(return 值应介于 -1 和 8 或 LUA_TNONE、LUA_TNIL、... LUA_TTHREAD).
发生了什么事?
栈顶索引为 -1,而不是 0。
0 永远不能用作访问堆栈的索引:
(Note that 0 is never an acceptable index.)
参考手册中的§4.3 – Valid and Acceptable Indices。
Lua中的CAPI不牵程序员的手:
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]