-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.cpp
42 lines (34 loc) · 811 Bytes
/
action.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <mutex>
#include "action.h"
#include "stack.h"
#include "plane_binding.h"
using namespace std;
using namespace DP;
Action::Action(Stack &stack, Plane *plane)
: _stack(stack), _plane(plane), _L(NULL)
{
cout << "Action constructor" << endl;
}
Action::~Action()
{
if (_L)
lua_close(_L);
}
void Action::operator()()
{
cout << "Lua state initialization" << endl;
_L = luaL_newstate();
luaL_openlibs(_L);
registerPlane(_L, _plane);
while (true) {
unique_lock<mutex> lock(_stack._mutex);
while (!_stack.stopAsked() && _stack.queueEmpty()) {
_stack._condition.wait(lock);
}
if (_stack.stopAsked())
return;
DPTask *task = _stack.dequeueTask();
task->routine(_L);
}
}