-
Notifications
You must be signed in to change notification settings - Fork 0
/
js_shell.h
44 lines (34 loc) · 908 Bytes
/
js_shell.h
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
43
44
#ifndef JS_SHELL_H
#define JS_SHELL_H
#include "duktape.h"
#include "json/json.h"
class JSScript {
public:
JSScript() : ctx(NULL), isComplete(true) {};
JSScript (const std::string& filename);
void init(const std::string& filename);
~JSScript();
virtual void run();
void printError(const std::string &message);
void varNotFound(const std::string &variable, const std::string reason);
template<typename T> T get(const std::string &variable);
bool error() { return ctx == NULL; }
protected:
bool isComplete;
duk_context *ctx;
virtual void pre_run() {};
virtual void post_run() {};
};
class Game;
class JSRegion : public JSScript {
public:
JSRegion() {};
JSRegion(const std::string& name, Game *g) : JSScript(name), game(g) {};
void move(const std::string ®ion, Json::Value args);
void render();
Game *game;
private:
void pre_run();
void post_run();
};
#endif /* JS_SHELL_H */