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 | |
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.
-rw-r--r-- | LuaSL/src/LuaSL.h | 2 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 27 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 4 |
3 files changed, 27 insertions, 6 deletions
diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 852847d..59a3fbd 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h | |||
@@ -57,7 +57,7 @@ typedef struct | |||
57 | 57 | ||
58 | 58 | ||
59 | Eina_Bool compilerSetup(gameGlobals *game); | 59 | Eina_Bool compilerSetup(gameGlobals *game); |
60 | Eina_Bool compileLSL(gameGlobals *game, char *script); | 60 | Eina_Bool compileLSL(gameGlobals *game, char *script, boolean doConstants); |
61 | 61 | ||
62 | void loggingStartup(gameGlobals *game); | 62 | void loggingStartup(gameGlobals *game); |
63 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); | 63 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); |
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 | } |
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 3891cb4..e0d2629 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -164,12 +164,12 @@ main(int argc, char **argv) | |||
164 | compilerSetup(&game); | 164 | compilerSetup(&game); |
165 | // snprintf(buf, sizeof(buf), "%s/Test sim/objects/onefang's test bed/~run", PACKAGE_DATA_DIR); | 165 | // snprintf(buf, sizeof(buf), "%s/Test sim/objects/onefang's test bed/~run", PACKAGE_DATA_DIR); |
166 | snprintf(buf, sizeof(buf), "%s/test2.lsl", PACKAGE_DATA_DIR); | 166 | snprintf(buf, sizeof(buf), "%s/test2.lsl", PACKAGE_DATA_DIR); |
167 | if (compileLSL(&game, buf)) | 167 | if (compileLSL(&game, buf, FALSE)) |
168 | PIm("Against all odds, the compile of %s worked! lol", buf); | 168 | PIm("Against all odds, the compile of %s worked! lol", buf); |
169 | else | 169 | else |
170 | PEm("The compile of %s failed!", buf); | 170 | PEm("The compile of %s failed!", buf); |
171 | snprintf(buf, sizeof(buf), "%s/test.lsl", PACKAGE_DATA_DIR); | 171 | snprintf(buf, sizeof(buf), "%s/test.lsl", PACKAGE_DATA_DIR); |
172 | compileLSL(&game, buf); | 172 | compileLSL(&game, buf, FALSE); |
173 | 173 | ||
174 | // ecore_main_loop_begin(); | 174 | // ecore_main_loop_begin(); |
175 | 175 | ||