lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It seems that lua_pcallk() can not be used in main thread of a lua_State?

btw, lua_resume() works


test code:


==lua script test.txt==
function dotest()
local a = mytest()
error("err from lua a="..a)
end


C++ code:


CluatestDlg::OnInitDialog()
{
......
l = luaL_newstate();
luaL_openlibs(l);
lua_register(l, "mytest", lua_mytest);
}


static int lua_mytest_con_func(lua_State* ls)
{
return 0;
}


void CluatestDlg::OnBnClickedButton3()
{
if(luaL_dofile(l, "test.txt")) return;
lua_getglobal(l, "dotest");


int ret = lua_pcallk(l, 0, 0, 0, 0, lua_mytest_con_func);
if(ret != 0)
{
const char* err = luaL_checkstring(l, -1);
//err : attempt to yield from outside a coroutine
TRACE(err);
}
}


//lua_resume works fine
void CluatestDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
if(luaL_dofile(l, "test.txt")) return;
    lua_getglobal(l, "dotest");


int ret = lua_resume(l, NULL, 0);
if((ret!=LUA_OK) && (ret!=LUA_YIELD))
{
const char* err = luaL_checkstring(l, -1);
TRACE(err);
return;
}


int b = ret + 1;
}


​​