aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/LuaSL
diff options
context:
space:
mode:
Diffstat (limited to 'src/LuaSL')
-rw-r--r--src/LuaSL/LuaSL_LSL_tree.h2
-rw-r--r--src/LuaSL/LuaSL_compile.c63
2 files changed, 64 insertions, 1 deletions
diff --git a/src/LuaSL/LuaSL_LSL_tree.h b/src/LuaSL/LuaSL_LSL_tree.h
index dd15bed..26d63b1 100644
--- a/src/LuaSL/LuaSL_LSL_tree.h
+++ b/src/LuaSL/LuaSL_LSL_tree.h
@@ -389,6 +389,8 @@ typedef struct
389 int column, line; 389 int column, line;
390 int undeclared; 390 int undeclared;
391 boolean inState; 391 boolean inState;
392 boolean isLSL;
393 boolean isLua;
392} LuaSL_compiler; 394} LuaSL_compiler;
393 395
394 396
diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c
index ecc61bd..dab974c 100644
--- a/src/LuaSL/LuaSL_compile.c
+++ b/src/LuaSL/LuaSL_compile.c
@@ -2241,6 +2241,7 @@ boolean compilerSetup(gameGlobals *ourGlobals)
2241void compileLSL(LuaCompiler *compiler) 2241void compileLSL(LuaCompiler *compiler)
2242{ 2242{
2243 LuaSL_compiler *lcompiler = calloc(1, sizeof(LuaSL_compiler)); 2243 LuaSL_compiler *lcompiler = calloc(1, sizeof(LuaSL_compiler));
2244 char first[32];
2244 void *pParser = ParseAlloc(malloc); 2245 void *pParser = ParseAlloc(malloc);
2245#if LUASL_BAD_CHECK 2246#if LUASL_BAD_CHECK
2246 char tempName[PATH_MAX]; 2247 char tempName[PATH_MAX];
@@ -2261,20 +2262,80 @@ void compileLSL(LuaCompiler *compiler)
2261 lcompiler->ignorable = eina_strbuf_new(); 2262 lcompiler->ignorable = eina_strbuf_new();
2262#endif 2263#endif
2263 2264
2264 PI("Compiling %s.", lcompiler->compiler->file); 2265// PD("Compiling %s.", lcompiler->compiler->file);
2265 2266
2266 in = fopen(lcompiler->compiler->file, "r"); 2267 in = fopen(lcompiler->compiler->file, "r");
2267 if (NULL == in) 2268 if (NULL == in)
2268 { 2269 {
2269 PE("Error opening file %s.", lcompiler->compiler->file); 2270 PE("Error opening file %s.", lcompiler->compiler->file);
2271 free(lcompiler);
2270 return; 2272 return;
2271 } 2273 }
2274
2275 // Check for first line magic.
2276 if (fread(first, 1, 32, in))
2277 {
2278 first[31] = 0;
2279 if ((0 == strncasecmp(first, "//DotNetEngine:", 15)) || (0 == strncasecmp(first, "//XEngine:", 10)))
2280 {
2281#if COMPILE_OUTPUT
2282 PE("Illegal script engine requested in %s.", lcompiler->compiler->file);
2283#endif
2284 fclose(in);
2285 in = NULL;
2286 free(lcompiler);
2287 return;
2288 }
2289 else if ((0 == strncasecmp(first, "//LuaSL:", 8)) || (0 == strncasecmp(first, "--LuaSL:", 8)))
2290 {
2291 char *p = &first[8];
2292 lcompiler->isLSL = TRUE;
2293 lcompiler->isLua = TRUE;
2294 if (0 == strncasecmp(first, "LSL", 3))
2295 {
2296 p+= 3;
2297 lcompiler->isLua = FALSE;
2298 }
2299 else if (0 == strncasecmp(first, "Lua", 3))
2300 {
2301 p+= 3;
2302 lcompiler->isLSL = FALSE;
2303 }
2304 else if (0 == strncasecmp(first, "LuaSL", 5))
2305 {
2306 p+= 5;
2307 }
2308 if ((' ' != *p) && ('\t' != *p) && ('\n' != *p) && ('\r' != *p))
2309 {
2310#if COMPILE_OUTPUT
2311 PE("Unsupported script language requested in %s.", lcompiler->compiler->file);
2312#endif
2313 fclose(in);
2314 in = NULL;
2315 free(lcompiler);
2316 return;
2317 }
2318 }
2319 else if (isdigit(first[0]))
2320 {
2321#if COMPILE_OUTPUT
2322 PW("LuaSL script %s starts with a number, a common method of disabling scripts.", lcompiler->compiler->file);
2323#endif
2324 fclose(in);
2325 in = NULL;
2326 free(lcompiler);
2327 return;
2328 }
2329 }
2330 rewind(in);
2331
2272#if LUASL_BAD_CHECK 2332#if LUASL_BAD_CHECK
2273 // Mark the file as bad, in case we crash while compiling it. 2333 // Mark the file as bad, in case we crash while compiling it.
2274 // NOTE - wont work so well when we are threaded. 2334 // NOTE - wont work so well when we are threaded.
2275 sprintf(tempName, "%s.BAD", lcompiler->compiler->file); 2335 sprintf(tempName, "%s.BAD", lcompiler->compiler->file);
2276 ecore_file_mv(lcompiler->compiler->file, tempName); 2336 ecore_file_mv(lcompiler->compiler->file, tempName);
2277#endif 2337#endif
2338
2278 lcompiler->ast = NULL; 2339 lcompiler->ast = NULL;
2279 lcompiler->lval = newLeaf(LSL_UNKNOWN, NULL, NULL); 2340 lcompiler->lval = newLeaf(LSL_UNKNOWN, NULL, NULL);
2280 // Text editors usually start counting at 1, even programmers editors. mcedit is an exception, but you can deal with that yourself. 2341 // Text editors usually start counting at 1, even programmers editors. mcedit is an exception, but you can deal with that yourself.