ADD: Lua - add to package.path current content plugin path

This commit is contained in:
Alexander Koblov 2017-10-01 09:24:52 +00:00
commit 01fa62cf11
2 changed files with 17 additions and 0 deletions

View file

@ -30,6 +30,7 @@ uses
Classes, SysUtils, lua;
procedure RegisterPackages(L : Plua_State);
procedure SetPackagePath(L: Plua_State; const Path: String);
function LuaPCall(L : Plua_State; nargs, nresults : Integer): Boolean;
function ExecuteScript(const FileName: String; Args: array of String): Boolean;
@ -463,6 +464,20 @@ begin
ReplaceLib(L);
end;
procedure SetPackagePath(L: Plua_State; const Path: String);
var
APath: String;
begin
lua_getglobal(L, 'package');
lua_getfield(L, -1, 'path');
APath := lua_tostring(L, -1);
APath := APath + ';' + Path + '?.lua';
lua_pop(L, 1);
lua_pushstring(L, PAnsiChar(APath));
lua_setfield(L, -2, 'path');
lua_pop(L, 1);
end;
function LuaPCall(L: Plua_State; nargs, nresults: Integer): Boolean;
var
Status: Integer;

View file

@ -897,6 +897,8 @@ begin
RegisterPackages(L);
SetPackagePath(L, ExtractFilePath(FFileName));
if DoScript(Self.FFileName) = 0 then
Result := True
else