Skip to content

Commit

Permalink
Продолжение revision 12021: аргументы, передаваемые обработчикам собы…
Browse files Browse the repository at this point in the history
…тия "CommandLine", задаются списком Lua-выражений.
  • Loading branch information
shmuz committed Jun 30, 2014
1 parent 459ce87 commit 84330d1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 47 deletions.
14 changes: 7 additions & 7 deletions enc/enc_lua/macroapi_manual.en.tsi
Expand Up @@ -1700,7 +1700,7 @@ lv=1
dt=Text
nm=LuaMacro plugin
ctime=3551991405
mtime=3613146423
mtime=3613298444
<article>
#_<markdown>
#_This plugin is necessary for macros to work, therefore it should be installed. The same is true regarding the runtime (*lua51.dll*, *luafar3.dll* and *lpeg.dll*) that is necessary for plugin's work.
Expand All @@ -1717,20 +1717,20 @@ mtime=3613146423
#_ Unload macros (except those created with operation `MCTL_ADDMACRO`) and event handlers.
#_* `macro: about`<br>
#_ Show versions of the plugin and the libraries it is using.
#_* `macro: user [<text>]`<br>
#_* `macro: user [<args>]`<br>
#_ Initiate event `"CommandLine"`. [Handlers](78.html) of this event, if any, receive
#_ a sequence of of arguments extracted from the string `<text>`.
#_ arguments `<args>`. Arguments are a sequence of Lua-expressions delimited with commas.
#_* `lua: <code>`
#_* `moon: <code>`<br>
#_ Execute the code `<code>` written correspondingly in Lua or MoonScript.<br>
#_ If `<code>` begins with a character `=` then `far.Show()` is called, e.g.:<br>
#_ `lua:=5+2,6,"foo"` is equivalent to `lua:far.Show(5+2,6,"foo")`.
#_* `lua: @<filename> [<params>]`
#_* `moon: @<filename> [<params>]`<br>
#_* `lua: @<filename> [<args>]`
#_* `moon: @<filename> [<args>]`<br>
#_ Execute the script `<filename>` written correspondingly in Lua or MoonScript.<br>
#_ - For passing parameters to the script they should be specified after the file name,
#_ - For passing arguments to the script they should be specified after the file name,
#_ separated with whitespace.
#_ - Parameters are a sequence of expressions delimited with commas.
#_ - Arguments are a sequence of expressions delimited with commas.
#_ - The expressions must be written in the same programming language as the script.
#_ - The global (within the environment of the script) variable `_filename` contains
#_ the file name.
Expand Down
16 changes: 8 additions & 8 deletions enc/enc_lua/macroapi_manual.ru.tsi
Expand Up @@ -1693,7 +1693,7 @@ lv=1
dt=Text
nm=������ LuaMacro
ctime=3551991405
mtime=3613146363
mtime=3613297962
<article>
#_<markdown>
#_������ ������ ��������� ��� ������ ��������, ������� ������ ���� ����������. �� �� �������� � �������� (*lua51.dll*, *luafar3.dll* � *lpeg.dll*), ������������ ��� ������ �������.
Expand All @@ -1710,20 +1710,20 @@ mtime=3613146363
#_ ��������� ������� (����� ��������� ��������� `MCTL_ADDMACRO`) � ����������� �������.
#_* `macro: about`<br>
#_ �������� ������ ������� � ������������ �������� ���������.
#_* `macro: user [<text>]`<br>
#_* `macro: user [<args>]`<br>
#_ ������������ ������� `"CommandLine"`. [������������](78.html) ������� �������,
#_ ���� ������� �������, ����� �������� ������������������ ����������, ���������� ��
#_ ������ `<text>`.
#_ ���� ������� �������, ����� �������� ������������������ ���������� `<args>`.
#_ ��������� �������� ������� Lua-���������, ���������� ��������.
#_* `lua: <code>`
#_* `moon: <code>`<br>
#_ ��������� ��� `<code>`, ���������� �������������� �� Lua ��� MoonScript.<br>
#_ ���� `<code>` ���������� � ������� `=`, �� ���������� `far.Show()`, ��������:<br>
#_ `lua:=5+2,6,"foo"` ������������ `lua:far.Show(5+2,6,"foo")`.
#_* `lua: @<filename> [<params>]`
#_* `moon: @<filename> [<params>]`<br>
#_* `lua: @<filename> [<args>]`
#_* `moon: @<filename> [<args>]`<br>
#_ ��������� ������ `<filename>`, ���������� �������������� �� Lua ��� MoonScript.<br>
#_ - ���� ����� �������� ������� ���������, �� ������� ������� ����� ����� ����� ����� ������.
#_ - ��������� �������� ������� ���������, ���������� ��������.
#_ - ���� ����� �������� ������� ���������, �� ������� ������� ����� ����� ����� ����� ������.
#_ - ��������� �������� ������� ���������, ���������� ��������.
#_ - ��������� ������ ������������ ��� �� ���� ����������������, ��� � ������.
#_ - ���������� (� �������� ��������� �������) ���������� `_filename` �������� ��� �����.
#_
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 385 },
Version = { 1, 0, 0, 386 },
MinFarVersion = { 3, 0, 0, 3948 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
6 changes: 5 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,8 @@
shmuel 28.06.2014 19:47:38 +0200 - build 385
shmuel 30.06.2014 14:02:24 +0200 - build 386

1. Продолжение 383: аргументы, передаваемые обработчикам события "CommandLine", задаются списком Lua-выражений.

shmuel 28.06.2014 19:47:38 +0200 - build 385

1. Продолжение 383: плагин передаёт обработчикам события "CommandLine" не таблицу, а последовательность аргументов.

Expand Down
35 changes: 8 additions & 27 deletions plugins/luamacro/luamacro.lua
Expand Up @@ -288,32 +288,6 @@ local function About()
far.Message(text, "About", nil, "l")
end

local SplitCommandLine do
local pattern = regex.new([=[
" ( (?: \\" | [^"] )* ) "? |
( (?: \\" | [^"\s] )+ ) |
\s+
]=], "x")
SplitCommandLine = function (str)
local t, n, outside = {}, 0, true
pattern:gsub(str, function(a,b)
if a or b then
a = (a or b):gsub("\\\"", "\"")
if outside then
n = n + 1
t[n] = a
outside = false
else
t[n] = t[n]..a
end
else
outside = true
end
end)
return t
end
end

local function ProcessCommandLine (CmdLine)
local prefix, text = CmdLine:match("^%s*(%w+):%s*(.-)%s*$")
prefix = prefix:lower()
Expand All @@ -325,7 +299,14 @@ local function ProcessCommandLine (CmdLine)
elseif cmd == "post" then -- DEPRECATED, to be removed on 2014-Oct-29.
prefix, text = "lua", text:match("%S+%s*(.*)")
elseif cmd == "about" then About()
elseif cmd == "user" then utils.CommandLineEvent(SplitCommandLine(text:sub(5)))
elseif cmd == "user" then
local f,msg = loadstring("return "..text:sub(5))
if f then
local env = setmetatable({}, gmeta)
utils.CommandLineEvent(pcall(setfenv(f, env)))
else
ErrMsg(msg)
end
elseif cmd ~= "" then ErrMsg(Msg.CL_UnsupportedCommand .. cmd) end
end
if prefix == "lua" or prefix == "moon" then
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 385
#define PLUGIN_BUILD 386
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down
1 change: 1 addition & 0 deletions plugins/luamacro/mbrowser.lua
Expand Up @@ -184,6 +184,7 @@ local function MenuLoop()
Title = Title,
Flags = {FMENU_SHOWAMPERSAND=1,FMENU_WRAPMODE=1,FMENU_CHANGECONSOLETITLE=1},
MaxHeight = farRect.Bottom - farRect.Top - 6,
Id = win.Uuid("03DEFB28-8734-4EC0-8B25-C879846F0BE5"),
}

local bkeys = {
Expand Down
5 changes: 3 additions & 2 deletions plugins/luamacro/utils.lua
Expand Up @@ -188,8 +188,9 @@ local function export_ProcessEditorInput (Rec)
return EV_Handler(Events.editorinput, editor.GetFileName(nil), Rec)
end

local function CommandLineEvent (args)
return EV_Handler(Events.commandline, nil, unpack(args))
local function CommandLineEvent (ok, ...)
if ok then return EV_Handler(Events.commandline, nil, ...) end
ErrMsg((...))
end

local ExpandKey do -- èçìåðåííîå âðåìÿ èñïîëíåíèÿ íà êëþ÷å "CtrlAltShiftF12" = 5.7uS (Lua); 3.5uS (LuaJIT);
Expand Down

0 comments on commit 84330d1

Please sign in to comment.