1
#ifndef __H_JS_PARSER__
2
#define __H_JS_PARSER__
5
* This is based of MozJS/Spidermonkey from mozilla, pleace see
6
* .../js/jsapi.h for more information on the licenses used.
8
* This file, as the rest of the project is under MIT license.
9
* see http://opensource.org/licenses/MIT
11
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2013
14
* https://btwotch.wordpress.com/2013/03/05/embedding-javascript-via-spidermonkey-into-c/
21
* Function prototype to be used for loading context data, this is user-defined
22
* so any data can be loaded into the JS context.
24
typedef void (* GameJSParserLoadDataFunc)(GameJSParser * self, void * data);
27
* Function that is used to dump data from the JS context, it is user-defined.
29
typedef void * (* GameJSParserDumpDataFunc)(GameJSParser * self);
32
* The data structure that represents the EcmaScript/JavaScript parser/engine
33
* that can be used when creating games.
35
typedef struct _GameJSParser {
36
GameJSParserLoadDataFunc load_data_func;
37
GameJSParserDumpDataFunc dump_data_func;
43
JSFunctionSpec * js_global_funcs; /**< Treat as an array, end with NULL */
46
Game * game; /**< DO NOT FREE! */
48
char * game_script_file_name;
53
* Need to know a bit about the game, like screen and renderer and such.
55
* Note that file_name and script parameters are mutually exclusive. If both are
56
* set, the function will return NULL, and print an error to stderr.
58
GameJSParser * game_js_parser_new (Game * game,
65
void game_js_parser_free (GameJSParser * self);
70
void game_js_parser_set_settings_loader (GameJSParser * self,
71
GameJSParserLoadDataFunc func);
73
void game_js_parser_set_settings_dump (GameJSParser * self,
74
GameJSParserDumpDataFunc func);
76
void * game_js_parser_load_settings (GameJSParser * self, void * data);
78
void * game_js_parser_dump_settings (GameJSParser * self);
82
* This just wraps JS_DefineFunction:
83
* https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_DefineFunction
85
void game_js_parser_add_js_global_callback (GameJSParser * self,
91
void game_js_parser_add_js_private_callback (GameJSParser * self,
98
void game_js_parser_run (GameJSParser * self);