Skip to content

Commit

Permalink
LuaFAR: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jan 11, 2025
1 parent 3b86cb5 commit c07f890
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_build/
far2m-cppcheck-build-dir/
.luacheckrc
far/libluajit.a
34 changes: 34 additions & 0 deletions far2m.cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>far2m-cppcheck-build-dir</builddir>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>true</check-unused-templates>
<max-ctu-depth>2</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<includedir>
<dir name="far/far2sdk/"/>
<dir name="far/src/"/>
<dir name="far/src/base/"/>
<dir name="far/src/mix/"/>
<dir name="far/src/bookmarks/"/>
<dir name="far/src/cfg/"/>
<dir name="far/src/console/"/>
<dir name="far/src/panels/"/>
<dir name="far/src/filemask/"/>
<dir name="far/src/hist/"/>
<dir name="far/src/locale/"/>
<dir name="far/src/macro/"/>
<dir name="far/src/plug/"/>
<dir name="far/src/vt/"/>
<dir name="WinPort/"/>
</includedir>
<paths>
<dir name="far/src"/>
<dir name="luafar/src"/>
</paths>
<exclude>
<path name="/home/shmuel/far2m/luafar/src/slnunico.c"/>
</exclude>
<project-name>far2m</project-name>
</project>
16 changes: 4 additions & 12 deletions luafar/src/exported.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ void PushPluginPair(lua_State* L, HANDLE hPlugin)
lua_pushlightuserdata(L, hPlugin);
}

void DestroyCollector(lua_State* L, HANDLE hPlugin, const char* Collector)
{
PushPluginTable(L, hPlugin); //+1: Tbl
lua_pushnil(L); //+2
lua_setfield(L, -2, Collector); //+1
lua_pop(L,1); //+0
}

// the value is on stack top (-1)
// collector table is under the index 'pos' (this index cannot be a pseudo-index)
const wchar_t* _AddStringToCollector(lua_State *L, int pos)
Expand Down Expand Up @@ -245,7 +237,7 @@ void FillPluginPanelItem (lua_State *L, struct PluginPanelItem *pi, int index)
void FillFindData(lua_State* L, struct PluginPanelItem **pPanelItems, int *pItemsNumber)
{
struct PluginPanelItem *ppi;
int i, num=0;
int num = 0;
int numLines = lua_objlen(L,-1);

ppi = (struct PluginPanelItem*) malloc(sizeof(struct PluginPanelItem) * numLines);
Expand All @@ -259,7 +251,7 @@ void FillFindData(lua_State* L, struct PluginPanelItem **pPanelItems, int *pItem
lua_pushvalue(L,-2); //+6: Tbl,FindData,UData,Coll,ppi,Coll
lua_rawset(L, -6); //+4: Tbl,FindData,UData,Coll

for (i=1; i<=numLines; i++) {
for (int i=1; i<=numLines; i++) {
lua_rawgeti(L, -3, i); //+5: Tbl,FindData,UData,Coll,FindData[i]
if (lua_istable(L,-1)) {
FillPluginPanelItem(L, ppi+num, num+1);
Expand Down Expand Up @@ -806,7 +798,7 @@ HANDLE LF_Open (lua_State* L, int OpenFrom, INT_PTR Item)
case OPEN_FROMMACRO:
{
int top;
struct OpenMacroInfo* data = (struct OpenMacroInfo*)Item;
const struct OpenMacroInfo* data = (struct OpenMacroInfo*)Item;
lua_pushinteger(L, 0); // dummy menuitem Id
PackMacroValues(L, data->Count, data->Values);
top = lua_gettop(L);
Expand Down Expand Up @@ -1488,7 +1480,7 @@ int LF_GetLinkTarget(
if (lua_type(L,-1) == LUA_TSTRING)
{
size_t size = 0;
wchar_t* ptr = utf8_to_wcstring(L,-1,&size); //+1 (conversion in place)
const wchar_t* ptr = utf8_to_wcstring(L,-1,&size); //+1 (conversion in place)
if (Target && TargetSize)
{
wcsncpy(Target, ptr, TargetSize);
Expand Down
2 changes: 2 additions & 0 deletions luafar/src/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,14 @@ const luaL_Reg regex_functions[] =
{"gsub", func_gsub},
{"match", func_match},
{"exec", func_exec},
{"tfind", func_tfind},

{"findW", func_findW},
{"gmatchW", func_gmatchW},
{"gsubW", func_gsubW},
{"matchW", func_matchW},
{"execW", func_execW},
{"tfindW", func_tfindW},
{NULL, NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion luafar/src/luamacro.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int far_MacroCallToLua(lua_State *L)
{
if (lua_type(L,1) == LUA_TLIGHTUSERDATA)
{
struct FarMacroCall* Data = (struct FarMacroCall*)lua_touserdata(L, 1);
const struct FarMacroCall* Data = (struct FarMacroCall*)lua_touserdata(L, 1);
lua_settop(L, 0);
if (Data && !FL_PushParams(L, Data))
{
Expand Down
31 changes: 1 addition & 30 deletions luafar/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2056,21 +2056,6 @@ void LF_Error(lua_State *L, const wchar_t* aMsg)
lua_pop(L, 1);
}

static int SplitToTable(lua_State *L, const wchar_t *Text, wchar_t Delim, int StartIndex)
{
int count = StartIndex;
const wchar_t *p = Text;
do {
const wchar_t *q = wcschr(p, Delim);
if (q == NULL) q = wcschr(p, L'\0');
lua_pushinteger(L, ++count);
lua_pushlstring(L, (const char*)p, (q-p)*sizeof(wchar_t));
lua_rawset(L, -3);
p = *q ? q+1 : NULL;
} while(p);
return count - StartIndex;
}

// 1-st param: message text (if multiline, then lines must be separated by '\n')
// 2-nd param: message title (if absent or nil, then "Message" is used)
// 3-rd param: buttons (if multiple, then captions must be separated by ';';
Expand Down Expand Up @@ -3025,14 +3010,6 @@ LONG_PTR GetEnableFromLua (lua_State *L, int pos)
return ret;
}

static void SetColorForeAndBack(lua_State *L, const struct FarTrueColorForeAndBack *fb, const char *name)
{
lua_createtable(L,0,2);
PutIntToTable(L, "ForegroundColor", FarTrueColorToRGB(&fb->Fore));
PutIntToTable(L, "BackgroundColor", FarTrueColorToRGB(&fb->Back));
lua_setfield(L, -2, name);
}

DWORD GetColorFromTable(lua_State *L, const char *field, int index)
{
DWORD val;
Expand All @@ -3057,13 +3034,6 @@ static void FillColor(lua_State *L, struct FarTrueColorForeAndBack *fb)
}
}

static void FillColorForeAndBack(lua_State *L, struct FarTrueColorForeAndBack *fb, const char *Name)
{
lua_getfield(L, -1, Name);
FillColor(L, fb);
lua_pop(L,1);
}

static void FillDialogColors(lua_State *L, struct ColorDialogData *Data)
{
uint64_t Fore = GetColorFromTable (L, "ForegroundColor", 1) & 0xFFFFFF;
Expand Down Expand Up @@ -5895,6 +5865,7 @@ static const luaL_Reg dialog_methods[] =
PAIR( dlg, GetConstTextPtr),
PAIR( dlg, GetCursorPos),
PAIR( dlg, GetCursorSize),
PAIR( dlg, GetDefaultColor),
PAIR( dlg, GetDialogInfo),
PAIR( dlg, GetDlgData),
PAIR( dlg, GetDlgItem),
Expand Down

0 comments on commit c07f890

Please sign in to comment.