2993 end; |
2993 end; |
2994 |
2994 |
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; |
|
2999 var lastChar: char; |
|
3000 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ |
|
3001 function ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl; |
|
3002 var mybuf: PChar; |
|
3003 i: LongInt; |
|
3004 begin |
|
3005 mybuf := physfsReader(L, f, sz); |
|
3006 if (mybuf <> nil) and (sz^ > 0) then |
|
3007 begin |
|
3008 for i:= 0 to sz^-1 do |
|
3009 begin |
|
3010 if (lastChar = '-') and (mybuf[i] = '-') then |
|
3011 inComment := true |
|
3012 // gonna add any non-magic whitespace and skip - just to make comment avoidance easier |
|
3013 else if not inComment and (byte(mybuf[i]) > $20) and (byte(mybuf[i]) < $7F) and (mybuf[i]<>'-') then |
|
3014 AddRandomness(byte(mybuf[i])); |
|
3015 lastChar := mybuf[i]; |
|
3016 if inComment and ((byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A)) then |
|
3017 inComment := false |
|
3018 end; |
|
3019 end; |
|
3020 ScriptReader:= mybuf |
|
3021 end; |
|
3022 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ |
|
3023 |
2998 procedure ScriptLoad(name : shortstring); |
3024 procedure ScriptLoad(name : shortstring); |
2999 var ret : LongInt; |
3025 var ret : LongInt; |
3000 s : shortstring; |
3026 s : shortstring; |
3001 f : PFSFile; |
3027 f : PFSFile; |
3002 buf : array[0..Pred(BUFSIZE)] of byte; |
3028 buf : array[0..Pred(BUFSIZE)] of byte; |
3003 begin |
3029 begin |
|
3030 inComment:= false; |
|
3031 lastChar:= 'X'; |
3004 s:= cPathz[ptData] + name; |
3032 s:= cPathz[ptData] + name; |
3005 if not pfsExists(s) then |
3033 if not pfsExists(s) then |
3006 begin |
3034 begin |
3007 AddFileLog('[LUA] Script not found: ' + name); |
3035 AddFileLog('[LUA] Script not found: ' + name); |
3008 exit; |
3036 exit; |
3013 exit; |
3041 exit; |
3014 |
3042 |
3015 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp')); |
3043 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp')); |
3016 |
3044 |
3017 physfsReaderSetBuffer(@buf); |
3045 physfsReaderSetBuffer(@buf); |
3018 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s)); |
3046 ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s)); |
3019 pfsClose(f); |
3047 pfsClose(f); |
3020 |
3048 |
3021 if ret <> 0 then |
3049 if ret <> 0 then |
3022 begin |
3050 begin |
3023 LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
3051 LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |