diff options
author | 2014-03-26 10:15:53 -0400 | |
---|---|---|
committer | 2014-03-26 10:15:53 -0400 | |
commit | f65b2b2a66f05b20010256ca1d81cc3252ea1471 (patch) | |
tree | c7ee3cd4753a9e8a73f9e9d3e8a45f96eb5b36c7 | |
parent | 6304010d93b3cfe43e246dbb49c60d147a366b1b (diff) | |
download | textadept-f65b2b2a66f05b20010256ca1d81cc3252ea1471.tar.gz textadept-f65b2b2a66f05b20010256ca1d81cc3252ea1471.zip |
Include my new "lspawn" module by default for spawning processes.
The `textadept.run` module now uses `spawn()` instead of `io.popen()`.
This module replaces the dependency on winapi. Removed experimental
`io.popen()` and `os.execute()` hooks. They may be re-implemented later using
`spawn()`.
-rw-r--r-- | core/.proc.luadoc | 29 | ||||
-rw-r--r-- | core/file_io.lua | 45 | ||||
-rw-r--r-- | core/init.lua | 29 | ||||
-rw-r--r-- | core/locale.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.de.conf | 5 | ||||
-rw-r--r-- | core/locales/locale.es.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.fr.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.ru.conf | 3 | ||||
-rw-r--r-- | core/locales/locale.sv.conf | 37 | ||||
-rw-r--r-- | modules/lua/api | 10 | ||||
-rw-r--r-- | modules/lua/init.lua | 3 | ||||
-rw-r--r-- | modules/lua/tags | 9 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 1 | ||||
-rw-r--r-- | modules/textadept/run.lua | 35 | ||||
-rw-r--r-- | src/Makefile | 31 | ||||
-rw-r--r-- | src/textadept.c | 31 | ||||
-rw-r--r-- | src/winapi.patch | 456 |
17 files changed, 166 insertions, 567 deletions
diff --git a/core/.proc.luadoc b/core/.proc.luadoc new file mode 100644 index 00000000..ae62bdf8 --- /dev/null +++ b/core/.proc.luadoc @@ -0,0 +1,29 @@ +-- Copyright 2012-2014 Mitchell mitchell.att.foicica.com. See LICENSE. +-- This is a DUMMY FILE used for making LuaDoc for functions in the proc +-- userdata defined by the lspawn module. + +--- +-- Userdata representing a process created by `spawn()`. +module('proc') + +--- +-- Returns the status of `proc`, which is either "running" or "terminated". +-- @param proc A process created by `spawn()`. +-- @return "running" or "terminated" +function status(proc) end + +--- +-- Blocks until `proc` finishes. +-- @param proc A process created by `spawn()`. +function wait(proc) end + +--- +-- Writes string `input` to the stdin of `proc`. +-- @param proc A process created by `spawn()`. +-- @param ... Standard input for `proc`. +function write(proc, ...) end + +--- +-- Kills running `proc`. +-- @param proc A running process created by `spawn()`. +function kill(proc) end diff --git a/core/file_io.lua b/core/file_io.lua index 35ca5c03..a313cc66 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -418,48 +418,3 @@ function io.snapopen(paths, filter, exclude_FILTER, opts) for i = 1, #files do files[i] = files[i]:iconv(_CHARSET, 'UTF-8') end io.open_file(files) end - --- On Windows, override `io.popen` and `os.execute` to use winapi to prevent the --- flashing black box. -if WIN32 then - local winapi = require('winapi') - io.popen = function(prog) - local p, f = winapi.spawn_process(os.getenv('COMSPEC')..' /c '..prog) - if not p then return nil, f end - local file - file = { - read = function(self, format) - if not format or not format:find('^%*a') then return f:read() end - local chunk, text = f:read(), {} - while chunk do - text[#text + 1] = chunk - chunk = f:read() - end - return table.concat(text, '') - end, - write = function(self, ...) f:write(...) end, - flush = function() end, - lines = function() - local output, pos = file:read('*a'), 1 - if not output:find('\r?\n$') then output = output..'\n' end - return function() - local s, e, line = output:find('([^\r\n]*)\r?\n', pos) - if not s then return nil end - pos = e + 1 - return line - end - end, - close = function() - local _, status = p:wait(100) - if status == 'TIMEOUT' then p:kill() end - return true, 'exit', p:get_exit_code() - end - } - return file - end - os.execute = function(prog) - if not prog then return true end -- shell is available - local code = winapi.execute(prog) - return code == 0 and true or nil, 'exit', code - end -end diff --git a/core/init.lua b/core/init.lua index 6470f689..df4a5e38 100644 --- a/core/init.lua +++ b/core/init.lua @@ -122,4 +122,33 @@ local reset -- @class function -- @name timeout local timeout + +-- The function below comes from the lspawn module. + +--- +-- Spawns an interactive child process *argv* in a separate thread with the help +-- of GLib. +-- @param argv A UTF-8-encoded command line string containing the program's name +-- followed by arguments to pass to it. `PATH` is searched for program names. +-- @param working_dir The child's UTF-8 current working directory (cwd) or `nil` +-- to inherit the parent's. +-- @param stdout_cb A Lua function that accepts a string parameter for a block +-- of standard output read from the child. Stdout is read asynchronously in +-- 1KB or 0.5KB blocks (depending on the platform), or however much data is +-- available at the time. All text is encoded in `_CHARSET`. +-- @param stderr_cb A Lua function that accepts a string parameter for a block +-- of standard error read from the child. Stderr is read asynchronously in 1KB +-- or 0.5kB blocks (depending on the platform), or however much data is +-- available at the time. All text is encoded in `_CHARSET`. +-- @param exit_cb A Lua function that is called when the child process finishes. +-- The child's exit status is passed. +-- @return proc +-- @usage spawn('lua buffer.filename', nil, print) +-- @usage proc = spawn('lua -e "print(io.read())", nil, print) +-- proc:write('foo\\n') +-- @see _G._CHARSET +-- @see _G.proc +-- @class function +-- @name spawn +local spawn ]] diff --git a/core/locale.conf b/core/locale.conf index ed2b8d1c..37b784dd 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -177,6 +177,8 @@ Command _Entry = Command _Entry Select Co_mmand = Select Co_mmand _Run = _Run _Compile = _Compile +Buil_d = Buil_d +S_top = S_top _Next Error = _Next Error _Previous Error = _Previous Error _Adeptsense = _Adeptsense @@ -192,6 +194,7 @@ Snap_open = Snap_open Snapopen _User Home = Snapopen _User Home Snapopen _Textadept Home = Snapopen _Textadept Home Snapopen _Current Directory = Snapopen _Current Directory +Snapopen Current _Project = Snapopen Current _Project _Snippets = _Snippets _Insert Snippet... = _Insert Snippet... _Expand Snippet/Next Placeholder = _Expand Snippet/Next Placeholder diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index 40a3b746..6e2da778 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -167,8 +167,10 @@ Command _Entry = Befehlseingabe Select Co_mmand = Befehl auswählen _Run = Ausführen _Compile = Kompilieren +Buil_d = Build starten +S_top = Stoppen _Next Error = Nächstes Fehler -_Previous Error = Voriges Fehler +_Previous Error = Voriger Fehler _Adeptsense = _Adeptsense _Complete Symbol = Symbol vervollständigen Show _Documentation = Dokumentation anzeigen @@ -182,6 +184,7 @@ Snap_open = Snap_open Snapopen _User Home = Snapopen _Userhome-Verzeichnis Snapopen _Textadept Home = Snapopen _Textadept-Verzeichnis Snapopen _Current Directory = Snapopen aktuelles Verzeichnis +Snapopen Current _Project = Snapopen aktuelles Projekt _Snippets = _Snippets _Insert Snippet... = Snippet auswählen... _Expand Snippet/Next Placeholder = _Snippet einfügen/Nächster Platzhalter diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index 69da3223..6188c8f3 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -178,6 +178,8 @@ Command _Entry = _Línea de comandos Select Co_mmand = _Seleccionar comandos _Run = _Ejecutar _Compile = _Compilar +Buil_d = Co_nstruir +S_top = _Detener _Next Error = Error sig_uiente _Previous Error = Error _anterior _Adeptsense = _Adeptsense @@ -193,6 +195,7 @@ Snap_open = Snap_open Snapopen _User Home = Snapopen en carpeta de _usuario Snapopen _Textadept Home = Snapopen en carpeta de _Textadept Snapopen _Current Directory = Snapopen en carpeta _actual +Snapopen Current _Project = _Snippets = _Fragmentos de código _Insert Snippet... = _Insertar fragmento... _Expand Snippet/Next Placeholder = _Expandir fragmento/siguiente marcador diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index 5aa43d63..02d778d9 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -178,6 +178,8 @@ Command _Entry = Ligne de _commande Select Co_mmand = Sélectionner co_mmande _Run = _Lancer _Compile = _Compiler +Buil_d = C_onstruire +S_top = _Arrêter _Next Error = Erreur _suivant _Previous Error = Erreur _précédent _Adeptsense = _Adeptsense @@ -193,6 +195,7 @@ Snap_open = Snap_open Snapopen _User Home = Snapopen dossier _utilisateur Snapopen _Textadept Home = Snapopen dossier _Textadept Snapopen _Current Directory = Snapopen dossier _courant +Snapopen Current _Project = Snapopen _projet courant _Snippets = S_nippets _Insert Snippet... = _Insérer snippet... _Expand Snippet/Next Placeholder = _Étendre snippet/Marque snippet suivante diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index dcef6186..7fa0046d 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -167,6 +167,8 @@ Command _Entry = Командная _строка Select Co_mmand = Выбрать _команду _Run = _Запустить _Compile = _Скомпилировать +Buil_d = С_обрать +S_top = Ос_тановить _Next Error = Следующая Ошибка _Previous Error = Предыдущая Ошибка _Adeptsense = _Adeptsense @@ -182,6 +184,7 @@ Snap_open = _Быстрое открытие файлов Snapopen _User Home = Быстрое открытие _домашнего каталога Snapopen _Textadept Home = Быстрое открытие домашней страницы _Textadept Snapopen _Current Directory = Быстрое открытие _текущего каталога +Snapopen Current _Project = Быстрое открытие текущего _проект _Snippets = _Заготовки _Insert Snippet... = _Вставить загтовку... _Expand Snippet/Next Placeholder = _Развернуть заготовку/Следующая метка diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf index 11f04c70..e0ca67c6 100644 --- a/core/locales/locale.sv.conf +++ b/core/locales/locale.sv.conf @@ -20,7 +20,7 @@ Undefined event name = Odefinierat event-namn % core/file_io.lua Open = Öppna -Encoding conversion failed. = Kunde inte omvandla teckenkodningen. +Encoding conversion failed. = Kunde inte konvertera teckenkodningen. Cannot change binary file encoding = Kan inte ändra binär filkodning Save = Spara Untitled = Namnlös @@ -104,16 +104,16 @@ Files(F4) = Files(F4) % modules/textadept/keys.lua Lexer = Lexer Style = Stil -Error loading webpage: = Kunde inte ladda webbsida: +Error loading webpage: = Kunde inte läsa in webbsida: % modules/textadept/menu.lua _File = _Arkiv _New = _Nytt -_Open = _Öppna +_Open = _Öppna... Open _Recent... = Öppna s_enaste... Re_load = Ladda _om _Save = _Spara -Save _As = Spara so_m +Save _As = Spara so_m... Save All = Spara a_lla _Close = S_täng Close All = St_äng alla @@ -175,10 +175,12 @@ Goto Nex_t File Found = Gå till näs_ta funna fil Goto Previou_s File Found = Gå till f_öregående funna fil _Jump to = _Gå till rad... _Tools = _Verktyg -Command _Entry = _Kommandorad -Select Co_mmand = _Välj kommando +Command _Entry = _Kommandorad... +Select Co_mmand = _Välj kommando... _Run = K_ör _Compile = Ko_mpilera +Buil_d = B_ygg +S_top = Avbry_t _Next Error = _Nästa fel _Previous Error = _Föregående fel _Adeptsense = _Adeptsense @@ -190,15 +192,16 @@ _Clear Bookmarks = _Rensa bokmärken _Next Bookmark = _Nästa bokmärke _Previous Bookmark = _Föregående bokmärke _Goto Bookmark... = _Gå till bokmärke... -Snap_open = Snap_open -Snapopen _User Home = Snapopen _användarkonfiguration -Snapopen _Textadept Home = Snapopen _systemkonfiguration -Snapopen _Current Directory = Snapopen _nuvarande katalog -_Snippets = Sni_ppets -_Insert Snippet... = _Infoga snippet... -_Expand Snippet/Next Placeholder = _Expandera snippet/Nästa fält -_Previous Snippet Placeholder = _Föregående snippetfält -_Cancel Snippet = _Avbryt snippet +Snap_open = Snabb_öppna +Snapopen _User Home = Snabböppna _användarkonfiguration... +Snapopen _Textadept Home = Snabböppna _systemkonfiguration... +Snapopen _Current Directory = Snabböppna _nuvarande katalog... +Snapopen Current _Project = Snabböppna nuvarande _projekt... +_Snippets = Kodsn_uttar +_Insert Snippet... = _Infoga kodsnutt... +_Expand Snippet/Next Placeholder = Expandera kodsnutt/_Nästa fält +_Previous Snippet Placeholder = _Föregående fält +_Cancel Snippet = _Avbryt kodsnutt Show St_yle = Visa _stil _Buffer = _Buffert _Next Buffer = _Nästa buffert @@ -221,7 +224,7 @@ _ASCII Encoding = _ASCII _ISO-8859-1 Encoding = _ISO-8859-1 _MacRoman Encoding = _MacRoman UTF-1_6 Encoding = UTF-1_6 -Select _Lexer... = Välj _lexer... +Select _Lexer... = Välj språk (_lexer)... _Refresh Syntax Highlighting = _Uppdatera syntaxfärgning _View = V_y _Next View = _Nästa vy @@ -232,7 +235,7 @@ _Unsplit View = Slå _ihop vy Unsplit _All Views = _Endast en vy _Grow View = För_stora vy Shrin_k View = För_miska vy -Toggle Current _Fold = Växla nuvarande inf_ällning +Toggle Current _Fold = F_äll ihop/upp nuvarande sektion Toggle View _EOL = Växla _radslutstecken Toggle _Wrap Mode = Växla rad_brytning Toggle Show In_dent Guides = Växla in_dragshjälplinjer diff --git a/modules/lua/api b/modules/lua/api index 125d6a9f..08452f8d 100644 --- a/modules/lua/api +++ b/modules/lua/api @@ -555,7 +555,7 @@ current_pos buffer.current_pos (number)\nThe caret's position.\nWhen set, does n currentdir lfs.currentdir()\nReturns a string with the current working directory or nil plus an error\nstring. cursor buffer.cursor (number)\nThe display cursor type.\n\n* `buffer.CURSORNORMAL`\n The text insert cursor.\n* `buffer.CURSORARROW`\n The arrow cursor.\n* `buffer.CURSORWAIT`\n The wait cursor.\n* `buffer.CURSORREVERSEARROW`\n The reversed arrow cursor.\n\nThe default value is `buffer.CURSORNORMAL`. cut buffer.cut(buffer)\nCuts the selected text to the clipboard.\nMultiple selections are copied in order with no delimiters. Rectangular\nselections are copied from top to bottom with end of line characters. Virtual\nspace is not copied.\n@param buffer A buffer. -cwd textadept.run.cwd (string, Read-only)\nThe most recently executed compile or run shell command's working directory.\nIt is used for going to error messages with relative file paths. +cwd textadept.run.cwd (string, Read-only)\nThe most recently executed compile or run shell command's working\ndirectory.\nIt is used for going to error messages with relative file paths. date os.date([format [, time]])\nReturns a string or a table containing date and time, formatted according\nto the given string `format`.\n\nIf the `time` argument is present, this is the time to be formatted\n(see the `os.time` function for a description of this value). Otherwise,\n`date` formats the current time.\n\nIf `format` starts with '`!`', then the date is formatted in Coordinated\nUniversal Time. After this optional character, if `format` is the string\n"`*t`", then `date` returns a table with the following fields: `year` (four\ndigits), `month` (1-12), `day` (1-31), `hour` (0-23), `min` (0-59), `sec`\n(0-61), `wday` (weekday, Sunday is 1), `yday` (day of the year), and `isdst`\n(daylight saving flag, a boolean). This last field may be absent if the\ninformation is not available.\n\nIf `format` is not "`*t`", then `date` returns the date as a string,\nformatted according to the same rules as the ANSI C function `strftime`.\n\nWhen called without arguments, `date` returns a reasonable date and time\nrepresentation that depends on the host system and on the current locale\n(that is, `os.date()` is equivalent to `os.date("%c")`).\n\nOn non-Posix systems, this function may be not thread safe because of its\nreliance on C function `gmtime` and C function `localtime`. debug _G.debug (module)\nLua debug module. debug debug.debug()\nEnters an interactive mode with the user, running each string that\nthe user enters. Using simple commands and other debug facilities,\nthe user can inspect global and local variables, change their values,\nevaluate expressions, and so on. A line containing only the word `cont`\nfinishes this function, so that the caller continues its execution.\n\nNote that commands for `debug.debug` are not lexically nested within any\nfunction and so have no direct access to local variables. @@ -750,6 +750,7 @@ keychain keys.keychain (table)\nThe current chain of key sequences. (Read-only.) keys _G.keys (module)\nManages key bindings in Textadept. keys _G.keys (table)\nMap of key bindings to commands, with language-specific key tables assigned\nto a lexer name key. keys textadept.keys (module)\nDefines key commands for Textadept.\nThis set of key commands is pretty standard among other text editors. If\napplicable, load this module second to last in your *~/.textadept/init.lua*,\nbefore `textadept.menu`. +kill proc.kill(proc)\nKills running `proc`.\n@param proc A running process created by `spawn()`. last_char_includes lexer.last_char_includes(s)\nCreates and returns a pattern that verifies that string set *s* contains the\nfirst non-whitespace character behind the current match position.\n@param s String character set like one passed to `lpeg.S()`.\n@usage local regex = l.last_char_includes('+-*!%^&|=,([{') *\n l.delimited_range('/')\n@return pattern ldexp math.ldexp(m, e)\nReturns 'm2^e' (`e` should be an integer). len string.len(s)\nReceives a string and returns its length. The empty string `""` has\nlength 0. Embedded zeros are counted, so `"a\000bc\000"` has length 5. @@ -923,6 +924,8 @@ preload package.preload (table)\nA table to store loaders for specific modules ( print _G.print(···)\nReceives any number of arguments and prints their values to `stdout`, using\nthe `tostring` function to convert each argument to a string. `print` is not\nintended for formatted output, but only as a quick way to show a value,\nfor instance for debugging. For complete control over the output, use\n`string.format` and `io.write`. print lexer.print (pattern)\nA pattern that matches any printable character (' ' to '~'). print ui.print(...)\nPrints the given string messages to the message buffer.\nOpens a new buffer if one has not already been opened for printing messages.\n@param ... Message strings. +proc _G.proc (module)\nUserdata representing a process created by `spawn()`. +proc textadept.run.proc (process)\nThe currently running process or the most recent process run. process args.process(arg)\nProcesses command line argument table *arg*, handling switches previously\ndefined using `args.register()` and treating unrecognized arguments as\nfilenames to open.\nEmits an `ARG_NONE` event when no arguments are present.\n@param arg Argument table.\n@see register\n@see events properties _SCINTILLA.properties (table)\nMap of Scintilla property names to table values containing their "get"\nfunction IDs, "set" function IDs, return types, and wParam types.\nThe wParam type will be non-zero if the property is indexable.\nTypes are the same as in the `functions` table.\n@see functions property buffer.property (table)\nMap of key-value string pairs used by lexers. @@ -1102,6 +1105,7 @@ snippets _G.snippets (table)\nMap of snippet triggers with their snippet text, w snippets textadept.snippets (module)\nSnippets for Textadept. sort table.sort(list [, comp])\nSorts list elements in a given order, *in-place*, from `list[1]` to\n`list[#list]`. If `comp` is given, then it must be a function that receives\ntwo list elements and returns true when the first element must come before\nthe second in the final order (so that `not comp(list[i+1],list[i])` will be\ntrue after the sort). If `comp` is not given, then the standard Lua operator\n`<` is used instead.\n\nThe sort algorithm is not stable; that is, elements considered equal by the\ngiven order may have their relative positions changed by the sort. space lexer.space (pattern)\nA pattern that matches any whitespace character ('\t', '\v', '\f', '\n',\n'\r', space). +spawn _G.spawn(argv, working_dir, stdout_cb, stderr_cb, exit_cb)\nSpawns an interactive child process *argv* in a separate thread with the help\nof GLib.\n@param argv A UTF-8-encoded command line string containing the program's name\n followed by arguments to pass to it. `PATH` is searched for program names.\n@param working_dir The child's UTF-8 current working directory (cwd) or `nil`\n to inherit the parent's.\n@param stdout_cb A Lua function that accepts a string parameter for a block\n of standard output read from the child. Stdout is read asynchronously in\n 1KB or 0.5KB blocks (depending on the platform), or however much data is\n available at the time. All text is encoded in `_CHARSET`.\n@param stderr_cb A Lua function that accepts a string parameter for a block\n of standard error read from the child. Stderr is read asynchronously in 1KB\n or 0.5kB blocks (depending on the platform), or however much data is\n available at the time. All text is encoded in `_CHARSET`.\n@param exit_cb A Lua function that is called when the child process finishes.\n The child's exit status is passed.\n@usage spawn('lua buffer.filename', nil, print)\n@usage proc = spawn('lua -e "print(io.read())", nil, print)\n proc:write('foo\\n')\n@return proc\n@see _G._CHARSET\n@see _G.proc split view.split(view, vertical)\nSplits the view into top and bottom views (unless *vertical* is `true`),\nfocuses the new view, and returns both the old and new views.\nIf *vertical* is `false`, splits the view vertically into left and\nright views.\nEmits a `VIEW_NEW` event.\n@param view The view to split.\n@param vertical Optional flag indicating whether or not to split the view\n vertically. The default value is `false`, for horizontal.\n@return old view and new view.\n@see events.VIEW_NEW sqrt math.sqrt(x)\nReturns the square root of `x`. (You can also use the expression `x^0.5`\nto compute this value.) standard_dropdown ui.dialogs.standard_dropdown(options)\nPrompts the user with a drop down item selection dialog defined by dialog\noptions table *options* and with localized "Ok" and "Cancel" buttons,\nreturning the selected button's index along with the selected item's index\nor, if *options*.`string_output` is `true`, the selected button's label along\nwith the selected item's text.\nIf the dialog closed due to *options*.`exit_onchange`, returns `4` along with\neither the selected item's index or text. If the dialog timed out, returns\n`0` or `"timeout"`. If the user canceled the dialog, returns `-1` or\n`"delete"`.\n@param options Table of key-value option pairs for the drop down dialog.\n\n * `title`: The dialog's title text.\n * `text`: The dialog's main message text.\n * `items`: The list of string items to show in the drop down.\n * `no_cancel`: Do not display the "Cancel" button. The default value is\n `false`.\n * `exit_onchange`: Close the dialog after selecting a new item. The default\n value is `false`.\n * `select`: The index of the initially selected list item. The default\n value is `1`.\n * `string_output`: Return the selected button's label or the dialog's exit\n status along with the selected item's text instead of the button's index\n or the dialog's exit code along with the item's index. The default value\n is `false`.\n * `width`: The dialog's pixel width.\n * `height`: The dialog's pixel height.\n * `float`: Show the dialog on top of all desktop windows. The default value\n is `false`.\n * `timeout`: the integer number of seconds the dialog waits for the user to\n select a button before timing out. Dialogs do not time out by default.\n@return selected button or exit code, selected item @@ -1109,10 +1113,12 @@ standard_inputbox ui.dialogs.standard_inputbox(options)\nPrompts the user with a start_styling buffer.start_styling(buffer, position, style_mask, styling_mask)\nBegins styling at position *position* with styling bit-mask *styling_mask*.\n*styling_mask* specifies which style bits can be set with\n`buffer:set_styling()`.\n@param buffer A buffer.\n@param position The position in *buffer* to start styling at.\n@param styling_mask The bit mask of style bits that can be set when styling.\n@usage buffer:start_styling(0, 0xFF) starts_line lexer.starts_line(patt)\nCreates and returns a pattern that matches pattern *patt* only at the\nbeginning of a line.\n@param patt The LPeg pattern to match on the beginning of a line.\n@usage local preproc = token(l.PREPROCESSOR, #P('#') * l.starts_line('#' *\n l.nonnewline^0))\n@return pattern status coroutine.status(co)\nReturns the status of coroutine `co`, as a string: `"running"`, if\nthe coroutine is running (that is, it called `status`); `"suspended"`, if\nthe coroutine is suspended in a call to `yield`, or if it has not started\nrunning yet; `"normal"` if the coroutine is active but not running (that\nis, it has resumed another coroutine); and `"dead"` if the coroutine has\nfinished its body function, or if it has stopped with an error. +status proc.status(proc)\nReturns the status of `proc`, which is either "running" or "terminated".\n@param proc A process created by `spawn()`.\n@return "running" or "terminated" statusbar_text ui.statusbar_text (string, Write-only)\nThe text displayed in the statusbar. stderr io.stderr (file)\nStandard error. stdin io.stdin (file)\nStandard in. stdout io.stdout (file)\nStandard out. +stop textadept.run.stop()\nStops the currently running process, if any. string _G.string (module)\nLua string module. stuttered_page_down buffer.stuttered_page_down(buffer)\nMoves the caret to the bottom of the page or, if already there, down one\npage.\n@param buffer A buffer. stuttered_page_down_extend buffer.stuttered_page_down_extend(buffer)\nLike `buffer:stuttered_page_down()`, but extends the selected text to the new\nposition.\n@param buffer A buffer. @@ -1214,6 +1220,7 @@ view_eol buffer.view_eol (bool)\nDisplay end of line characters.\nThe default va view_ws buffer.view_ws (number)\nThe whitespace visibility mode.\n\n* `buffer.WS_INVISIBLE`\n Whitespace is invisible.\n* `buffer.WS_VISIBLEALWAYS`\n Display all space characters as dots and tab characters as arrows.\n* `buffer.WS_VISIBLEAFTERINDENT`\n Display only non-indentation spaces and tabs as dots and arrows.\n\nThe default value is `buffer.WS_INVISIBLE`. virtual_space_options buffer.virtual_space_options (number)\nThe virtual space mode.\n\n* `buffer.VS_NONE`\n Disable virtual space.\n* `buffer.VS_RECTANGULARSELECTION`\n Enable virtual space only for rectangular selections.\n* `buffer.VS_USERACCESSIBLE`\n Enable virtual space.\n\nWhen virtual space is enabled, the caret may move into the space past end\nof line characters.\nThe default value is `buffer.VS_NONE`. visible_from_doc_line buffer.visible_from_doc_line(buffer, line)\nReturns the displayed line number of actual line number *line*, taking hidden\nlines into account, or `-1` if *line* is outside the range of lines in the\nbuffer.\nLines can occupy more than one display line if they wrap.\n@param buffer A buffer.\n@param line The line number in *buffer* to use.\n@return number +wait proc.wait(proc)\nBlocks until `proc` finishes.\n@param proc A process created by `spawn()`. whitespace_chars buffer.whitespace_chars (string)\nThe string set of characters recognized as whitespace characters.\nSet this only after setting `buffer.word_chars`.\nThe default value is a string that contains all non-newline characters less\nthan ASCII value 33. whitespace_size buffer.whitespace_size (number)\nThe pixel size of the dots that represent space characters when whitespace\nis visible.\nThe default value is `1`. whole_word ui.find.whole_word (bool)\nMatch search text only when it is surrounded by non-word characters in\nsearches.\nThe default value is `false`. @@ -1245,6 +1252,7 @@ wrap_visual_flags buffer.wrap_visual_flags (number)\nThe wrapped line visual fla wrap_visual_flags_location buffer.wrap_visual_flags_location (number)\nThe wrapped line visual flag drawing mode.\n\n* `buffer.WRAPVISUALFLAGLOC_DEFAULT`\n Draw a visual flag near the view's right margin.\n* `buffer.WRAPVISUALFLAGLOC_END_BY_TEXT`\n Draw a visual flag near text at the end of a wrapped line.\n* `buffer.WRAPVISUALFLAGLOC_START_BY_TEXT`\n Draw a visual flag near text at the beginning of a subline.\n\nThe default value is `buffer.WRAPVISUALFLAGLOC_DEFAULT`. write file:write(···)\nWrites the value of each of its arguments to `file`. The arguments must be\nstrings or numbers.\n\nIn case of success, this function returns `file`. Otherwise it returns nil\nplus a string describing the error. write io.write(···)\nEquivalent to `io.output():write(···)`. +write proc.write(proc, input)\nWrites string `input` to the stdin of `proc`.\n@param proc A process created by `spawn()`.\n@param input Standard input for `proc`. x_offset buffer.x_offset (number)\nThe horizontal scroll pixel position.\nA value of `0` is the normal position with the first text column visible at\nthe left of the view. xdigit lexer.xdigit (pattern)\nA pattern that matches any hexadecimal digit ('0'-'9', 'A'-'F', 'a'-'f'). xor bit32.xor(...)\nReturns the bitwise "exclusive or" of its operands. diff --git a/modules/lua/init.lua b/modules/lua/init.lua index 0f68a1e1..1ba3ee02 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -35,7 +35,8 @@ M.sense.syntax.type_assignments = { ['^([%w_%.]+)%s*$'] = '%1', -- foo = textadept.adeptsense ['^(_M%.textadept%.adeptsense)%.new'] = '%1', ['require%s*%(?%s*(["\'])([%w_%.]+)%1%)?'] = '%2', - ['^io%.p?open%s*%b()%s*$'] = 'file' + ['^io%.p?open%s*%b()%s*$'] = 'file', + ['^spawn%s*%b()%s*$'] = 'proc' } M.sense.api_files = {_HOME..'/modules/lua/api'} M.sense:add_trigger('.') diff --git a/modules/lua/tags b/modules/lua/tags index 3474cd81..a6d11c12 100644 --- a/modules/lua/tags +++ b/modules/lua/tags @@ -771,6 +771,7 @@ keys _ 0;" m keys _ 0;" t keys _ 0;" t keys _ 0;" t class:textadept +kill _ 0;" f class:proc last_char_includes _ 0;" f class:lexer ldexp _ 0;" f class:math len _ 0;" f class:string @@ -950,6 +951,9 @@ preload _ 0;" F class:package print _ 0;" F class:lexer print _ 0;" f print _ 0;" f class:ui +proc _ 0;" F class:textadept.run +proc _ 0;" m +proc _ 0;" t process _ 0;" f class:args properties _ 0;" t class:_SCINTILLA property _ 0;" F class:buffer @@ -1129,6 +1133,7 @@ snippets _ 0;" t snippets _ 0;" t class:textadept sort _ 0;" f class:table space _ 0;" F class:lexer +spawn _ 0;" f split _ 0;" f class:view sqrt _ 0;" f class:math standard_dropdown _ 0;" f class:ui.dialogs @@ -1136,10 +1141,12 @@ standard_inputbox _ 0;" f class:ui.dialogs start_styling _ 0;" f class:buffer starts_line _ 0;" f class:lexer status _ 0;" f class:coroutine +status _ 0;" f class:proc statusbar_text _ 0;" F class:ui stderr _ 0;" F class:io stdin _ 0;" F class:io stdout _ 0;" F class:io +stop _ 0;" f class:textadept.run string _ 0;" m string _ 0;" t stuttered_page_down _ 0;" f class:buffer @@ -1258,6 +1265,7 @@ view_eol _ 0;" F class:buffer view_ws _ 0;" F class:buffer virtual_space_options _ 0;" F class:buffer visible_from_doc_line _ 0;" f class:buffer +wait _ 0;" f class:proc whitespace_chars _ 0;" F class:buffer whitespace_size _ 0;" F class:buffer whole_word _ 0;" F class:ui.find @@ -1289,6 +1297,7 @@ wrap_visual_flags _ 0;" F class:buffer wrap_visual_flags_location _ 0;" F class:buffer write _ 0;" f class:file write _ 0;" f class:io +write _ 0;" f class:proc x_offset _ 0;" F class:buffer xdigit _ 0;" F class:lexer xor _ 0;" f class:bit32 diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 3a0348ab..73ddbb83 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -103,6 +103,7 @@ local menubar = { SEPARATOR, {_L['_Run'], textadept.run.run}, {_L['_Compile'], textadept.run.compile}, + {_L['S_top'], textadept.run.stop}, {_L['_Next Error'], {textadept.run.goto_error, false, true}}, {_L['_Previous Error'], {textadept.run.goto_error, false, false}}, SEPARATOR, diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index d7248862..15bf3c9c 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -14,8 +14,11 @@ local M = {} -- @field MARK_ERROR (number) -- The run or compile error marker number. -- @field cwd (string, Read-only) --- The most recently executed compile or run shell command's working directory. +-- The most recently executed compile or run shell command's working +-- directory. -- It is used for going to error messages with relative file paths. +-- @field proc (process) +-- The currently running process or the most recent process run. -- @field _G.events.COMPILE_OUTPUT (string) -- Emitted when executing a language's compile shell command. -- By default, compiler output is printed to the message buffer. To override @@ -56,8 +59,6 @@ local function command(commands, compiling) commands[buffer:get_lexer()] if not command then return end if type(command) == 'function' then command = command() end - - preferred_view = view local filepath, filedir, filename = buffer.filename, '', buffer.filename if filepath:find('[/\\]') then filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$') @@ -67,20 +68,23 @@ local function command(commands, compiling) ['%(filepath)'] = filepath, ['%(filedir)'] = filedir, ['%(filename)'] = filename, ['%(filename_noext)'] = filename_noext, }):gsub('%%([dfe])', {d = filedir, f = filename, e = filename_noext}) - local current_dir = lfs.currentdir() - lfs.chdir(filedir) - local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT + + preferred_view = view local events_emit = events.emit + local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT local lexer = buffer:get_lexer() - events_emit(event, lexer, '> '..command:iconv('UTF-8', _CHARSET)) - local p = io.popen(command..' 2>&1') - for line in p:lines() do - events_emit(event, lexer, line:iconv('UTF-8', _CHARSET)) + local function emit_output(output) + events_emit(event, lexer, output:iconv('UTF-8', _CHARSET)) end - local ok, status, code = p:close() - if ok and code then events_emit(event, lexer, status..': '..code) end + + emit_output('> '..command) + ui.SILENT_PRINT = true + proc = spawn(command, filedir, emit_output, emit_output, function(status) + emit_output('> exit status: '..status) + ui.SILENT_PRINT = false + end) + M.cwd = filedir - lfs.chdir(current_dir) end -- Parses the given message for a warning or error message and returns a table @@ -169,6 +173,11 @@ function M.run() command(M.run_commands) end events.connect(events.RUN_OUTPUT, print_output) --- +-- Stops the currently running process, if any. +-- @name stop +function M.stop() if proc then proc:kill() end end + +--- -- List of warning and error string patterns that match various compile and run -- warnings and errors. -- Patterns contain filename, line number, and optional warning or error message diff --git a/src/Makefile b/src/Makefile index c4452619..563fdfe6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -33,6 +33,9 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) GTK_LIBS = $(shell PKG_CONFIG_PATH=`pwd`/$(arch)gtk/lib/pkgconfig \ pkg-config --define-variable=prefix=$(arch)gtk \ --libs gtk+-2.0) + GLIB_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/$(arch)gtk/lib/pkgconfig \ + pkg-config --define-variable=prefix=$(arch)gtk \ + --cflags glib-2.0) else plat_flag = -DCURSES CURSES_CFLAGS = -DLIBICONV_STATIC -I$(arch)curses/include @@ -62,6 +65,9 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) pkg-config --define-variable=prefix=gtkosx \ --libs gtk+-2.0 gmodule-2.0 gtk-mac-integration) \ -framework Cocoa + GLIB_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \ + pkg-config --define-variable=prefix=gtkosx \ + --cflags glib-2.0) else plat_flag = -DCURSES -D_XOPEN_SOURCE_EXTENDED CURSES_LIBS = -lncurses @@ -98,6 +104,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) endif GTK_CFLAGS = $(shell pkg-config --cflags gtk+-$(gtk_version) gmodule-2.0) GTK_LIBS = $(shell pkg-config --libs gtk+-$(gtk_version) gmodule-2.0) + GLIB_CFLAGS = $(shell pkg-config --cflags glib-2.0) install_targets = ../textadept ../textadeptjit else plat_flag = -DCURSES -D_XOPEN_SOURCE_EXTENDED @@ -175,16 +182,11 @@ lua_objs = lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o \ lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o \ lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ lmathlib.o loadlib.o loslib.o ltablib.o lstrlib.o -lua_lib_objs = lpeg.o lfs.o +lua_lib_objs = lpeg.o lfs.o lspawn.o #lua_lib_objs = lpcap.o lpcode.o lpprint.o lptree.o lpvm.o lfs.o -luajit_lib_objs = lpegjit.o lfsjit.o +luajit_lib_objs = lpegjit.o lfsjit.o lspawnjit.o #luajit_lib_objs = lpcapjit.o lpcodejit.o lpprintjit.o lptreejit.o lpvmjit.o \ # lfsjit.o -ifeq (win, $(findstring win, $(MAKECMDGOALS))) - # Compile in winapi module for Windows. - lua_lib_objs += wutils.o winapi.o - luajit_lib_objs += wutilsjit.o winapijit.o -endif termkey_objs = termkey.o driver-ti.o driver-csi.o windowman_objs = windowman.o cdk_objs = binding.o buttonbox.o button.o cdk.o cdk_display.o cdk_objs.o \ @@ -248,9 +250,9 @@ textadeptjit-curses.o: textadept.c $(lua_objs): %.o: lua/src/%.c $(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -Ilua/src $< -o $@ $(lua_lib_objs): %.o: lua/src/lib/%.c - $(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -Ilua/src $< -o $@ + $(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -Ilua/src $(GLIB_CFLAGS) $< -o $@ $(luajit_lib_objs): %jit.o: lua/src/lib/%.c - $(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -Iluajit/src $< -o $@ + $(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -Iluajit/src $(GLIB_CFLAGS) $< -o $@ luajit/src/libluajit.a: ; $(MAKE) -C luajit CC="$(CC) $(CFLAGS)" luajit/src/lua51.dll: $(MAKE) -C luajit HOST_CC="$(CC) -m32" CROSS=$(CROSS) TARGET_SYS=Windows @@ -431,7 +433,7 @@ scintillua_zip = scintillua.zip lua_tgz = lua-5.2.3.tar.gz lpeg_tgz = lpeg-0.10.2.tar.gz lfs_zip = d71c63cdb776f7d25313f8fcd14f07512ba1f83e.zip -lwinapi_zip = 23dd43141d04d010a9986cca9e5ecb9e598a2899.zip +lspawn_zip = lspawn.zip luajit_tgz = LuaJIT-2.0.3.tar.gz libluajit_tgz = libluajit_2.0.3.x86_64.tgz gtdialog_zip = gtdialog.zip @@ -463,19 +465,18 @@ $(lua_tgz): ; wget "http://www.lua.org/ftp/$@" $(lpeg_tgz): ; wget "http://www.inf.puc-rio.br/~roberto/lpeg/$@" $(lfs_zip): wget "https://github.com/keplerproject/luafilesystem/archive/$@" -O $@ -$(lwinapi_zip): ; wget "https://github.com/stevedonovan/winapi/archive/$@" -O $@ +$(lspawn_zip): ; wget "http://foicica.com/hg/lspawn/archive/tip.zip" -O $@ lua: lua.patch | $(lua_tgz) mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@ patch -d $@ -N -p1 < $< -lualibs: lua/src/lib/lpeg lua/src/lib/lfs lua/src/lib/winapi +lualibs: lua/src/lib/lpeg lua/src/lib/lfs lua/src/lib/lspawn lua/src/lib/lpeg: | $(lpeg_tgz) mkdir -p $@ && tar xzf $| -C $@ && mv $@/*/*.c $@/*/*.h $(dir $@) lua/src/lib/lfs: lfs.patch | $(lfs_zip) mkdir -p $@ && unzip -d $@ $| && mv $@/*/src/*.c $@/*/src/*.h $(dir $@) patch -d $(dir $@) -N -p1 < $< -lua/src/lib/winapi: winapi.patch | $(lwinapi_zip) - mkdir -p $@ && unzip -d $@ $| && mv $@/*/*.c $@/*/*.h $(dir $@) - patch -d $(dir $@) -N --binary -p1 < $< +lua/src/lib/lspawn: | $(lspawn_zip) + mkdir -p $@ && unzip -d $@ $| && mv $@/*/*.c $(dir $@) $(luajit_tgz): ; wget "http://luajit.org/download/$@" luajit: luajit.patch | $(luajit_tgz) mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@ diff --git a/src/textadept.c b/src/textadept.c index 9b5a789a..d3d1dd67 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -13,9 +13,7 @@ #elif _WIN32 #include <windows.h> #define main main_ -#elif (__APPLE__ && !CURSES) -#include <gtkmacintegration/gtkosxapplication.h> -#elif (__APPLE__ && CURSES) +#elif __APPLE__ #include <mach-o/dyld.h> #elif (__FreeBSD__ || __NetBSD__ || __OpenBSD__) #define u_int unsigned int // 'u_int' undefined when _POSIX_SOURCE is defined @@ -25,6 +23,9 @@ #if GTK #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> +#if __APPLE__ +#include <gtkmacintegration/gtkosxapplication.h> +#endif #elif CURSES #if !_WIN32 #include <signal.h> @@ -92,7 +93,6 @@ typedef GtkWidget Scintilla; #define LUA_OK 0 #define lua_rawlen lua_objlen #define LUA_OPEQ 0 -#define lua_compare(l, a, b, _) lua_equal(l, a, b) #define lL_openlib(l, n, f) \ (lua_pushcfunction(l, f), lua_pushstring(l, n), lua_call(l, 1, 0)) #else @@ -210,9 +210,7 @@ static void new_buffer(sptr_t); static Scintilla *new_view(sptr_t); static int lL_init(lua_State *, int, char **, int); LUALIB_API int luaopen_lpeg(lua_State *), luaopen_lfs(lua_State *); -#if _WIN32 -LUALIB_API int luaopen_winapi(lua_State *); -#endif +LUALIB_API int luaopen_spawn(lua_State *); /** * Emits an event. @@ -1061,7 +1059,7 @@ static int lui__newindex(lua_State *L) { static sptr_t l_globaldoccompare(lua_State *L, int index) { luaL_getmetatable(L, "ta_buffer"); lua_getmetatable(L, (index > 0) ? index : index - 1); - luaL_argcheck(L, lua_compare(L, -1, -2, LUA_OPEQ), index, "Buffer expected"); + luaL_argcheck(L, lua_rawequal(L, -1, -2), index, "Buffer expected"); lua_getfield(L, (index > 0) ? index : index - 2, "doc_pointer"); sptr_t doc = (sptr_t)lua_touserdata(L, -1); lua_pop(L, 3); // doc_pointer, metatable, metatable @@ -1305,7 +1303,7 @@ static int lbuf_property(lua_State *L) { int newindex = (lua_gettop(L) == 3); luaL_getmetatable(L, "ta_buffer"); lua_getmetatable(L, 1); // metatable can be either ta_buffer or ta_bufferp - int is_buffer = lua_compare(L, -1, -2, LUA_OPEQ); + int is_buffer = lua_rawequal(L, -1, -2); lua_pop(L, 2); // metatable, metatable // If the key is a Scintilla function, return a callable closure. @@ -1605,6 +1603,7 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { luaL_openlibs(L); lL_openlib(L, "lpeg", luaopen_lpeg); lL_openlib(L, "lfs", luaopen_lfs); + lL_openlib(L, "spawn", luaopen_spawn); lua_newtable(L); lua_newtable(L); @@ -1644,7 +1643,6 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { lua_pushstring(L, textadept_home), lua_setglobal(L, "_HOME"); #if _WIN32 lua_pushboolean(L, 1), lua_setglobal(L, "WIN32"); - lL_openlib(L, "winapi", luaopen_winapi); #elif (__APPLE__ && !CURSES) lua_pushboolean(L, 1), lua_setglobal(L, "OSX"); #endif @@ -1970,7 +1968,7 @@ static int s_buttonpress(GtkWidget*_, GdkEventButton *event, void*__) { static Scintilla *lL_checkview(lua_State *L, int arg) { luaL_getmetatable(L, "ta_view"); lua_getmetatable(L, arg); - luaL_argcheck(L, lua_compare(L, -1, -2, LUA_OPEQ), arg, "View expected"); + luaL_argcheck(L, lua_rawequal(L, -1, -2), arg, "View expected"); lua_getfield(L, (arg > 0) ? arg : arg - 2, "widget_pointer"); Scintilla *view = (Scintilla *)lua_touserdata(L, -1); lua_pop(L, 3); // widget_pointer, metatable, metatable @@ -2398,19 +2396,16 @@ int main(int argc, char **argv) { textadept_home = malloc(FILENAME_MAX); GetModuleFileName(0, textadept_home, FILENAME_MAX); if ((last_slash = strrchr(textadept_home, '\\'))) *last_slash = '\0'; -#elif (__APPLE__ && !CURSES) - osxapp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL); - char *path = gtkosx_application_get_resource_path(); - textadept_home = g_filename_from_utf8((const char *)path, -1, NULL, NULL, - NULL); - g_free(path); -#elif (__APPLE__ && CURSES) +#elif __APPLE__ char *path = malloc(FILENAME_MAX), *p = NULL; uint32_t size = FILENAME_MAX; _NSGetExecutablePath(path, &size); textadept_home = realpath(path, NULL); p = strstr(textadept_home, "MacOS"), strcpy(p, "Resources\0"); free(path); +#if !CURSES + osxapp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL); +#endif #elif (__FreeBSD__ || __NetBSD__ || __OpenBSD__) textadept_home = malloc(FILENAME_MAX); int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; diff --git a/src/winapi.patch b/src/winapi.patch deleted file mode 100644 index 1303a538..00000000 --- a/src/winapi.patch +++ /dev/null @@ -1,456 +0,0 @@ ---- a/winapi.c 2012-06-28 04:50:56.000000000 -0400 -+++ b/winapi.c 2013-12-13 09:14:05.006746200 -0500 -@@ -20,7 +20,7 @@ - #ifdef __GNUC__
- #include <winable.h> /* GNU GCC specific */
- #endif
--#include "Winnetwk.h"
-+#include "winnetwk.h"
- #include <psapi.h>
-
-
-@@ -65,6 +65,7 @@ - return wstring_buff(text,wbuff,sizeof(wbuff));
- }
-
-+#if 0
- /// Text encoding.
- // @section encoding
-
-@@ -768,7 +769,9 @@ - return push_bool(L, MoveFile(src,dest));
- }
-
-+#endif
- #define wconv(name) (name ? wstring_buff(name,w##name,sizeof(w##name)) : NULL)
-+#if 0
-
- /// execute a shell command.
- // @param verb the action (e.g. 'open' or 'edit') can be nil.
-@@ -891,6 +894,7 @@ - }
- return push_new_File(L,hSerial,hSerial);
- }
-+#endif
-
- static int push_wait_result(lua_State *L, DWORD res) {
- if (res == WAIT_OBJECT_0) {
-@@ -918,6 +922,7 @@ - return push_wait_result(L,wait_single(h,timeout));
- }
-
-+#if 0
- static int push_wait_async(lua_State *L, HANDLE h, int timeout, int callback);
-
- /// The Event class.
-@@ -1128,6 +1133,7 @@ - #line 825 "winapi.l.c"
- return push_new_Mutex(L,CreateMutex(NULL,FALSE,*name==0 ? NULL : name));
- }
-+#endif
-
- /// A class representing a Windows process.
- // this example was [helpful](http://msdn.microsoft.com/en-us/library/ms682623%28VS.85%29.aspx)
-@@ -1179,6 +1185,7 @@ - }
- }
-
-+#if 0
- /// get the name of the process.
- // @param full true if you want the full path; otherwise returns the base name.
- // @function get_process_name
-@@ -1210,6 +1217,7 @@ - lua_pushnumber(L, this->pid);
- return 1;
- }
-+#endif
-
- /// kill the process.
- // @{test-spawn.lua} kills a launched process after a certain amount of output.
-@@ -1221,6 +1229,7 @@ - return 0;
- }
-
-+#if 0
- /// get the working size of the process.
- // @return minimum working set size
- // @return maximum working set size.
-@@ -1280,6 +1289,7 @@ - lua_pushnumber(L,fileTimeToMillisec(&kernel));
- return 2;
- }
-+#endif
-
- /// wait for this process to finish.
- // @param timeout optional timeout in millisec; defaults to waiting indefinitely.
-@@ -1293,6 +1303,7 @@ - return push_wait(L,this->hProcess, TIMEOUT(timeout));
- }
-
-+#if 0
- /// run callback when this process is finished.
- // @param callback the callback
- // @param timeout optional timeout in millisec; defaults to waiting indefinitely.
-@@ -1320,6 +1331,7 @@ - #line 968 "winapi.l.c"
- return push_wait_result(L, WaitForInputIdle(this->hProcess, TIMEOUT(timeout)));
- }
-+#endif
-
- /// exit code of this process.
- // (Only makes sense if the process has in fact finished.)
-@@ -1354,15 +1366,21 @@ - #line 995 "winapi.l.c"
-
- static const struct luaL_Reg Process_methods [] = {
-+#if 0
- {"get_process_name",l_Process_get_process_name},
- {"get_pid",l_Process_get_pid},
-+#endif
- {"kill",l_Process_kill},
-+#if 0
- {"get_working_size",l_Process_get_working_size},
- {"get_start_time",l_Process_get_start_time},
- {"get_run_times",l_Process_get_run_times},
-+#endif
- {"wait",l_Process_wait},
-+#if 0
- {"wait_async",l_Process_wait_async},
- {"wait_for_input_idle",l_Process_wait_for_input_idle},
-+#endif
- {"get_exit_code",l_Process_get_exit_code},
- {"close",l_Process_close},
- {"__gc",l_Process___gc},
-@@ -1388,6 +1406,7 @@ - // @{readme.md.Creating_and_working_with_Processes}
- // @section Processes
-
-+#if 0
- /// create a process object from the id.
- // @param pid the process id
- // @return @{Process}
-@@ -1477,6 +1496,7 @@ - return 1;
- }
- }
-+#endif
-
- // These functions are all run in background threads, and a little bit of poor man's
- // OOP helps here. This is the base struct for describing threads with callbacks,
-@@ -1493,6 +1513,7 @@ - callback_data_
- } LuaCallback, *PLuaCallback;
-
-+#if 0
- LuaCallback *lcb_callback(void *lcb, lua_State *L, int idx) {
- LuaCallback *data;
- if (lcb == NULL) {
-@@ -1510,6 +1531,7 @@ - LuaCallback *lcb = (LuaCallback*)data;
- return call_lua(lcb->L,lcb->callback,idx,text,persist);
- }
-+#endif
-
- void lcb_allocate_buffer(void *data, int size) {
- LuaCallback *lcb = (LuaCallback*)data;
-@@ -1535,6 +1557,7 @@ - #define lcb_bufsz(data) ((LuaCallback *)data)->bufsz
- #define lcb_handle(data) ((LuaCallback *)data)->handle
-
-+#if 0
- /// Thread object. This is returned by the @{File:read_async} method and the @{make_timer},
- // @{make_pipe_server} and @{watch_for_file_changes} functions. Useful to kill a thread
- // and free associated resources.
-@@ -1707,6 +1730,7 @@ - lcb->bufsz = timeout;
- return lcb_new_thread((TCB)handle_waiter,lcb);
- }
-+#endif
-
- /// this represents a raw Windows file handle.
- // The write handle may be distinct from the read handle.
-@@ -1785,6 +1809,7 @@ - }
- }
-
-+#if 0
- static void file_reader (File *this) { // background reader thread
- int n;
- do {
-@@ -1806,6 +1831,7 @@ - this->callback = make_ref(L,callback);
- return lcb_new_thread((TCB)&file_reader,this);
- }
-+#endif
-
- static int l_File_close(lua_State *L) {
- File *this = File_arg(L,1);
-@@ -1827,7 +1853,9 @@ - static const struct luaL_Reg File_methods [] = {
- {"write",l_File_write},
- {"read",l_File_read},
-+#if 0
- {"read_async",l_File_read_async},
-+#endif
- {"close",l_File_close},
- {"__gc",l_File___gc},
- {NULL, NULL} /* sentinel */
-@@ -1853,6 +1881,7 @@ - /// Launching processes.
- // @section Launch
-
-+#if 0
- /// set an environment variable for any child processes.
- // @{setenv.lua} shows how this also affects processes
- // launched with @{os.execute}
-@@ -1869,6 +1898,7 @@ - WCHAR wname[256],wvalue[MAX_WPATH];
- return push_bool(L, SetEnvironmentVariableW(wconv(name),wconv(value)));
- }
-+#endif
-
- /// Spawn a process.
- // @param program the command-line (program + parameters)
-@@ -1938,6 +1968,7 @@ - }
- }
-
-+#if 0
- /// execute a system command.
- // This is like `os.execute()`, except that it works without ugly
- // console flashing in Windows GUI applications. It additionally
-@@ -2564,11 +2595,28 @@ - return push_error(L);
- }
- }
-+#endif
-
- #line 2005 "winapi.l.c"
- static const char *lua_code_block = ""\
- "function winapi.execute(cmd,unicode)\n"\
- " local comspec = os.getenv('COMSPEC')\n"\
-+ " cmd = comspec ..' /c '..cmd\n"\
-+ " local P,f = winapi.spawn_process(cmd)\n"\
-+ " if not P then return nil,f end\n"\
-+ " local txt = f:read()\n"\
-+ " local out = {}\n"\
-+ " while txt do\n"\
-+ " table.insert(out,txt)\n"\
-+ " txt = f:read()\n"\
-+ " end\n"\
-+ " return P:wait():get_exit_code(),table.concat(out,'')\n"\
-+ "end\n"\
-+;
-+#if 0
-+static const char *lua_code_block = ""\
-+ "function winapi.execute(cmd,unicode)\n"\
-+ " local comspec = os.getenv('COMSPEC')\n"\
- " if unicode ~= 'unicode' then\n"\
- " cmd = comspec ..' /c '..cmd\n"\
- " local P,f = winapi.spawn_process(cmd)\n"\
-@@ -2638,11 +2686,13 @@ - "end\n"\
- "function winapi.dirs(mask,subdirs) return winapi.files(mask,subdirs,'D') end\n"\
- ;
-+#endif
- static void load_lua_code (lua_State *L) {
- luaL_dostring(L,lua_code_block);
- }
-
-
-+#if 0
- #line 2010 "winapi.l.c"
- int init_mutex(lua_State *L) {
- setup_mutex();
-@@ -2769,9 +2819,11 @@ - lua_pushinteger(L,REG_MULTI_SZ); lua_setfield(L,-2,"REG_MULTI_SZ");
- lua_pushinteger(L,REG_EXPAND_SZ); lua_setfield(L,-2,"REG_EXPAND_SZ");
- }
-+#endif
-
- #line 2126 "winapi.l.c"
- static const luaL_Reg winapi_funs[] = {
-+#if 0
- {"set_encoding",l_set_encoding},
- {"get_encoding",l_get_encoding},
- {"encode",l_encode},
-@@ -2804,7 +2856,9 @@ - {"get_processes",l_get_processes},
- {"wait_for_processes",l_wait_for_processes},
- {"setenv",l_setenv},
-+#endif
- {"spawn_process",l_spawn_process},
-+#if 0
- {"thread",l_thread},
- {"make_timer",l_make_timer},
- {"open_pipe",l_open_pipe},
-@@ -2817,6 +2871,7 @@ - {"watch_for_file_changes",l_watch_for_file_changes},
- {"open_reg_key",l_open_reg_key},
- {"create_reg_key",l_create_reg_key},
-+#endif
- {NULL,NULL}
- };
-
-@@ -2829,16 +2884,24 @@ - #else
- luaL_register(L,"winapi",winapi_funs);
- #endif
-+#if 0
- Window_register(L);
- Event_register(L);
- Mutex_register(L);
-+#endif
- Process_register(L);
-+#if 0
- Thread_register(L);
-+#endif
- File_register(L);
-+#if 0
- Regkey_register(L);
-+#endif
- load_lua_code(L);
-+#if 0
- init_mutex(L);
- set_winapi_constants(L);
-+#endif
- return 1;
- }
-
---- a/wutils.h 2012-06-28 04:50:56.000000000 -0400 -+++ b/wutils.h 2013-11-19 22:59:15.224130460 -0500 -@@ -4,12 +4,17 @@ - - extern int mutex_locked; - -+#if 0 - Ref make_ref(lua_State *L, int idx); -+#endif - void release_ref(lua_State *L, Ref ref); -+#if 0 - int push_ref(lua_State *L, Ref ref); -+#endif - const char *last_error(int err); - int push_error_msg(lua_State *L, LPCSTR msg) ; - int push_error(lua_State *L); -+#if 0 - int push_error_code(lua_State *L, int err); - int push_ok(lua_State *L); - int push_bool(lua_State *L, int bval); -@@ -17,15 +22,19 @@ - BOOL call_lua_direct(lua_State *L, Ref ref, int idx, LPCSTR text, int discard); - void make_message_window(); - BOOL call_lua(lua_State *L, Ref ref, int idx, LPCSTR text, int discard); -+#endif - void lock_mutex(); - void release_mutex(); -+#if 0 - void setup_mutex(); - - // encoding and converting text - void set_encoding(int e); - int get_encoding(); -+#endif - - LPWSTR wstring_buff(LPCSTR text, LPWSTR wbuf, int bufsz); -+#if 0 - int push_wstring_l(lua_State *L, LPCWSTR us, int len); - int push_wstring(lua_State *L, LPCWSTR us); - -@@ -33,5 +42,6 @@ - - int mb_const (LPCSTR name); - LPCSTR mb_result (int res); -+#endif - - #endif ---- a/wutils.c 2012-06-28 04:50:56.000000000 -0400 -+++ b/wutils.c 2013-11-19 22:59:15.224130460 -0500 -@@ -12,6 +12,7 @@ - - typedef int Ref; - -+#if 0 - /// make a reference to a Lua object. - // @param L the state - // @param idx the index of the value on the stack. -@@ -21,6 +22,7 @@ - lua_pushvalue(L,idx); - return luaL_ref(L,LUA_REGISTRYINDEX); - } -+#endif - - /// release a reference to a Lua value. - // @param L the state -@@ -30,6 +32,7 @@ - luaL_unref(L,LUA_REGISTRYINDEX,ref); - } - -+#if 0 - /// push a referenced value on the stack. - // @param L the state - // @param ref the reference -@@ -39,6 +42,7 @@ - lua_rawgeti(L,LUA_REGISTRYINDEX,ref); - return 1; - } -+#endif - - const char *last_error(int err) { - static char errbuff[256]; -@@ -75,6 +79,7 @@ - return push_error_msg(L,last_error(0)); - } - -+#if 0 - /// push a particular Windows error. - // @param L the state - // @param err the error code -@@ -192,6 +197,7 @@ - SetWindowLongPtr(hMessageWin, GWLP_USERDATA, subclassedProc); - } - } -+#endif - - static HANDLE hLuaMutex = NULL, hMutex = NULL; - int mutex_locked = 0; -@@ -210,6 +216,7 @@ - ReleaseMutex(hMutex); - } - -+#if 0 - // this is a useful function to call a Lua function within an exclusive - // mutex lock. There are two parameters: - // -@@ -255,7 +262,9 @@ - return res; - } - -+#endif - static int current_encoding = CP_ACP; -+#if 0 - - /// set the encoding. - // Will be one of `CP_ACP` or `CP_UTF8` -@@ -271,6 +280,7 @@ - int get_encoding() { - return current_encoding; - } -+#endif - - /// convert text to UTF-16 depending on encoding. - // @param text the input multi-byte text -@@ -290,6 +300,7 @@ - } - } - -+#if 0 - /// push a wide string on the Lua stack with given size. - // This converts to the current encoding first. - // @param L the State -@@ -389,4 +400,5 @@ - default: return "?"; - } - } -+#endif - |