diff --git a/src/manager.impl.cpp b/src/manager.impl.cpp index ec2bfd9..2bdf0ee 100644 --- a/src/manager.impl.cpp +++ b/src/manager.impl.cpp @@ -88,24 +88,19 @@ namespace loader return std::make_unique>(restore); }; - table["detour"] = [](sol::table table, const std::string &func, sol::function callback) - { - auto original = table.get(func); - - const auto detour = [=, callback = std::move(callback)](const sol::variadic_args &args) - { - return callback.call(original, sol::as_args(args)); - }; - - const auto restore = [=]() mutable - { - table[func] = original; - }; - - table[func] = detour; - - return std::make_unique>(restore); - }; + lua->do_string(R"lua( + mod_api.hooks.detour = function(table, func, callback) + local original = table[func] + + table[func] = function(...) + return callback(original, ...) + end + + return function() + table[func] = original + end + end + )lua"); auto require = lua->get>("require"); (*lua)["require"] = [this, require](const std::string &module)