Critical error if loading a script has failed
authorWuzzy <Wuzzy2@mail.ru>
Fri, 31 Aug 2018 18:15:45 +0200
changeset 13721 61095cb5f58a
parent 13720 8e3d2f7d8737
child 13722 6cdb12449be7
Critical error if loading a script has failed
hedgewars/uCommandHandlers.pas
hedgewars/uScript.pas
--- a/hedgewars/uCommandHandlers.pas	Fri Aug 31 16:51:33 2018 +0200
+++ b/hedgewars/uCommandHandlers.pas	Fri Aug 31 18:15:45 2018 +0200
@@ -113,7 +113,7 @@
 if s[byte(s[0])]='"' then
     Delete(s, byte(s[0]), 1);
 cScriptName:= s;
-ScriptLoad(s)
+ScriptLoad(s, true)
 end;
 
 procedure chScriptParam(var s: shortstring);
@@ -536,7 +536,7 @@
     InitStepsFlags:= InitStepsFlags or cifMap
     end;
 cMapName:= s;
-ScriptLoad('Maps/' + s + '/map.lua')
+ScriptLoad('Maps/' + s + '/map.lua', false)
 end;
 
 procedure chSetTheme(var s: shortstring);
--- a/hedgewars/uScript.pas	Fri Aug 31 16:51:33 2018 +0200
+++ b/hedgewars/uScript.pas	Fri Aug 31 18:15:45 2018 +0200
@@ -34,7 +34,7 @@
 procedure ScriptPrintStack;
 procedure ScriptClearStack;
 
-procedure ScriptLoad(name : shortstring);
+procedure ScriptLoad(name : shortstring; mustExist : boolean);
 procedure ScriptOnPreviewInit;
 procedure ScriptOnGameInit;
 procedure ScriptOnScreenResize;
@@ -3068,7 +3068,7 @@
 function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl;
 begin
     if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then
-        ScriptLoad(lua_tostring(L, 1))
+        ScriptLoad(lua_tostring(L, 1), true)
     else
         lua_pushnil(L);
     lc_hedgewarsscriptload:= 0;
@@ -3560,7 +3560,7 @@
 end;
 // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧
 
-procedure ScriptLoad(name : shortstring);
+procedure ScriptLoad(name : shortstring; mustExist : boolean);
 var ret : LongInt;
       s : shortstring;
       f : PFSFile;
@@ -3575,13 +3575,16 @@
 s:= cPathz[ptData] + name;
 if not pfsExists(s) then
     begin
-    AddFileLog('[LUA] Script not found: ' + name);
+    if mustExist then
+        OutError('Script not found: ' + name, true)
+    else
+        AddFileLog('[LUA] Script not found: ' + name);
     exit;
     end;
 
 f:= pfsOpenRead(s);
 if f = nil then
-    exit;
+    OutError('Error reading script: ' + name, true);
 
 hedgewarsMountPackage(Str2PChar(copy(s, 3, length(s)-6)+'.hwp'));