fixes of review comments

This commit is contained in:
mihacooper 2017-01-20 14:16:29 +03:00
parent f8da71f2f1
commit 5f59d008be
4 changed files with 9 additions and 18 deletions

View File

@ -1,9 +1,4 @@
extern "C" #include "lua.hpp"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include "threading.h" #include "threading.h"
#include "shared-table.h" #include "shared-table.h"

View File

@ -69,4 +69,4 @@ TablePool& defaultPool() noexcept {
return pool; return pool;
} }
} // core } // share_data

View File

@ -18,19 +18,14 @@ LuaThread::LuaThread(const sol::function& function, const sol::variadic_args& ar
share_data::SharedTable::get_user_type(*p_state_); share_data::SharedTable::get_user_type(*p_state_);
// 3. Save parameters // 3. Save parameters
validate_args(args); store_args(args);
// 4. Run thread // 4. Run thread
p_thread_.reset(new std::thread(&LuaThread::work, this)); p_thread_.reset(new std::thread(&LuaThread::work, this));
assert(p_thread_.get() != NULL); assert(p_thread_.get() != NULL);
} }
LuaThread::~LuaThread() void LuaThread::store_args(const sol::variadic_args& args) noexcept
{
join();
}
void LuaThread::validate_args(const sol::variadic_args& args) noexcept
{ {
const auto end = --args.end(); const auto end = --args.end();
for(auto iter = args.begin(); iter != end; iter++) for(auto iter = args.begin(); iter != end; iter++)

View File

@ -1,19 +1,20 @@
#pragma once #pragma once
#include "shared-table.h"
#include <sol.hpp> #include <sol.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include "shared-table.h"
namespace threading { namespace threading {
class LuaThread class LuaThread
{ {
public: public:
LuaThread(const sol::function& function, const sol::variadic_args& args) noexcept; LuaThread(const sol::function& function, const sol::variadic_args& args) noexcept;
virtual ~LuaThread() noexcept; virtual ~LuaThread() noexcept = default;
void join() noexcept; void join() noexcept;
static std::string thread_id() noexcept; static std::string thread_id() noexcept;
@ -21,7 +22,7 @@ public:
private: private:
void work() noexcept; void work() noexcept;
void validate_args(const sol::variadic_args& args) noexcept; void store_args(const sol::variadic_args& args) noexcept;
std::string str_function_; std::string str_function_;
std::shared_ptr<sol::state> p_state_; std::shared_ptr<sol::state> p_state_;