Página 1 de 2

LuaLint Plugin for NotePad++

Publicado: 03 Ene 2018 16:19
por Pabloko
Hello, having to edit huge lua files lately, i quickly made a NotePad++ plugin to check integrity of lua code

Imagen

FEATURES:
  • Auto check .lua files when saved
  • Also allow to check any file even not saved tab by Plugin menu
Its compiled with lua5.1.4

Note: This plugin only check syntactic errors on code, its not aware of programming errors.

INSTALL: Put this dll on npp plugins folder
DOWNLOAD: https://mega.nz/#!IQI3GTIB!MIrWrkneTk4l ... vNdD0TXJVY
Source code: (all code is same as NppPluginTemplate base they provide ill only dump changes)

Código: Seleccionar todo

lua_State* L;
//
// Initialize your plugin data here
// It will be called while plugin loading   
void pluginInit(HANDLE /*hModule*/)
{
	L = lua_open();
}

//
// Here you can do the clean up, save the parameters (if any) for the next session
//
void pluginCleanUp()
{
	lua_close(L);
}

...


extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
{
	switch (notifyCode->nmhdr.code) 
	{
		case NPPN_SHUTDOWN:
		{
			commandMenuCleanUp();
		}
		break;

		case NPPN_FILEBEFORESAVE:
		{
			hello();
		}
		break;

		default:
			return;
	}
}

...

void hello()
{
    int which = -1;
    ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
    if (which == -1)
        return;
    HWND curScintilla = (which == 0)?nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
	TCHAR ext[MAX_PATH];
	::SendMessage(nppData._nppHandle, NPPM_GETEXTPART, 0, (LPARAM)ext);
	if (wcsstr((wchar_t*)ext, L".lua") != NULL) {}
	else {
		::SendMessage(nppData._nppHandle, NPPM_GETCURRENTLANGTYPE, 0, (LPARAM)&langtype);
		if (langtype != LangType::L_LUA) return;
	}
	int nLength = ::SendMessage(curScintilla, SCI_GETLENGTH, 0, NULL);
	CHAR * pBuffer = new CHAR[nLength + 1];
	::memset((void *)pBuffer, 0, sizeof(CHAR) * (nLength + 1));
	int nTempLength = (int) ::SendMessageA(curScintilla, SCI_GETTEXT, nLength + 1, (LPARAM)pBuffer);
	//lua_State* L = lua_open();
	if (luaL_loadbuffer(L, (char*)pBuffer, nLength, "LuaLint") != 0) {
		const char *err = lua_tostring(L, -1);
		//TRIM FIRST PART
		int ccstart = 0;
		for (int cc = 0; cc < (int)nLength; cc++) {
			if (err[cc] == ':') {
				ccstart = cc + 1;
				break;
			}
		}
		char linenumberstr[12];
		for (int cc = ccstart; cc < (int)nLength; cc++) {
			linenumberstr[cc - ccstart] = err[cc];
			if (err[cc] == ':')  break;
		}
		int line = atoi(linenumberstr)-1;
		::SendMessage(curScintilla, SCI_GOTOLINE, line, NULL);
		MessageBoxA(NULL, (char*)err + ccstart, "Lua Error", MB_OK);
	}
	//lua_close(L);
	nTempLength = 0;
	delete pBuffer;
}

Re: LuaLint Plugin for NotePad++

Publicado: 03 Ene 2018 19:31
por abood1987
Imagen

:)

my app version is :

Imagen

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 05:10
por Pabloko
Can u try this? https://puu.sh/yTO0r/83e847a43b.dll
Ive compiled it with weird c++ toolset, now should work

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 11:04
por abood1987
I forgot to remind you that this next message appears to me first:
Imagen
Knowing that I put the msvcr120.dll file In the system folder "System32" or in "C:\Program Files\Notepad++"
but the problem still occurs with me :hypno: and after i clicked ok this message is showen :
Imagen

:hypno: :hypno: :hypno:

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 16:39
por Pabloko
Its very stange, that error means that you have to install
VC Redistributable package 2013 x86 - https://www.microsoft.com/es-es/downloa ... x?id=40784

But it not makes sense that it MSVCRT120D.dll that means DEBUG but plugin isnt compiled on debug and also /MT what should include all CRT runtime and not need external install.

Maybe its lua! Let me recompile everithing again check if works, its my firts plugin on npp https://puu.sh/yU6jI/b3571e7f76.dll

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 19:26
por abood1987
Pabloko escribió:
04 Ene 2018 16:39

Maybe its lua! Let me recompile everithing again check if works, its my firts plugin on npp https://puu.sh/yU6jI/b3571e7f76.dll
By this last modification it works fine without any MSVCRT120D.dll files "very good Pablo Gracias"
Imagen

ImagenImagenImagen

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 19:49
por usamakey
tnks m8

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 19:55
por Pabloko
fine, i updated the download link on 1st post and a bit of code, it will check lua files or files where you select language>LUA

Re: LuaLint Plugin for NotePad++

Publicado: 04 Ene 2018 19:56
por abood1987
Pablo
i Can Call this dll in AMS ? How ?
Because I want to use it with Scintilla Object Plugin So that this function can be called with DLL.CallFunction ?

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 03:59
por Pabloko
Hmm no because this DLL has notepad++ specific api, but for your editor you can just use luac.exe, the lua compiler that converts code to bytecode. just use:

Código: Seleccionar todo

luac.exe -p filename.lua
luac -p - <input code on stdin>
It will dump errors on code, thats the same way i use to get errors.

Código: Seleccionar todo

if(luaL_loadbuffer(L, "CODE",codesize, "FILENAME")!=0) error(lua_tosting(L,-1))
It also works in native lua but executes the code...

Código: Seleccionar todo

err = loadstring("code")() --err contain error or nil of its ok
Here its a version of luac.exe with static dll (embedded) https://puu.sh/yUsRT/3883d4015e.rar

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 14:33
por abood1987
ok i can used that :
nlen = Scintilla.SendMessage("Plugin1",MinTabIndex, "num",SCI_GETLENGTH, "num", 0, "num",0);
ret , text = Scintilla.SendMessage("Plugin1", MinTabIndex, "num", SCI_GETTEXT, "num", nlen+1, "pstr", nlen);

Dialog.Message("",assert(loadstring(text))());

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 20:00
por Pabloko
abood1987 escribió:
05 Ene 2018 14:33
ok i can used that :
nlen = Scintilla.SendMessage("Plugin1",MinTabIndex, "num",SCI_GETLENGTH, "num", 0, "num",0);
ret , text = Scintilla.SendMessage("Plugin1", MinTabIndex, "num", SCI_GETTEXT, "num", nlen+1, "pstr", nlen);

Dialog.Message("",assert(loadstring(text))());
Problem with that is that you actually execute the code, that can give you problems in your project, that why i suggested luac.exe

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 21:42
por abood1987
Pabloko escribió:
05 Ene 2018 20:00

Problem with that is that you actually execute the code, that can give you problems in your project, that why i suggested luac.exe
can you put an apz ? Sorry I did not understand the correct way to use your file
I tried so but nothing :)
File.Run(_DesktopFolder.."\\aa\\luac5.1.exe", _DesktopFolder.."\\aa\\MyFile.lua", "", SW_HIDE, true);

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 22:36
por Pabloko
Well i tried myself and it not so simple as error messages are put into stderr, you have to use commandline plugin or something like that, for simplicity i just compiled a dll that does this task :)

	int lua_lualint(lua_State* L) {
lua_State* Ls = lua_open();
const char * pBuffer = lua_tostring(L, 1);
const char * fileName = lua_tostring(L, 2);
if (luaL_loadbuffer(Ls, (char*)pBuffer, strlen(pBuffer), fileName) != 0) {
const char *err = lua_tostring(Ls, -1);
lua_pushstring(L, err);
}
else lua_pushnil(L);
lua_close(Ls);
return 1;
}
// Ejemplo de función exportada.
LUALINT_API int luaopen_LuaLint(lua_State* L)
{
lua_register(L, "lualint", lua_lualint);
return 0;
}


Download:
HIDE: ON
Hidebb Message Hidden Description


Usage:
require("LuaLint")

err = lualint('if (a==b) theen print(k) end', 'myfile.lua')
if (err~=nil) then
	Dialog.Message('lua error', err)
end

Re: LuaLint Plugin for NotePad++

Publicado: 05 Ene 2018 23:07
por abood1987
Pabloko escribió:
05 Ene 2018 22:36
Well i tried myself and it not so simple as error messages are put into stderr, you have to use commandline plugin or something like that, for simplicity i just compiled a dll that does this task :)

	int lua_lualint(lua_State* L) {
lua_State* Ls = lua_open();
const char * pBuffer = lua_tostring(L, 1);
const char * fileName = lua_tostring(L, 2);
if (luaL_loadbuffer(Ls, (char*)pBuffer, strlen(pBuffer), fileName) != 0) {
const char *err = lua_tostring(Ls, -1);
lua_pushstring(L, err);
}
else lua_pushnil(L);
lua_close(Ls);
return 1;
}
// Ejemplo de función exportada.
LUALINT_API int luaopen_LuaLint(lua_State* L)
{
lua_register(L, "lualint", lua_lualint);
return 0;
}


Download:
HIDE: ON
Hidebb Message Hidden Description


Usage:
require("LuaLint")

err = lualint('if (a==b) theen print(k) end', 'myfile.lua')
if (err~=nil) then
	Dialog.Message('lua error', err)
end
that is very good
Imagen

Gracias Pablo Imagen

Re: LuaLint Plugin for NotePad++

Publicado: 06 Ene 2018 00:24
por Pabloko
With sci, you should parse this message and use sci api to print it better

Imagen

Use annotations to display the message and markers if you want

Código: Seleccionar todo

SCI_ANNOTATIONSETTEXT(int line, const char *text)
SCI_ANNOTATIONSETSTYLE(int line, int style)
SCI_MARKERADD(int line, int markerNumber)
...
I sould did the same on notepad++ editor but i did it quick for me, didnt think about releasing it.

Re: LuaLint Plugin for NotePad++

Publicado: 06 Ene 2018 00:38
por abood1987
Pabloko escribió:
06 Ene 2018 00:24
With sci, you should parse this message and use sci api to print it better

Imagen

Use annotations to display the message and markers if you want

Código: Seleccionar todo

SCI_ANNOTATIONSETTEXT(int line, const char *text)
SCI_ANNOTATIONSETSTYLE(int line, int style)
SCI_MARKERADD(int line, int markerNumber)
...
yes that is good idea Imagen

Re: LuaLint Plugin for NotePad++

Publicado: 29 Ene 2018 22:48
por patch
Nice plugin feller.

Re: LuaLint Plugin for NotePad++

Publicado: 11 Jul 2020 00:17
por mahdi1993
thanks pabloco

Re: LuaLint Plugin for NotePad++

Publicado: 11 Jul 2020 00:19
por mahdi1993
Hi dear friends.
I need lualint plugin strongly.
Put download link is damage.
Can you update download link please????