variables.cxx

changeset 24
7dcc8419dbdb
parent 23
ba351235688e
child 32
d11a034aabfd
equal deleted inserted replaced
23:ba351235688e 24:7dcc8419dbdb
59 g_GlobalVariables[u] = NULL; 59 g_GlobalVariables[u] = NULL;
60 } 60 }
61 61
62 // Tries to declare a new global-scope variable. Returns pointer 62 // Tries to declare a new global-scope variable. Returns pointer
63 // to new global variable, NULL if declaration failed. 63 // to new global variable, NULL if declaration failed.
64 ScriptVar* DeclareGlobalVariable (ScriptReader* r, str name, int type) { 64 ScriptVar* DeclareGlobalVariable (ScriptReader* r, str name) {
65 // Apparently the Zandronum engine does not support string variables..
66 if (type == RETURNVAL_VOID || type == RETURNVAL_STRING)
67 return NULL;
68
69 // Find a NULL pointer to a global variable 65 // Find a NULL pointer to a global variable
70 ScriptVar* g; 66 ScriptVar* g;
71 unsigned int u = 0; 67 unsigned int u = 0;
72 ITERATE_GLOBAL_VARS (u) { 68 ITERATE_GLOBAL_VARS (u) {
73 // Check that it doesn't exist already 69 // Check that it doesn't exist already
83 79
84 g = new ScriptVar; 80 g = new ScriptVar;
85 g->index = u; 81 g->index = u;
86 g->name = name; 82 g->name = name;
87 g->statename = ""; 83 g->statename = "";
88 g->type = type;
89 g->next = NULL; 84 g->next = NULL;
90 g->value = (type == RETURNVAL_BOOLEAN) ? "false" : 85 g->value = 0;
91 (type == RETURNVAL_INT) ? "0" : "";
92 86
93 g_GlobalVariables[u] = g; 87 g_GlobalVariables[u] = g;
94 return g; 88 return g;
95 } 89 }
96 90
99 if (!g) 93 if (!g)
100 r->ParserError ("global variable %s not declared", name.chars()); 94 r->ParserError ("global variable %s not declared", name.chars());
101 }*/ 95 }*/
102 96
103 // Find a global variable by name 97 // Find a global variable by name
104 /* ScriptVar* FindScriptVariable (str name) { 98 ScriptVar* FindGlobalVariable (str name) {
105 ScriptVar* g; 99 unsigned int u = 0;
106 ITERATE_SCRIPT_VARS (g) 100 ITERATE_GLOBAL_VARS (u) {
101 ScriptVar* g = g_GlobalVariables[u];
102 if (!g)
103 return NULL;
104
107 if (!g->name.compare (name)) 105 if (!g->name.compare (name))
108 return g; 106 return g;
107 }
109 108
110 return NULL; 109 return NULL;
111 }*/ 110 }
112 111
113 unsigned int CountGlobalVars () { 112 unsigned int CountGlobalVars () {
114 ScriptVar* var;
115 unsigned int count = 0; 113 unsigned int count = 0;
116 unsigned int u = 0; 114 unsigned int u = 0;
117 ITERATE_GLOBAL_VARS (u) { 115 ITERATE_GLOBAL_VARS (u) {
118 if (g_GlobalVariables[u] != NULL) 116 if (g_GlobalVariables[u] != NULL)
119 count++; 117 count++;

mercurial