2014-11-28 09:00:48 -05:00
|
|
|
#ifndef SCRIPTING_ENVIRONMENT_HPP
|
|
|
|
#define SCRIPTING_ENVIRONMENT_HPP
|
2012-11-19 13:04:59 -05:00
|
|
|
|
2014-05-16 07:26:42 -04:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2014-12-17 08:34:23 -05:00
|
|
|
#include <mutex>
|
2014-05-16 07:26:42 -04:00
|
|
|
#include <tbb/enumerable_thread_specific.h>
|
2012-11-19 13:04:59 -05:00
|
|
|
|
2013-12-23 11:55:29 -05:00
|
|
|
struct lua_State;
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
|
2015-04-10 09:46:49 -04:00
|
|
|
/**
|
|
|
|
* Creates a lua context and binds osmium way, node and relation objects and
|
|
|
|
* ExtractionWay and ExtractionNode to lua objects.
|
|
|
|
*
|
|
|
|
* Each thread has its own lua state which is implemented with thread specific
|
|
|
|
* storage from TBB.
|
|
|
|
*/
|
2014-05-09 10:17:31 -04:00
|
|
|
class ScriptingEnvironment
|
|
|
|
{
|
|
|
|
public:
|
2014-08-27 10:26:14 -04:00
|
|
|
ScriptingEnvironment() = delete;
|
2014-12-17 08:34:23 -05:00
|
|
|
explicit ScriptingEnvironment(const std::string &file_name);
|
2012-11-19 13:04:59 -05:00
|
|
|
|
2016-01-04 05:44:23 -05:00
|
|
|
lua_State *GetLuaState();
|
2012-11-19 13:04:59 -05:00
|
|
|
|
2014-05-16 07:26:42 -04:00
|
|
|
private:
|
2016-01-04 05:44:23 -05:00
|
|
|
void InitLuaState(lua_State *lua_state);
|
2015-01-22 06:19:11 -05:00
|
|
|
std::mutex init_mutex;
|
2014-05-16 07:26:42 -04:00
|
|
|
std::string file_name;
|
|
|
|
tbb::enumerable_thread_specific<std::shared_ptr<lua_State>> script_contexts;
|
2012-11-19 13:04:59 -05:00
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-28 09:00:48 -05:00
|
|
|
#endif /* SCRIPTING_ENVIRONMENT_HPP */
|