/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
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
 *
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
11
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
7 by Gustav Hartvigsson
* Added licensing information to the files.
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
/**
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
21
 * The maximum size of the memory after which GC is run.
22
 */
23
#define JS_RUNTIME_SIZE 1024*64
24
25
/******************************************************************************/
26
27
/**
7 by Gustav Hartvigsson
* Added licensing information to the files.
28
 * The data structure that represents the EcmaScript/JavaScript parser/engine
29
 * that can be used when creating games.
30
 */
12 by Gustav Hartvigsson
* reorganising code to be remove extra typedefs.
31
typedef struct GameJSParser {
7 by Gustav Hartvigsson
* Added licensing information to the files.
32
  GameJSParserLoadDataFunc load_data_func;
33
  GameJSParserDumpDataFunc dump_data_func;
34
  
35
  JSRuntime * js_rt;
36
  JSContext * js_cx;
37
  JSObject * js_global;
38
  
39
  JSFunctionSpec * js_global_funcs; /**< Treat as an array, end with NULL */
40
  
41
  
42
  Game * game; /**< DO NOT FREE! */
43
  
44
  char * game_script_file_name;
45
  char * game_script;
46
} GameJSParser;
47
12 by Gustav Hartvigsson
* reorganising code to be remove extra typedefs.
48
/**
49
 * Function prototype to be used for loading context data, this is user-defined
50
 * so any data can be loaded into the JS context.
51
 */
52
typedef void (* GameJSParserLoadDataFunc)(GameJSParser * self, void * data);
53
54
/**
55
 * Function that is used to dump data from the JS context, it is user-defined.
56
 */
57
typedef void * (* GameJSParserDumpDataFunc)(GameJSParser * self);
58
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
59
/******************************************************************************/
60
7 by Gustav Hartvigsson
* Added licensing information to the files.
61
/**
62
 * Need to know a bit about the game, like screen and renderer and such.
63
 *
64
 * Note that file_name and script parameters are mutually exclusive. If both are
65
 * set, the function will return NULL, and print an error to stderr.
66
 */
67
GameJSParser * game_js_parser_new (Game * game,
68
                                   char * file_name,
69
                                   char * script);
70
71
/**
72
 * 
73
 */
74
void game_js_parser_free (GameJSParser * self);
75
76
/**
77
 * 
78
 */
79
void game_js_parser_set_settings_loader (GameJSParser * self,
80
                                              GameJSParserLoadDataFunc func);
81
82
void game_js_parser_set_settings_dump (GameJSParser * self,
83
                                              GameJSParserDumpDataFunc func);
84
85
void * game_js_parser_load_settings (GameJSParser * self, void * data);
86
87
void * game_js_parser_dump_settings (GameJSParser * self);
88
89
90
/**
91
 * This just wraps JS_DefineFunction:
92
 * https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_DefineFunction
93
 */
94
void game_js_parser_add_js_global_callback (GameJSParser * self,
95
                                            const char * name,
96
                                            JSNative call,
97
                                            uint16 nargs,
98
                                            uint16 flags);
99
100
void game_js_parser_add_js_private_callback (GameJSParser * self,
101
                                            JSObject * context,
102
                                            const char * name,
103
                                            JSNative call,
104
                                            uint16 nargs,
105
                                            uint16 flags);
106
107
void game_js_parser_run (GameJSParser * self);
108
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
109
/******************************************************************************/
110
111
7 by Gustav Hartvigsson
* Added licensing information to the files.
112
#endif