免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1880 | 回复: 1
打印 上一主题 下一主题

[其他] 这段lua在5.1里为什么会core? [复制链接]

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-11 15:17 |只看该作者 |倒序浏览
  1. #include "lua.h"
  2. #include "lualib.h"
  3. #include "lauxlib.h"

  4. int n = 0;

  5. int func(lua_State *L) {
  6.     printf("func_top=%d top=%s\n", lua_gettop(L), lua_tostring(L, -1));
  7.     if (!n) {
  8.         ++ n;
  9.         return lua_yield(L, 1);
  10.     } else {
  11.         return 1;
  12.     }
  13. }

  14. int main(int argc, char* const argv[]) {
  15.     lua_State *L = luaL_newstate();

  16.     /* init lua library */   
  17.     lua_pushcfunction(L, luaopen_base);
  18.     if (lua_pcall(L, 0, 0, 0) != 0) {
  19.         return 1;
  20.     }
  21.     lua_pushcfunction(L, luaopen_package);
  22.     if (lua_pcall(L, 0, 0, 0 ) != 0) {
  23.         return 2;
  24.     }
  25.    
  26.     /* create the coroutine */
  27.     lua_State *LL = lua_newthread(L);

  28.     lua_pushcfunction(LL, func);
  29.     lua_pushstring(LL, "hello world");
  30.    
  31.     /* first time resume */
  32.     if (lua_resume(LL, 1) == LUA_YIELD) {
  33.         printf("first_top=%d top_string=%s\n", lua_gettop(LL), lua_tostring(LL, -1));
  34.         /* twice resume */
  35.         if (lua_resume(LL, 1) == 0) {
  36.             printf("second_top=%d top_string=%s\n", lua_gettop(LL), lua_tostring(LL, -1));
  37.         }
  38.     }

  39.     lua_close(L);

  40.     return 0;
  41. }
复制代码
func_top=1 top=hello world
first_top=1 top_string=hello world
Segmentation fault (core dumped)

#0  0x000000000040e1d5 in luaV_execute ()
(gdb) bt
#0  0x000000000040e1d5 in luaV_execute ()
#1  0x00000000004059ae in luaD_rawrunprotected ()
#2  0x000000000040666c in lua_resume ()
#3  0x0000000000402bbc in main ()

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
2 [报告]
发表于 2013-01-11 15:49 |只看该作者
在网上找到类似问题,

http://lua-users.org/lists/lua-l/2010-04/msg00401.html

应该是说5.1不支持lua_resume一个c函数, 怨不着在5.2里可以了.

是这样吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP