/+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.c

  • Committer: Gustav Hartvigsson
  • Date: 2014-01-09 20:07:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140109200752-owx481zfl2n4tjsc
* added and changed little in the files Lincening information.
* Started to implement the JS parser's C file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
2
#include <string.h>
3
 
#include "game_utils.h"
4
3
#include "JSParser.h"
5
4
 
6
 
/**
7
 
 * This file, as the rest of the project is under MIT license.
8
 
 * see http://opensource.org/licenses/MIT
9
 
 *
10
 
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
11
 
 */
 
5
 
12
6
 
13
7
/*
14
8
  The global JS Class.
27
21
                                   char * script) {
28
22
  GameJSParser * self = malloc (sizeof(GameJSParser));
29
23
  if (file_name != NULL && stript != NULL) {
30
 
    print_error (
31
 
      "You can not use both a script and a file when creating a GameJSParser.\n"
32
 
      "Exacly ONE of these must be used."
 
24
    fprintf (stderr,
 
25
"============================================================================\n"
 
26
"You can not use both a script and a file when creating a GameJSParser.\n"
 
27
"Exacly ONE of these must be used.\n"
 
28
"============================================================================\n"
33
29
    );
34
30
    game_js_parser_free (self);
35
31
    return NULL;
36
32
  } else if (file_name == NULL && stript == NULL) {
37
 
    print_error (
38
 
      "WARNING: No script or file is set when constructing GameJSParser"
 
33
    fprintf (stderr,
 
34
"============================================================================\n"
 
35
"WARNING: No script or file is set when constructing GameJSParser\n"
 
36
"============================================================================\n"
39
37
    );
 
38
  } else {
 
39
    game_js_parser_free (self);
 
40
    return NULL;
40
41
  }
41
42
  
42
43
  self->js_rt = JS_NewRuntime (JS_RUNTIME_SIZE);
43
44
  
44
45
  if (!self->js_rt) {
45
 
    print_error ("Could not contruct JSRunTime.");
 
46
    fprintf (stderr,
 
47
"============================================================================\n"
 
48
"Could not contruct JSRunTime.\n"
 
49
"============================================================================\n"
 
50
    );
46
51
    return NULL;
47
52
  }
48
53
  
49
 
  self->js_cx = JS_NewContext (self->js_rt, 1024 * 8); /* Do not change. **/
 
54
  self->js_cx = JS_NewContext (self->js_rt, 1024 * 8); /** Do not change. **/
50
55
  
51
56
  if (!self->js_cx) {
52
 
    print_error ("Could not contruct JSContext.");
 
57
    fprintf (stderr,
 
58
"============================================================================\n"
 
59
"Could not contruct JSContext.\n"
 
60
"============================================================================\n"
 
61
    );
53
62
    game_js_parser_free (self);
54
63
    return NULL;
55
64
  }
56
65
  self->js_global = JS_NewGlobalObject (self->js_cx, _js_global_class, NULL);
57
66
  if (!self->js_global) {
58
 
    print_error ( "Could not contruct the JS runtime global object.");
 
67
    fprintf (stderr,
 
68
"============================================================================\n"
 
69
"Could not contruct JS runtime the global object.\n"
 
70
"============================================================================\n"
 
71
    );
59
72
    game_js_parser_free (self);
60
73
    return NULL;
61
74
  }