aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-21 10:46:28 +1000
committerDavid Walter Seikel2012-01-21 10:46:28 +1000
commitb96977724164fc9f973b4d30b697b4ed228fa882 (patch)
treeacc5866b1f99c0aae0d41d94143689ca2e10bf4a
parentVectors and rotations are broken, but I'll deal with those next. Just commen... (diff)
downloadSledjHamr-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.h2
-rw-r--r--LuaSL/src/LuaSL_compile.c27
-rw-r--r--LuaSL/src/LuaSL_main.c4
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
59Eina_Bool compilerSetup(gameGlobals *game); 59Eina_Bool compilerSetup(gameGlobals *game);
60Eina_Bool compileLSL(gameGlobals *game, char *script); 60Eina_Bool compileLSL(gameGlobals *game, char *script, boolean doConstants);
61 61
62void loggingStartup(gameGlobals *game); 62void loggingStartup(gameGlobals *game);
63char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); 63char *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
202LSL_Token **tokens = NULL; 202LSL_Token **tokens = NULL;
203LSL_Script constants;
203int lowestToken = 999999; 204int 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
1110Eina_Bool compileLSL(gameGlobals *game, char *script) 1120Eina_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