Skip to content

Commit

Permalink
LuaFAR: fix unicode.utf8.gmatch and add a specific test for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jun 7, 2016
1 parent 70b38c1 commit daa52bd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 570 },
Version = { 1, 0, 0, 571 },
MinFarVersion = { 3, 0, 0, 4582 },
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 @@
zg 08.05.2016 13:40:15 +0200 - build 570
shmuel 08.06.2016 00:23:44 +0200 - build 571

1. LuaFAR: fix unicode.utf8.gmatch and add a specific test for it.

zg 08.05.2016 13:40:15 +0200 - build 570

1. LuaFAR: поддержка WTYPE_COMBOBOX.

Expand Down
19 changes: 10 additions & 9 deletions plugins/luamacro/luafar/slnunico.c
Expand Up @@ -1318,10 +1318,11 @@ static int unic_match(lua_State *L)

static int gmatch_aux(lua_State *L)
{
MatchState *ms = (MatchState*)lua_tostring(L, lua_upvalueindex(4));
MatchState *ms = (MatchState*)lua_touserdata(L, lua_upvalueindex(4));
const char *p = lua_tostring(L, lua_upvalueindex(2));
const char *src;

ms->L = L; /* important, as gmatch and gmatch_aux can be called from different coroutines */
for(src = ms->src_init + (size_t)lua_tointeger(L, lua_upvalueindex(3));
src <= ms->src_end;
advance(&src, ms->mb))
Expand Down Expand Up @@ -1349,16 +1350,16 @@ static int gmatch_aux(lua_State *L)
static int gmatch(lua_State *L)
{
size_t len;
MatchState ms;
ms.L = L;
ms.src_init = luaL_checklstring(L, 1, &len);
ms.src_end = ms.src_init + len;
ms.mode = get_mode(L);
ms.mb = MODE_MBYTE(ms.mode);
luaL_checkstring(L, 2);
MatchState *ms;

lua_settop(L, 2);
lua_pushinteger(L, 0);
lua_pushlstring(L, (char*)&ms, sizeof(MatchState));
ms = (MatchState*) lua_newuserdata(L, sizeof(MatchState));
ms->src_init = luaL_checklstring(L, 1, &len);
ms->src_end = ms->src_init + len;
ms->mode = get_mode(L);
ms->mb = MODE_MBYTE(ms->mode);
luaL_checkstring(L, 2);
lua_pushcclosure(L, gmatch_aux, 4);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 570
#define PLUGIN_BUILD 571
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down
13 changes: 13 additions & 0 deletions plugins/luamacro/macrotest.lua
Expand Up @@ -1667,6 +1667,18 @@ local function test_issue_3129()
assert(k == 3)
end

local function test_gmatch_coro()
local function yieldFirst(it)
return coroutine.wrap(function()
coroutine.yield(it())
end)
end

local it = ("1 2 3"):gmatch("(%d+)")
local head = yieldFirst(it)
assert(head() == "1")
end

function MT.test_luafar()
test_AdvControl()
test_bit64()
Expand All @@ -1675,6 +1687,7 @@ function MT.test_luafar()
test_MacroControl()
test_RegexControl()
test_issue_3129()
test_gmatch_coro()
end

-- Test in particular that Plugin.Call (a so-called "restricted" function) works properly
Expand Down

0 comments on commit daa52bd

Please sign in to comment.