hedgewars/uScript.pas
changeset 12464 06bf46238a89
parent 12463 3af8d755de17
child 12498 f3d6f1b0b59d
equal deleted inserted replaced
12463:3af8d755de17 12464:06bf46238a89
  2995 // custom script loader via physfs, passed to lua_load
  2995 // custom script loader via physfs, passed to lua_load
  2996 const BUFSIZE = 1024;
  2996 const BUFSIZE = 1024;
  2997 
  2997 
  2998 var inComment: boolean;
  2998 var inComment: boolean;
  2999 var inQuote: boolean;
  2999 var inQuote: boolean;
       
  3000 var locSum: LongWord;
  3000 var braceCount: LongWord;
  3001 var braceCount: LongWord;
  3001 var wordCount: LongWord;
  3002 var wordCount: LongWord;
  3002 var lastChar: char;
  3003 var lastChar: char;
  3003 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
  3004 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
  3004 function  ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
  3005 function  ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl;
  3033                 begin
  3034                 begin
  3034                     if not inComment and (mybuf[i] = '"') and (lastChar <> '\') then
  3035                     if not inComment and (mybuf[i] = '"') and (lastChar <> '\') then
  3035                         inQuote := not inQuote;
  3036                         inQuote := not inQuote;
  3036                     if (lastChar = '-') and (mybuf[i] = '-') then
  3037                     if (lastChar = '-') and (mybuf[i] = '-') then
  3037                         inComment := true;
  3038                         inComment := true;
       
  3039                     if not inComment and not inQuote then
       
  3040                        locSum := locSum xor (byte(mybuf[i]) shl (i mod 4));
  3038                     if not inComment and not inQuote and 
  3041                     if not inComment and not inQuote and 
  3039                         ((mybuf[i] = '(') or 
  3042                         ((mybuf[i] = '(') or 
  3040                         (mybuf[i] = ')') or 
  3043                         (mybuf[i] = ')') or 
  3041                         (mybuf[i] = '+') or 
  3044                         (mybuf[i] = '+') or 
  3042                         (mybuf[i] = '#') or 
  3045                         (mybuf[i] = '#') or 
  3043                         (braceCount > 2) or
  3046                         (braceCount > 2) or
  3044                         (wordCount > 6)) then 
  3047                         (wordCount > 6)) then 
  3045                        CheckSum := $deadbeef;
  3048                        CheckSum := locSum;
  3046                     if not inComment and not inQuote and ((mybuf[i] = '{') or (mybuf[i] = '}')) then
  3049                     if not inComment and not inQuote and ((mybuf[i] = '{') or (mybuf[i] = '}')) then
  3047                         inc(braceCount);
  3050                         inc(braceCount);
  3048                     if not inComment and not inQuote and 
  3051                     if not inComment and not inQuote and 
  3049                         (((byte(mybuf[i]) > $40) and (byte(mybuf[i]) < $5B)) or
  3052                         (((byte(mybuf[i]) > $40) and (byte(mybuf[i]) < $5B)) or
  3050                         ((byte(mybuf[i]) > $60) and (byte(mybuf[i]) < $6B)) or
  3053                         ((byte(mybuf[i]) > $60) and (byte(mybuf[i]) < $7B)) or
  3051                         ((byte(mybuf[i]) >= $30) and (byte(mybuf[i]) < $40))) then
  3054                         ((byte(mybuf[i]) >= $30) and (byte(mybuf[i]) < $3A))) then
  3052                         inc(wordCount);
  3055                         inc(wordCount);
  3053                     lastChar := mybuf[i];
  3056                     lastChar := mybuf[i];
  3054                     if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) then
  3057                     if (byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A) then
  3055                         inComment := false 
  3058                         inComment := false 
  3056                 end;
  3059                 end;
  3068 inComment:= false;
  3071 inComment:= false;
  3069 inQuote:= false;
  3072 inQuote:= false;
  3070 lastChar:= 'X';
  3073 lastChar:= 'X';
  3071 braceCount:= 0;
  3074 braceCount:= 0;
  3072 wordCount:= 0;
  3075 wordCount:= 0;
       
  3076 locSum:= 0;
  3073 s:= cPathz[ptData] + name;
  3077 s:= cPathz[ptData] + name;
  3074 if not pfsExists(s) then
  3078 if not pfsExists(s) then
  3075     begin
  3079     begin
  3076     AddFileLog('[LUA] Script not found: ' + name);
  3080     AddFileLog('[LUA] Script not found: ' + name);
  3077     exit;
  3081     exit;