1
3
#include "JSParser.h"
10
static JSClass _js_global_class = {
11
"global", JSCLASS_GLOBAL_FLAGS,
12
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
13
JS_StrictPropertyStub,
14
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
15
JSCLASS_NO_OPTIONAL_MEMBERS
19
GameJSParser * game_js_parser_new (Game * game,
22
GameJSParser * self = malloc (sizeof(GameJSParser));
23
if (file_name != NULL && stript != NULL) {
25
"============================================================================\n"
26
"You can not use both a script and a file when creating a GameJSParser.\n"
27
"Exacly ONE of these must be used.\n"
28
"============================================================================\n"
30
game_js_parser_free (self);
32
} else if (file_name == NULL && stript == NULL) {
34
"============================================================================\n"
35
"WARNING: No script or file is set when constructing GameJSParser\n"
36
"============================================================================\n"
39
game_js_parser_free (self);
43
self->js_rt = JS_NewRuntime (JS_RUNTIME_SIZE);
47
"============================================================================\n"
48
"Could not contruct JSRunTime.\n"
49
"============================================================================\n"
54
self->js_cx = JS_NewContext (self->js_rt, 1024 * 8); /** Do not change. **/
58
"============================================================================\n"
59
"Could not contruct JSContext.\n"
60
"============================================================================\n"
62
game_js_parser_free (self);
65
self->js_global = JS_NewGlobalObject (self->js_cx, _js_global_class, NULL);
66
if (!self->js_global) {
68
"============================================================================\n"
69
"Could not contruct JS runtime the global object.\n"
70
"============================================================================\n"
72
game_js_parser_free (self);
82
void game_js_parser_free (GameJSParser * self) {
83
if (self->file_name) {
84
free (self->file_name);
91
JS_DestroyContext (self->js_cx);
93
JS_DestroyRuntime (self->js_rt);
98
void game_js_parser_set_settings_loader (GameJSParser * self,
99
GameJSParserLoadDataFunc func) {
100
self->load_data_func = func;
103
void game_js_parser_set_settings_dump (GameJSParser * self,
104
GameJSParserDumpDataFunc func) {
105
self->dump_data_func = func;
108
void * game_js_parser_load_settings (GameJSParser * self, void * data) {
109
GameJSParserDumpDataFunc func = self->load_data_func;
112
void * game_js_parser_dump_settings (GameJSParser * self) {
113
GameJSParserDumpDataFunc func = self->dump_data_func;