在从Lua调用的C中,lua_type(L,0)返回9,未记录

前端之家收集整理的这篇文章主要介绍了在从Lua调用的C中,lua_type(L,0)返回9,未记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的(C)游戏中使用Lua作为脚本语言.
在一次调用中(从lua到c)我检查堆栈顶部的类型:
if(lua_type(L,(0)) == LUA_TSTRING)

但有时lua_type(L,(0))返回9.

我似乎无法找到任何引用(返回值应介于-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中的C API没有程序员的手:

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. [07001]

原文链接:https://www.f2er.com/lua/274510.html

猜你在找的Lua相关文章