Skip to content

Commit

Permalink
LuaFAR (generic plugin):
Browse files Browse the repository at this point in the history
Размер структур PluginStartupInfo и FarStandardFunctions определяется теперь не при компиляции, а динамически, по значениям полей StructSize в аргументе, полученном от Far в SetStartupInfoW(). Это позволит LuaFAR-плагинам автоматически поддерживать добавляемые функции Plugins API без необходимости перекомпиляции плагина.
  • Loading branch information
shmuz committed Feb 8, 2015
1 parent 05838bc commit 7b6fcbc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 481 },
Version = { 1, 0, 0, 482 },
MinFarVersion = { 3, 0, 0, 4252 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
10 changes: 9 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,12 @@
shmuel 06.02.2015 17:07:16 +0200 - build 481
shmuel 08.02.2015 17:47:16 +0200 - build 482

1. LuaFAR (generic plugin):
Размер структур PluginStartupInfo и FarStandardFunctions определяется теперь не при компиляции,
а динамически, по значениям полей StructSize в аргументе, полученном от Far в SetStartupInfoW().
Это позволит LuaFAR-плагинам автоматически поддерживать добавляемые функции Plugins API без
необходимости перекомпиляции плагина.

shmuel 06.02.2015 17:07:16 +0200 - build 481

1. Уточнение build 476: после вызова Plugin.Call и завершения макроса не производилась перерисовка редактора.

Expand Down
55 changes: 30 additions & 25 deletions plugins/luamacro/luafar/luaplug.c
Expand Up @@ -25,19 +25,17 @@ extern int FUNC_OPENLIBS(lua_State*);

typedef struct
{
lua_State* LS;
struct PluginStartupInfo Info;
struct FarStandardFunctions FSF;
lua_State *LS;
struct PluginStartupInfo *StartupInfo;
GUID PluginId;
TPluginData PluginData;
wchar_t PluginDir[512];
int Init1_Done; // Ensure initializations are done only once
int Init2_Done; // *
int InitStage;
int Depth;
CRITICAL_SECTION FindFileSection; // http://forum.farmanager.com/viewtopic.php?f=9&p=107075#p107075
} Global;

#define IsPluginReady(g) (g.LS && g.Init2_Done)
#define IsPluginReady(g) (g.LS && g.InitStage==2)

static Global G;

Expand Down Expand Up @@ -65,10 +63,9 @@ static void InitGlobal (Global *g, HINSTANCE hDll)
{
size_t PluginDirSize = sizeof(g->PluginDir) / sizeof(g->PluginDir[0]);
size_t RetSize = GetModuleFileNameW(hDll, g->PluginDir, (DWORD)PluginDirSize);
TPluginData PD = { &g->Info,&g->FSF,&g->PluginId,DlgProc,0,NULL,NULL,NULL,laction,SIG_DFL };
TPluginData PD = { NULL,NULL,&g->PluginId,DlgProc,0,NULL,NULL,NULL,laction,SIG_DFL };
g->PluginData = PD;
g->Init1_Done = 0;
g->Init2_Done = 0;
g->InitStage = 0;
g->Depth = 0;
g->LS = NULL;
if (RetSize && RetSize < PluginDirSize)
Expand All @@ -81,11 +78,10 @@ static void InitGlobal (Global *g, HINSTANCE hDll)

static void DestroyGlobal (Global *g)
{
if (g->LS)
{
lua_close(g->LS);
g->LS = NULL;
}
if (g->StartupInfo) free(g->StartupInfo);

if (g->LS) lua_close(g->LS);

DeleteCriticalSection(&g->FindFileSection);
}

Expand Down Expand Up @@ -128,17 +124,17 @@ __declspec(dllexport) lua_State* GetLuaState()
/* for other C-files of the plugin */
struct PluginStartupInfo *GetPluginStartupInfo()
{
return &G.Info;
return G.StartupInfo;
}

void LUAPLUG GetGlobalInfoW(struct GlobalInfo *globalInfo)
{
if (G.LS)
{
if (!G.Init1_Done)
if (G.InitStage == 0)
{
LF_InitLuaState1(G.LS, FUNC_OPENLIBS);
G.Init1_Done = 1;
G.InitStage++;
}

if (LF_GetGlobalInfo(G.LS, globalInfo, G.PluginDir))
Expand All @@ -154,17 +150,26 @@ void LUAPLUG GetGlobalInfoW(struct GlobalInfo *globalInfo)

void LUAPLUG SetStartupInfoW(const struct PluginStartupInfo *aInfo)
{
if (G.LS && !G.Init2_Done)
if (G.LS && G.InitStage==1)
{
G.Info = *aInfo;
G.FSF = *aInfo->FSF;
G.Info.FSF = &G.FSF;
InitLuaState2(G.LS, &G.PluginData);
G.StartupInfo = (struct PluginStartupInfo *) malloc(aInfo->StructSize + aInfo->FSF->StructSize);
if (G.StartupInfo)
{
memcpy(G.StartupInfo, aInfo, aInfo->StructSize);
memcpy(G.StartupInfo+1, aInfo->FSF, aInfo->FSF->StructSize);
G.StartupInfo->FSF = (struct FarStandardFunctions *) (G.StartupInfo+1);
G.PluginData.Info = G.StartupInfo;
G.PluginData.FSF = G.StartupInfo->FSF;

InitLuaState2(G.LS, &G.PluginData);
if (LF_RunDefaultScript(G.LS))
G.InitStage++;
}

if (LF_RunDefaultScript(G.LS))
G.Init2_Done = 1;
else
if (G.InitStage != 2)
{
if (G.StartupInfo) { free(G.StartupInfo); G.StartupInfo=NULL; }

lua_close(G.LS);
G.LS = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 481
#define PLUGIN_BUILD 482
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down

0 comments on commit 7b6fcbc

Please sign in to comment.