mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Lua-wdx crash if script contains errors
This commit is contained in:
parent
f586accf5d
commit
5f321ee45a
2 changed files with 23 additions and 10 deletions
|
|
@ -30,13 +30,14 @@ uses
|
|||
Classes, SysUtils, lua;
|
||||
|
||||
procedure RegisterPackages(L : Plua_State);
|
||||
function LuaPCall(L : Plua_State; nargs, nresults : Integer): Boolean;
|
||||
function ExecuteScript(const FileName: String; Args: array of String): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Forms, Dialogs, LazUTF8, DCOSUtils, DCConvertEncoding, fMain, uFormCommands,
|
||||
uOSUtils, uGlobs;
|
||||
uOSUtils, uGlobs, uLog;
|
||||
|
||||
procedure luaPushSearchRec(L : Plua_State; var Rec: TSearchRec);
|
||||
var
|
||||
|
|
@ -186,6 +187,18 @@ begin
|
|||
lua_pop(L, 1);
|
||||
end;
|
||||
|
||||
function LuaPCall(L: Plua_State; nargs, nresults: Integer): Boolean;
|
||||
var
|
||||
Status: Integer;
|
||||
begin
|
||||
Status:= lua_pcall(L, nargs, nresults, 0);
|
||||
// Check execution result
|
||||
if Status <> 0 then begin
|
||||
logWrite(lua_tostring(L, -1), lmtError, True, False);
|
||||
end;
|
||||
Result:= (Status = 0);
|
||||
end;
|
||||
|
||||
function ExecuteScript(const FileName: String; Args: array of String): Boolean;
|
||||
var
|
||||
L: Plua_State;
|
||||
|
|
|
|||
|
|
@ -1053,7 +1053,7 @@ begin
|
|||
if not lua_isfunction(L, -1) then
|
||||
exit;
|
||||
lua_pushinteger(L, Index);
|
||||
lua_call(L, 1, 3);
|
||||
LuaPCall(L, 1, 3);
|
||||
xFieldName := lua_tostring(L, -3);
|
||||
xUnits := lua_tostring(L, -2);
|
||||
Result := Integer(lua_tointeger(L, -1));
|
||||
|
|
@ -1067,7 +1067,7 @@ begin
|
|||
lua_getglobal(L, 'ContentPluginUnloading');
|
||||
if not lua_isfunction(L, -1) then
|
||||
exit;
|
||||
lua_call(L, 0, 0);
|
||||
LuaPCall(L, 0, 0);
|
||||
end;
|
||||
|
||||
procedure TLuaWdx.CallContentGetSupportedField;
|
||||
|
|
@ -1101,7 +1101,7 @@ begin
|
|||
lua_pushstring(L, PChar(gpCfgDir + WdxIniFileName));
|
||||
lua_pushinteger(L, 1);
|
||||
lua_pushinteger(L, 50);
|
||||
lua_call(L, 3, 0);
|
||||
LuaPCall(L, 3, 0);
|
||||
end;
|
||||
|
||||
procedure TLuaWdx.CallContentStopGetValue(FileName: String);
|
||||
|
|
@ -1112,7 +1112,7 @@ begin
|
|||
if not lua_isfunction(L, -1) then
|
||||
exit;
|
||||
lua_pushstring(L, PChar(FileName));
|
||||
lua_call(L, 1, 0);
|
||||
LuaPCall(L, 1, 0);
|
||||
end;
|
||||
|
||||
function TLuaWdx.CallContentGetDefaultSortOrder(FieldIndex: Integer): Boolean;
|
||||
|
|
@ -1127,7 +1127,7 @@ begin
|
|||
if not lua_isfunction(L, -1) then
|
||||
exit;
|
||||
lua_pushinteger(L, FieldIndex);
|
||||
lua_call(L, 1, 1);
|
||||
LuaPCall(L, 1, 1);
|
||||
|
||||
x := lua_tointeger(L, -1);
|
||||
case x of
|
||||
|
|
@ -1146,7 +1146,7 @@ begin
|
|||
lua_getglobal(L, 'ContentGetDetectString');
|
||||
if not lua_isfunction(L, -1) then
|
||||
exit;
|
||||
lua_call(L, 0, 1);
|
||||
LuaPCall(L, 0, 1);
|
||||
Result := lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
end;
|
||||
|
|
@ -1184,7 +1184,7 @@ begin
|
|||
lua_pushinteger(L, UnitIndex);
|
||||
lua_pushinteger(L, flags);
|
||||
|
||||
lua_call(L, 4, 1);
|
||||
LuaPCall(L, 4, 1);
|
||||
|
||||
if not lua_isnil(L, -1) then
|
||||
begin
|
||||
|
|
@ -1239,7 +1239,7 @@ begin
|
|||
lua_pushinteger(L, UnitIndex);
|
||||
lua_pushinteger(L, flags);
|
||||
|
||||
lua_call(L, 4, 1);
|
||||
LuaPCall(L, 4, 1);
|
||||
|
||||
if not lua_isnil(L, -1) then
|
||||
begin
|
||||
|
|
@ -1274,7 +1274,7 @@ begin
|
|||
exit;
|
||||
lua_pushinteger(L, FieldIndex);
|
||||
|
||||
lua_call(L, 1, 1);
|
||||
LuaPCall(L, 1, 1);
|
||||
Result := lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue