Skip to content

Commit

Permalink
Merge branch 'callbackhell' into 'master'
Browse files Browse the repository at this point in the history
Use the actual callback function instead of mocking it

Closes #8183

See merge request OpenMW/openmw!4452
  • Loading branch information
Capostrophic committed Nov 24, 2024
2 parents 97522c2 + 5dbe86e commit 9351a0e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions apps/components_tests/lua/test_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ namespace
void SetUp() override
{
mLua.protectedCall([&](LuaUtil::LuaView& view) {
view.sol()["callback"] = [](sol::this_state state, sol::protected_function fn) -> LuaUtil::Callback {
sol::table hiddenData(state, sol::create);
hiddenData[LuaUtil::ScriptsContainer::sScriptIdKey] = LuaUtil::ScriptId{};
return LuaUtil::Callback{ std::move(fn), hiddenData };
};
view.sol()["pass"] = [&](LuaUtil::Callback callback) { mCb = callback; };
sol::table hiddenData(view.sol(), sol::create);
hiddenData[LuaUtil::ScriptsContainer::sScriptIdKey] = LuaUtil::ScriptId{};
view.sol()["async"] = LuaUtil::getAsyncPackageInitializer(
view.sol(), []() { return 0.; }, []() { return 0.; })(hiddenData);
view.sol()["pass"] = [&](const sol::table& t) { mCb = LuaUtil::Callback::fromLua(t); };
});
}

Expand All @@ -34,7 +33,7 @@ namespace
view.sol().safe_script(R"X(
local s = 'test'
coroutine.wrap(function()
pass(callback(function(v) print(s) end))
pass(async:callback(function(v) print(s) end))
end)()
)X");
view.sol().collect_garbage();
Expand All @@ -48,7 +47,7 @@ namespace
mLua.protectedCall([&](LuaUtil::LuaView& view) {
view.sol().safe_script(R"X(
coroutine.wrap(function()
pass(callback(function() error('COROUTINE CALLBACK') end))
pass(async:callback(function() error('COROUTINE CALLBACK') end))
end)()
)X");
view.sol().collect_garbage();
Expand Down

0 comments on commit 9351a0e

Please sign in to comment.