(Ret) , Lua.
Luabind , , coroutine.yield.
, , ? resume_function ?
, .
, , ( ) ? , , .
; . , , , .
Ret, ?
. . , .
: Lua . , Luabind, , , Lua , . , Luabind . , , /, , , Ret.
loadImage ++, , lua_yield, luabind:: resume_function img .
Luabind, lua_yield . Luabind - , , , . :
module(L)
[
def("do_thing_that_takes_time", &do_thing_that_takes_time, yield)
];
, ++, . Luabind, Lua, , , .
, , Lua coroutines - , . ; , coroutine.resume .
, Lua C/++; Lua ( lua_State).
, , , , Lua ++, , Lua , , .
, Lua script , ++. loadImage coroutine; , ++. Lua script , , , .
, , - , Lua script , . Lua script , ++ , . - :
function loadImageAsCoroutine(imageFilename)
local cppThread = cpp.loadImage(imageFilename);
local function threadFunc(cppThread)
if(cppThread:isFinished()) then
local data = cppThread:GetImage();
return data;
else
coroutine.yield();
end
end
local thread = coroutine.create(threadFunc);
local errors, data = assert(coroutine.resume(thread, cppThread));
if(coroutine.status(thread) == "dead") then
return data;
else
return thread;
end
end
coroutine . ; "thread", ++ . .
, , coroutine.resume ( luabind:: resume_function - ). . nil, ++ , nil .