/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad
7 by Gustav Hartvigsson
* Added licensing information to the files.
1
#ifndef __H_JS_PARSER__
2
#define __H_JS_PARSER__
3
4
/** @file
5
 * This is based of MozJS/Spidermonkey from mozilla, pleace see 
6
 * .../js/jsapi.h for more information on the licenses used.
7
 *
8
 * This file, as the rest of the project is under MIT license.
9
 * see http://opensource.org/licenses/MIT
10
 *
11
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2013
12
 *
13
 * Thanks to:
14
 * https://btwotch.wordpress.com/2013/03/05/embedding-javascript-via-spidermonkey-into-c/
15
 */
16
17
#include <js/jsapi.h>
18
#include "Game.h"
19
20
/**
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.
23
 */
24
typedef void (* GameJSParserLoadDataFunc)(GameJSParser * self, void * data);
25
26
/**
27
 * Function that is used to dump data from the JS context, it is user-defined.
28
 */
29
typedef void * (* GameJSParserDumpDataFunc)(GameJSParser * self);
30
31
/**
32
 * The data structure that represents the EcmaScript/JavaScript parser/engine
33
 * that can be used when creating games.
34
 */
35
typedef struct _GameJSParser {
36
  GameJSParserLoadDataFunc load_data_func;
37
  GameJSParserDumpDataFunc dump_data_func;
38
  
39
  JSRuntime * js_rt;
40
  JSContext * js_cx;
41
  JSObject * js_global;
42
  
43
  JSFunctionSpec * js_global_funcs; /**< Treat as an array, end with NULL */
44
  
45
  
46
  Game * game; /**< DO NOT FREE! */
47
  
48
  char * game_script_file_name;
49
  char * game_script;
50
} GameJSParser;
51
52
/**
53
 * Need to know a bit about the game, like screen and renderer and such.
54
 *
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.
57
 */
58
GameJSParser * game_js_parser_new (Game * game,
59
                                   char * file_name,
60
                                   char * script);
61
62
/**
63
 * 
64
 */
65
void game_js_parser_free (GameJSParser * self);
66
67
/**
68
 * 
69
 */
70
void game_js_parser_set_settings_loader (GameJSParser * self,
71
                                              GameJSParserLoadDataFunc func);
72
73
void game_js_parser_set_settings_dump (GameJSParser * self,
74
                                              GameJSParserDumpDataFunc func);
75
76
void * game_js_parser_load_settings (GameJSParser * self, void * data);
77
78
void * game_js_parser_dump_settings (GameJSParser * self);
79
80
81
/**
82
 * This just wraps JS_DefineFunction:
83
 * https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_DefineFunction
84
 */
85
void game_js_parser_add_js_global_callback (GameJSParser * self,
86
                                            const char * name,
87
                                            JSNative call,
88
                                            uint16 nargs,
89
                                            uint16 flags);
90
91
void game_js_parser_add_js_private_callback (GameJSParser * self,
92
                                            JSObject * context,
93
                                            const char * name,
94
                                            JSNative call,
95
                                            uint16 nargs,
96
                                            uint16 flags);
97
98
void game_js_parser_run (GameJSParser * self);
99
100
#endif