diff options
author | 2016-01-30 22:10:09 -0500 | |
---|---|---|
committer | 2016-01-30 22:10:09 -0500 | |
commit | 491a5f0b794c799a1c45971ef92e86488b322b81 (patch) | |
tree | c7be4cf887b1b7bbc820c2175d543f2f4409d09c | |
parent | aad5a9aeab1390d4c8fb07e6d790425f6d84b9c1 (diff) | |
download | textadept-491a5f0b794c799a1c45971ef92e86488b322b81.tar.gz textadept-491a5f0b794c799a1c45971ef92e86488b322b81.zip |
Replaced `buffer:text_range()` C function with a Lua function.
-rw-r--r-- | core/init.lua | 12 | ||||
-rw-r--r-- | src/textadept.c | 16 |
2 files changed, 12 insertions, 16 deletions
diff --git a/core/init.lua b/core/init.lua index 093d0faa..ce126943 100644 --- a/core/init.lua +++ b/core/init.lua @@ -33,6 +33,18 @@ if CURSES and WIN32 then end end +-- Replacement for original `buffer:text_range()`, which has a C struct for an +-- argument. +-- Documentation is in core/.buffer.luadoc. +local function text_range(buffer, start_pos, end_pos) + local target_start, target_end = buffer.target_start, buffer.target_end + buffer:set_target_range(start_pos, end_pos) + local text = buffer.target_text + buffer:set_target_range(target_start, target_end) -- reset + return text +end +events.connect(events.BUFFER_NEW, function() buffer.text_range = text_range end) + --[[ This comment is for LuaDoc. --- -- Extends Lua's _G table to provide extra functions and fields for Textadept. diff --git a/src/textadept.c b/src/textadept.c index d608b205..ac9d1967 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -1107,20 +1107,6 @@ static int lbuffer_new(lua_State *L) { return (lua_rawgeti(L, -1, lua_rawlen(L, -1)), 1); } -/** `buffer.text_range()` Lua function. */ -static int lbuffer_text_range(lua_State *L) { - Scintilla *view = focused_view; - int result = l_globaldoccompare(L, 1); - if (result != 0) view = (result > 0) ? dummy_view : command_entry; - Sci_PositionCR min = luaL_checkinteger(L, 2), max = luaL_checkinteger(L, 3); - luaL_argcheck(L, min <= max, 3, "start > end"); - struct Sci_TextRange tr = {{min, max}, malloc(max - min + 1)}; - SS(view, SCI_GETTEXTRANGE, 0, (sptr_t)&tr); - lua_pushlstring(L, tr.lpstrText, max - min); - if (tr.lpstrText) free(tr.lpstrText); - return 1; -} - /** * Checks whether the function argument arg is the given Scintilla parameter * type and returns it cast to the proper type. @@ -1329,7 +1315,6 @@ static void lL_adddoc(lua_State *L, sptr_t doc) { #endif l_setcfunction(L, -2, "delete", lbuffer_delete); l_setcfunction(L, -2, "new", lbuffer_new); - l_setcfunction(L, -2, "text_range", lbuffer_text_range); l_setmetatable(L, -2, "ta_buffer", lbuf_property, lbuf_property); // t[doc_pointer] = buffer, t[#t + 1] = buffer, t[buffer] = #t lua_pushvalue(L, -2), lua_settable(L, -4); @@ -1543,7 +1528,6 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { if (!reinit) { lua_newtable(L); l_setcfunction(L, -1, "focus", lce_focus); - l_setcfunction(L, -1, "text_range", lbuffer_text_range); l_setmetatable(L, -1, "ta_buffer", lbuf_property, lbuf_property); } else { lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers"); |