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