hedgewars/uScript.pas
changeset 13726 61095cb5f58a
parent 13679 3f6fae745f84
child 13729 a62408ee8281
--- 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'));