Scripts discussion (2)

Discuss and announce AkelPad plugins
Locked
  • Author
  • Message
Offline
Site Admin
Posts: 6403
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

Infocatcher wrote:Improved: don't get output twice. ;)
А теперь сравни скорость на более менее большом файле.

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Instructor
Как все, оказывается, печально. :?

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Тогда как-то так:
CodePoster_mod2.js
Хотя там весьма криво сделано вытаскивание пробельных символов из конца текста. :?

Пожалуй, не хватает возможности прочитать DT_ANSI/DT_UNICODE не до конца строки, а до выбранной позиции.
Или надо читать DT_BYTE/DT_WORD и делать String.fromCharCode(). Но блоками, вроде, должно быть быстрее.

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Не так криво, но потенциально не очень быстро:
CodePoster_mod3.js

[Upd] Ай, я же вывод ссылок поломал. :)
[Upd] Вроде, починил.

Offline
Site Admin
Posts: 6403
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »


KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

FeyFre
Script QuoteExtend.js
I don't understand for what purpose you have used "wnd" variable.
It seems to me that it can be replaced by "edit".

Code: Select all

var edit = AkelPad.GetEditWnd();
...
   var wnd = edit || AkelPad.GetEditWnd();
...

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Translator.js
Added: Esperanto in Google Translate.

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ
edit - is optional argument, wnd - local variable. If edit is not specified by caller function assumes current edit window. If edit is given - function works with it.
Extraction from ecma-262
The production LogicalORExpression : LogicalORExpression || LogicalANDExpression is evaluated as follows:
1. Let lref be the result of evaluating LogicalORExpression.
2. Let lval be GetValue(lref).
3. If ToBoolean(lval) is true, return lval.
4. Let rref be the result of evaluating LogicalANDExpression.
5. Return GetValue(rref).
I.e if edit is evaluable to boolean true(i.e. non false, not 0, not null, not "", not undefined) result of expression is left operand. Otherwise - right operand. Left operand can be null only if it is not given bay caller, so right operand will be calculated.
Yes, in this simple case it is redundant, by in future this little function may probably be exported to larger library so I became brave enough to prepare it.

By the way, you didn't asked why I used form "var doit = function(edit,quote){}" instead of "function doit(edit,quote){}" :)

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

FeyFre
Well, in that case, probably is not needed "if(edit)".

Code: Select all

//if(edit)
{
   doit(edit,quotes);
}

Offline
Posts: 2248
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, not, it absolutely required in case of MDI with no tabs. GetEditWnd() will return 0 and doit will do something weird. But if(edit) prevents it. Yes, I could add such check inside of doit, but I didn't %) I did it outside

Offline
Posts: 176
Joined: Sat Dec 24, 2011 4:05 pm

Post by F. Phoenix »

Ну а все же, к теме о получении строк... можно как-нибудь по-человечески получить данные о настоящей строке текста, а не той, которая в результате переноса образовалась - при этом не переключая настройку WordWrap (ибо это лишние мигания) и не извращаясь из серии "загрузить весь файл в Яву, а там String.Split('\n');" (не особо шустро)? Редактор-то наверняка знает все о своих строках... =\

Кстати еще вопросик по яваскрипту - есть ли в нем какие-либо аналоги си-шарповых ref и out, для изменения значений тех переменных, которые указаны аргументами функции? Чет не нашел... А если нету, то как лучше быть, если функция должна вернуть не одно значение, а несколько - только работать с глобальными переменными чтоли?

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

F. Phoenix wrote:... можно как-нибудь по-человечески получить данные о настоящей строке текста, а не той, которая в результате переноса образовалась ...
See in AkelEdit.h (AkelPad source):
AEM_GETWRAPLINE and AEM_GETUNWRAPLINE.

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Всплыло старое наследие.

Code: Select all

var lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/, true);
Теперь зачем-то ругается, хотя в доке ничего не сказано про повторное появление второго параметра. :?
Скрипт: <...>\AkelFiles\Plugs\Scripts\TabsToSpaces_mod.js
Строка: 117
Символ: 2
Ошибка: Недопустимое число аргументов или присвоение значения свойства
Код: 800A01C2
Источник: Ошибка выполнения Microsoft JScript
И у меня такого много накопипастилось...

Offline
Posts: 1873
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

F. Phoenix wrote:... получить данные о настоящей строке текста, а не той, которая в результате переноса образовалась - при этом не переключая настройку WordWrap
viewtopic.php?p=11379#p11379
F. Phoenix wrote:Кстати еще вопросик по яваскрипту - есть ли в нем какие-либо аналоги си-шарповых ref и out, для изменения значений тех переменных, которые указаны аргументами функции? Чет не нашел... А если нету, то как лучше быть, если функция должна вернуть не одно значение, а несколько - только работать с глобальными переменными чтоли?
https://developer.mozilla.org/en/JavaSc ... /Functions
Primitive parameters (such as a number) are passed to functions by value; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.

If you pass an object (i.e. a non-primitive value, such as Array or a user-defined object) as a parameter, and the function changes the object's properties, that change is visible outside the function
Способа изменить такое поведение нету.
Так что если надо вернуть несколько значений, проще вернуть объект или массив:

Code: Select all

function get() {
	return {
		x: 0,
		y: 1
	};
}
var o = get();
WScript.Echo(o.x + "\n" + o.y);
Ну, или так:

Code: Select all

var o1 = { value: 1 };
var o2 = { value: 2 };
function get(out1, out2) {
	out1.value = 3;
	out2.value = 4;
	return 5;
}
var out = get(o1, o2);
WScript.Echo(out + "\n" + o1.value + "\n" + o2.value);

Offline
Site Admin
Posts: 6403
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

Infocatcher
Параметр упразнен.
Scripts.idl wrote: //Allocate memory.
HRESULT MemAlloc([in] DWORD dwSize, [out, retval] MYRETHANDLE *nPointer);

//Copy memory.
HRESULT MemCopy([in] MYHANDLE nPointer, [in] VARIANT vpData, [in] DWORD dwType, [in, defaultvalue(-1)] int nDataLen, [out, retval] int *nBytes);

//Read memory.
HRESULT MemRead([in] MYHANDLE nPointer, [in] DWORD dwType, [in, defaultvalue(-1)] int nDataLen, [out, retval] VARIANT *vpData);

//Get pointer to a script string.
HRESULT MemStrPtr([in] BSTR wpString, [out, retval] MYRETHANDLE *nPointer);

//Free memory.
HRESULT MemFree([in] MYHANDLE nPointer);
Locked