| |
    前两天在用lua_next遍历一个lua表的时候遇到了:PANIC: unprotected error in call to Lua API (invalid key to 'next')  仔细检查了下代码和堆栈信息,发现没有问题,但为什么会说遍历失败呢?

    找到文档看了下,原来lua_tolstring只支持number和string类型,但是对于number类型,在取值后也会转换其在表中的实际内容为string,而我遍历的表是使用默认自增索引作为key的,这样对key调用这个函数会导致key变成字符串,因而遍历有问题。

    如果表的key不一定是string,而又要用lua_tolstring获取它的值,那么建议先在栈上复制一份,然后对于复制的值进行获取。





Tags:
by snooda | 分类: c程序设计 | 评论(0) | 引用(0) | 阅读(5885)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]