/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad
21 by Gustav Hatvigsson
* added Modeline to (almost) all files.
1
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
2
 * vi: set shiftwidth=2 tabstop=2 expandtab:
3
 * :indentSize=2:tabSize=2:noTabs=true:
4
 */
5
7 by Gustav Hartvigsson
* Added licensing information to the files.
6
#ifndef __H_JS_PARSER__
7
#define __H_JS_PARSER__
8
9
/** @file
10
 * This is based of MozJS/Spidermonkey from mozilla, pleace see 
11
 * .../js/jsapi.h for more information on the licenses used.
12
 *
13
 * This file, as the rest of the project is under MIT license.
14
 * see http://opensource.org/licenses/MIT
15
 *
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
16
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
7 by Gustav Hartvigsson
* Added licensing information to the files.
17
 *
18
 * Thanks to:
19
 * https://btwotch.wordpress.com/2013/03/05/embedding-javascript-via-spidermonkey-into-c/
20
 */
21
22
#include <js/jsapi.h>
23
#include "Game.h"
24
25
/**
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
26
 * The maximum size of the memory after which GC is run.
27
 */
28
#define JS_RUNTIME_SIZE 1024*64
29
30
/******************************************************************************/
31
16 by Gustav Hartvigsson
* made the code compile.
32
typedef struct GameJSParser GameJSParser;
33
34
/**
35
 * Function prototype to be used for loading context data, this is user-defined
36
 * so any data can be loaded into the JS context.
37
 */
38
typedef void (* GameJSParserLoadDataFunc)(GameJSParser * self, void * data);
39
40
/**
41
 * Function that is used to dump data from the JS context, it is user-defined.
42
 */
43
typedef void * (* GameJSParserDumpDataFunc)(GameJSParser * self);
44
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
45
/**
7 by Gustav Hartvigsson
* Added licensing information to the files.
46
 * The data structure that represents the EcmaScript/JavaScript parser/engine
47
 * that can be used when creating games.
48
 */
12 by Gustav Hartvigsson
* reorganising code to be remove extra typedefs.
49
typedef struct GameJSParser {
7 by Gustav Hartvigsson
* Added licensing information to the files.
50
  GameJSParserLoadDataFunc load_data_func;
51
  GameJSParserDumpDataFunc dump_data_func;
52
  
53
  JSRuntime * js_rt;
54
  JSContext * js_cx;
55
  JSObject * js_global;
56
  
57
  JSFunctionSpec * js_global_funcs; /**< Treat as an array, end with NULL */
58
  
59
  
60
  Game * game; /**< DO NOT FREE! */
61
  
16 by Gustav Hartvigsson
* made the code compile.
62
  char * file_name;
63
  char * script;
7 by Gustav Hartvigsson
* Added licensing information to the files.
64
} GameJSParser;
65
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
66
/******************************************************************************/
67
7 by Gustav Hartvigsson
* Added licensing information to the files.
68
/**
69
 * Need to know a bit about the game, like screen and renderer and such.
70
 *
71
 * Note that file_name and script parameters are mutually exclusive. If both are
72
 * set, the function will return NULL, and print an error to stderr.
73
 */
74
GameJSParser * game_js_parser_new (Game * game,
75
                                   char * file_name,
76
                                   char * script);
77
78
/**
79
 * 
80
 */
81
void game_js_parser_free (GameJSParser * self);
82
83
/**
84
 * 
85
 */
86
void game_js_parser_set_settings_loader (GameJSParser * self,
87
                                              GameJSParserLoadDataFunc func);
88
89
void game_js_parser_set_settings_dump (GameJSParser * self,
90
                                              GameJSParserDumpDataFunc func);
91
16 by Gustav Hartvigsson
* made the code compile.
92
void game_js_parser_load_settings (GameJSParser * self, void * data);
7 by Gustav Hartvigsson
* Added licensing information to the files.
93
94
void * game_js_parser_dump_settings (GameJSParser * self);
95
96
97
/**
98
 * This just wraps JS_DefineFunction:
99
 * https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_DefineFunction
100
 */
101
void game_js_parser_add_js_global_callback (GameJSParser * self,
102
                                            const char * name,
103
                                            JSNative call,
104
                                            uint16 nargs,
105
                                            uint16 flags);
106
107
void game_js_parser_add_js_private_callback (GameJSParser * self,
108
                                            JSObject * context,
109
                                            const char * name,
110
                                            JSNative call,
111
                                            uint16 nargs,
112
                                            uint16 flags);
113
114
void game_js_parser_run (GameJSParser * self);
115
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
116
/******************************************************************************/
117
118
7 by Gustav Hartvigsson
* Added licensing information to the files.
119
#endif