lua_tothread

http://arcemu.org/forums/index.php?showtopic=19327
 
 
    Hello.

Call to lua function from c using yielded lua_State works fine. But  same call with line hook set crashes in lvm.c line 71.
    Lua version 5.1.4

    Code to reproduce:

#include <stdio.h>

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

void testHook(lua_State *L, lua_Debug *ar)
{
    static int c = 0;
    c++;
}

int main(void)
{
    lua_State* l = lua_open();
    luaopen_base(l);

lua_sethook(l, testHook, LUA_MASKLINE, 0); //works fine when  this line is commented
    const char* script =   "function func()    \
                                print('func1')    \
                            end    \
                            function threadFunc()    \
                                print('before yield')    \
                                coroutine.yield()    \
                                print('after yield')    \
                            end    \
                            thread = coroutine.create(threadFunc)    \
                            coroutine.resume(thread)    \
                            ";
    int rez = luaL_dostring(l, script);
    if (rez) {
        return 1;
    }

    lua_getglobal(l, "thread");
    lua_State* thread = lua_tothread(l, -1);

lua_getglobal(thread, "func"); //will work too if "l" state is  used....
    if (lua_pcall(thread, 0, 0, 0)) {
        return 1;
    }

    lua_resume(thread, 0);

    return 0;
}

I believe that it should either work in both cases (wonder how?...)  or report error even if no hook set...
--
WBR, Anatoly Ahmedov
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值