| 43 list<script_variable> g_LocalVariables; |
43 list<script_variable> g_LocalVariables; |
| 44 |
44 |
| 45 // ============================================================================ |
45 // ============================================================================ |
| 46 // Tries to declare a new global-scope variable. Returns pointer |
46 // Tries to declare a new global-scope variable. Returns pointer |
| 47 // to new global variable, null if declaration failed. |
47 // to new global variable, null if declaration failed. |
| 48 script_variable* DeclareGlobalVariable (botscript_parser* r, type_e type, string name) |
48 script_variable* declare_global_variable (type_e type, string name) |
| 49 { |
49 { |
| 50 // Unfortunately the VM does not support string variables so yeah. |
50 // Unfortunately the VM does not support string variables so yeah. |
| 51 if (type == TYPE_STRING) |
51 if (type == TYPE_STRING) |
| 52 error ("variables cannot be string\n"); |
52 error ("variables cannot be string\n"); |
| 53 |
53 |
| 56 error ("name of variable-to-be `%s` conflicts with that of a command", name.chars()); |
56 error ("name of variable-to-be `%s` conflicts with that of a command", name.chars()); |
| 57 |
57 |
| 58 if (IsKeyword (name)) |
58 if (IsKeyword (name)) |
| 59 error ("name of variable-to-be `%s` is a keyword", name.chars()); |
59 error ("name of variable-to-be `%s` is a keyword", name.chars()); |
| 60 |
60 |
| 61 if (g_GlobalVariables.size() >= MAX_SCRIPT_VARIABLES) |
61 if (g_GlobalVariables.size() >= g_max_global_vars) |
| 62 error ("too many global variables!"); |
62 error ("too many global variables!"); |
| 63 |
63 |
| 64 for (int i = 0; i < g_GlobalVariables.size(); i++) |
64 for (int i = 0; i < g_GlobalVariables.size(); i++) |
| 65 if (g_GlobalVariables[i].name == name) |
65 if (g_GlobalVariables[i].name == name) |
| 66 error ("attempted redeclaration of global variable `%s`", name.chars()); |
66 error ("attempted redeclaration of global variable `%s`", name.chars()); |
| 76 return &g_GlobalVariables[g.index]; |
76 return &g_GlobalVariables[g.index]; |
| 77 } |
77 } |
| 78 |
78 |
| 79 // ============================================================================ |
79 // ============================================================================ |
| 80 // Find a global variable by name |
80 // Find a global variable by name |
| 81 script_variable* FindGlobalVariable (string name) |
81 script_variable* find_global_variable (string name) |
| 82 { |
82 { |
| 83 for (int i = 0; i < g_GlobalVariables.size(); i++) |
83 for (int i = 0; i < g_GlobalVariables.size(); i++) |
| 84 { |
84 { |
| 85 script_variable* g = &g_GlobalVariables[i]; |
85 script_variable* g = &g_GlobalVariables[i]; |
| 86 |
86 |