aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_compile.c')
-rw-r--r--LuaSL/src/LuaSL_compile.c27
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
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}