/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape

« back to all changes in this revision

Viewing changes to JSParser.h

  • Committer: Gustav Hartvigsson
  • Date: 2014-01-09 20:50:51 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140109205051-4j1veaw5fwux8591
created a generic error print function that should print nice looking
error messages, supports formating...
Not tested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
6
1
#ifndef __H_JS_PARSER__
7
2
#define __H_JS_PARSER__
8
3
 
9
4
/** @file
10
 
 * 
 
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
11
10
 *
12
11
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
13
12
 *
 
13
 * Thanks to:
 
14
 * https://btwotch.wordpress.com/2013/03/05/embedding-javascript-via-spidermonkey-into-c/
14
15
 */
15
16
 
16
 
#include "duktape.h"
 
17
#include <js/jsapi.h>
17
18
#include "Game.h"
18
19
 
 
20
/**
 
21
 * The maximum size of the memory after which GC is run.
 
22
 */
 
23
#define JS_RUNTIME_SIZE 1024*64
 
24
 
19
25
/******************************************************************************/
20
26
 
21
 
typedef struct GameJSParser GameJSParser;
22
 
 
23
27
/**
24
28
 * Function prototype to be used for loading context data, this is user-defined
25
29
 * so any data can be loaded into the JS context.
35
39
 * The data structure that represents the EcmaScript/JavaScript parser/engine
36
40
 * that can be used when creating games.
37
41
 */
38
 
typedef struct GameJSParser {
 
42
typedef struct _GameJSParser {
39
43
  GameJSParserLoadDataFunc load_data_func;
40
44
  GameJSParserDumpDataFunc dump_data_func;
41
45
  
42
 
  duk_context * ctx;
43
 
  duk_function_list_entry * function_array;
 
46
  JSRuntime * js_rt;
 
47
  JSContext * js_cx;
 
48
  JSObject * js_global;
 
49
  
 
50
  JSFunctionSpec * js_global_funcs; /**< Treat as an array, end with NULL */
 
51
  
44
52
  
45
53
  Game * game; /**< DO NOT FREE! */
46
54
  
47
 
  char * file_name;
48
 
  char * script;
 
55
  char * game_script_file_name;
 
56
  char * game_script;
49
57
} GameJSParser;
50
58
 
51
59
/******************************************************************************/
74
82
void game_js_parser_set_settings_dump (GameJSParser * self,
75
83
                                              GameJSParserDumpDataFunc func);
76
84
 
77
 
void game_js_parser_load_settings (GameJSParser * self, void * data);
 
85
void * game_js_parser_load_settings (GameJSParser * self, void * data);
78
86
 
79
87
void * game_js_parser_dump_settings (GameJSParser * self);
80
88
 
81
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
 
82
107
void game_js_parser_run (GameJSParser * self);
83
108
 
84
109
/******************************************************************************/