Skip to content

Commit

Permalink
Remove LuaCoroutine(const sol::function&) constructor
Browse files Browse the repository at this point in the history
Use static method `create(const sol::function&)` instead.
  • Loading branch information
gilzoide committed Oct 8, 2023
1 parent c2130a3 commit e874a6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/LuaCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ namespace luagdextension {

LuaCoroutine::LuaCoroutine(sol::thread&& thread) : thread(thread) {}
LuaCoroutine::LuaCoroutine(const sol::thread& thread) : thread(thread) {}
LuaCoroutine::LuaCoroutine(const sol::function& function) {
thread = sol::thread::create(function.lua_state());
function.push(thread.thread_state());
}

LuaCoroutine::~LuaCoroutine() {
#if LUA_VERSION_NUM >= 504
lua_closethread(thread.lua_state(), NULL);
#endif
}

LuaCoroutine *LuaCoroutine::create(const sol::function& function) {
sol::thread thread = sol::thread::create(function.lua_state());
function.push(thread.thread_state());
return memnew(LuaCoroutine(thread));
}

LuaCoroutine *LuaCoroutine::create(LuaFunction *function) {
ERR_FAIL_COND_V_MSG(!function, nullptr, "Function cannot be null");
return memnew(LuaCoroutine(function->get_function()));
return create(function->get_function());
}

LuaCoroutine::LuaCoroutineStatus LuaCoroutine::get_status() const {
Expand Down
2 changes: 1 addition & 1 deletion src/LuaCoroutine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class LuaCoroutine : public RefCounted {
LuaCoroutine() = default;
LuaCoroutine(sol::thread&& thread);
LuaCoroutine(const sol::thread& thread);
LuaCoroutine(const sol::function& function);
~LuaCoroutine();

static LuaCoroutine *create(const sol::function& function);
static LuaCoroutine *create(LuaFunction *function);

LuaCoroutineStatus get_status() const;
Expand Down

0 comments on commit e874a6f

Please sign in to comment.