diff options
author | David Walter Seikel | 2012-01-21 10:46:28 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-21 10:46:28 +1000 |
commit | b96977724164fc9f973b4d30b697b4ed228fa882 (patch) | |
tree | acc5866b1f99c0aae0d41d94143689ca2e10bf4a /LuaSL/src/LuaSL_compile.c | |
parent | Vectors and rotations are broken, but I'll deal with those next. Just commen... (diff) | |
download | SledjHamr-b96977724164fc9f973b4d30b697b4ed228fa882.zip SledjHamr-b96977724164fc9f973b4d30b697b4ed228fa882.tar.gz SledjHamr-b96977724164fc9f973b4d30b697b4ed228fa882.tar.bz2 SledjHamr-b96977724164fc9f973b4d30b697b4ed228fa882.tar.xz |
Add LSL constants by simply compiling an LSL script with them all, and keeping the result.
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index fd5bbb2..29c45f3 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -200,6 +200,7 @@ opType opExpr[][10] = | |||
200 | 200 | ||
201 | 201 | ||
202 | LSL_Token **tokens = NULL; | 202 | LSL_Token **tokens = NULL; |
203 | LSL_Script constants; | ||
203 | int lowestToken = 999999; | 204 | int lowestToken = 999999; |
204 | 205 | ||
205 | 206 | ||
@@ -263,6 +264,8 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) | |||
263 | } | 264 | } |
264 | 265 | ||
265 | if (NULL == var) | 266 | if (NULL == var) |
267 | var = eina_hash_find(constants.variables, name); | ||
268 | if (NULL == var) | ||
266 | var = eina_hash_find(compiler->script.variables, name); | 269 | var = eina_hash_find(compiler->script.variables, name); |
267 | } | 270 | } |
268 | 271 | ||
@@ -1092,6 +1095,8 @@ Eina_Bool compilerSetup(gameGlobals *game) | |||
1092 | tokens = calloc(i + 1, sizeof(LSL_Token *)); | 1095 | tokens = calloc(i + 1, sizeof(LSL_Token *)); |
1093 | if (tokens) | 1096 | if (tokens) |
1094 | { | 1097 | { |
1098 | char buf[PATH_MAX]; | ||
1099 | |||
1095 | // Sort the token table. | 1100 | // Sort the token table. |
1096 | for (i = 0; LSL_Tokens[i].token != NULL; i++) | 1101 | for (i = 0; LSL_Tokens[i].token != NULL; i++) |
1097 | { | 1102 | { |
@@ -1099,6 +1104,11 @@ Eina_Bool compilerSetup(gameGlobals *game) | |||
1099 | 1104 | ||
1100 | tokens[j] = &(LSL_Tokens[i]); | 1105 | tokens[j] = &(LSL_Tokens[i]); |
1101 | } | 1106 | } |
1107 | |||
1108 | // Compile the constants. | ||
1109 | snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); | ||
1110 | compileLSL(game, buf, TRUE); | ||
1111 | |||
1102 | return EINA_TRUE; | 1112 | return EINA_TRUE; |
1103 | } | 1113 | } |
1104 | else | 1114 | else |
@@ -1107,7 +1117,7 @@ Eina_Bool compilerSetup(gameGlobals *game) | |||
1107 | return EINA_FALSE; | 1117 | return EINA_FALSE; |
1108 | } | 1118 | } |
1109 | 1119 | ||
1110 | Eina_Bool compileLSL(gameGlobals *game, char *script) | 1120 | Eina_Bool compileLSL(gameGlobals *game, char *script, boolean doConstants) |
1111 | { | 1121 | { |
1112 | Eina_Bool result = EINA_FALSE; | 1122 | Eina_Bool result = EINA_FALSE; |
1113 | LuaSL_compiler compiler; | 1123 | LuaSL_compiler compiler; |
@@ -1160,7 +1170,14 @@ Eina_Bool compileLSL(gameGlobals *game, char *script) | |||
1160 | yylex_destroy(compiler.scanner); | 1170 | yylex_destroy(compiler.scanner); |
1161 | Parse (pParser, 0, compiler.lval, &compiler); | 1171 | Parse (pParser, 0, compiler.lval, &compiler); |
1162 | ParseFree(pParser, free); | 1172 | ParseFree(pParser, free); |
1163 | doneParsing(&compiler); | 1173 | |
1174 | if (doConstants) | ||
1175 | { | ||
1176 | memcpy(&constants, &(compiler.script), sizeof(LSL_Script)); | ||
1177 | } | ||
1178 | else | ||
1179 | { | ||
1180 | doneParsing(&compiler); | ||
1164 | 1181 | ||
1165 | // Take the result of the parse, and convert it into Lua source. | 1182 | // Take the result of the parse, and convert it into Lua source. |
1166 | // Each LSL script becomes a Lua state. | 1183 | // Each LSL script becomes a Lua state. |
@@ -1169,12 +1186,16 @@ Eina_Bool compileLSL(gameGlobals *game, char *script) | |||
1169 | 1186 | ||
1170 | // Compile the Lua source by the Lua compiler. | 1187 | // Compile the Lua source by the Lua compiler. |
1171 | 1188 | ||
1189 | } | ||
1190 | |||
1172 | if (NULL != compiler.file) | 1191 | if (NULL != compiler.file) |
1173 | { | 1192 | { |
1174 | fclose(compiler.file); | 1193 | fclose(compiler.file); |
1175 | compiler.file = NULL; | 1194 | compiler.file = NULL; |
1176 | } | 1195 | } |
1177 | burnLeaf(compiler.ast); | 1196 | |
1197 | if (!doConstants) | ||
1198 | burnLeaf(compiler.ast); | ||
1178 | 1199 | ||
1179 | return result; | 1200 | return result; |
1180 | } | 1201 | } |