/+junk/c_sdl_joypad

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

« back to all changes in this revision

Viewing changes to JSParser.c

  • 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
1
#include <stdio.h>
2
2
#include <string.h>
 
3
#include "game_utils.h"
3
4
#include "JSParser.h"
4
5
 
5
6
/**
26
27
                                   char * script) {
27
28
  GameJSParser * self = malloc (sizeof(GameJSParser));
28
29
  if (file_name != NULL && stript != NULL) {
29
 
    fprintf (stderr,
30
 
"============================================================================\n"
31
 
"You can not use both a script and a file when creating a GameJSParser.\n"
32
 
"Exacly ONE of these must be used.\n"
33
 
"============================================================================\n"
 
30
    print_error (
 
31
      "You can not use both a script and a file when creating a GameJSParser."
 
32
      "Exacly ONE of these must be used.\n"
34
33
    );
35
34
    game_js_parser_free (self);
36
35
    return NULL;
37
36
  } else if (file_name == NULL && stript == NULL) {
38
 
    fprintf (stderr,
39
 
"============================================================================\n"
40
 
"WARNING: No script or file is set when constructing GameJSParser\n"
41
 
"============================================================================\n"
 
37
    print_error (
 
38
      "WARNING: No script or file is set when constructing GameJSParser"
42
39
    );
43
40
  }
44
41
  
45
42
  self->js_rt = JS_NewRuntime (JS_RUNTIME_SIZE);
46
43
  
47
44
  if (!self->js_rt) {
48
 
    fprintf (stderr,
49
 
"============================================================================\n"
50
 
"Could not contruct JSRunTime.\n"
51
 
"============================================================================\n"
52
 
    );
 
45
    print_error ("Could not contruct JSRunTime.");
53
46
    return NULL;
54
47
  }
55
48
  
56
49
  self->js_cx = JS_NewContext (self->js_rt, 1024 * 8); /** Do not change. **/
57
50
  
58
51
  if (!self->js_cx) {
59
 
    fprintf (stderr,
60
 
"============================================================================\n"
61
 
"Could not contruct JSContext.\n"
62
 
"============================================================================\n"
63
 
    );
 
52
    print_error ("Could not contruct JSContext.");
64
53
    game_js_parser_free (self);
65
54
    return NULL;
66
55
  }
67
56
  self->js_global = JS_NewGlobalObject (self->js_cx, _js_global_class, NULL);
68
57
  if (!self->js_global) {
69
 
    fprintf (stderr,
70
 
"============================================================================\n"
71
 
"Could not contruct the JS runtime global object.\n"
72
 
"============================================================================\n"
73
 
    );
 
58
    print_error ( "Could not contruct the JS runtime global object.");
74
59
    game_js_parser_free (self);
75
60
    return NULL;
76
61
  }