Namespaced aliases, virtual classes and added missing returns.

This commit is contained in:
jgmdev 2021-06-30 03:02:01 -04:00
parent 18eee34aa9
commit 900e9d1422
4 changed files with 144 additions and 71 deletions

View File

@ -29,7 +29,13 @@ process.ERROR_TIMEDOUT = -3
---its value is platform dependent, so the value declared on this
---interface does not represents the real one.
---@type integer
process.ERROR_INVALID = -4
process.ERROR_INVAL = -4
---Error triggered when no memory is available to allocate the process,
---its value is platform dependent, so the value declared on this
---interface does not represents the real one.
---@type integer
process.ERROR_NOMEM = -5
---Used for the process:close_stream() method to close stdin.
---@type integer
@ -51,111 +57,174 @@ process.WAIT_INFINITE = -1
---@type integer
process.WAIT_DEADLINE = -2
---Used for the process.options stdin, stdout and stderr fields.
---@type integer
process.REDIRECT_DEFAULT = 0
---Used for the process.options stdin, stdout and stderr fields.
---@type integer
process.REDIRECT_PIPE = 1
---Used for the process.options stdin, stdout and stderr fields.
---@type integer
process.REDIRECT_PARENT = 2
---Used for the process.options stdin, stdout and stderr fields.
---@type integer
process.REDIRECT_DISCARD = 3
---Used for the process.options stdin, stdout and stderr fields.
---@type integer
process.REDIRECT_STDOUT = 4
---@alias process.errortype
---|>'process.ERROR_PIPE'
---| 'process.ERROR_WOULDBLOCK'
---| 'process.ERROR_TIMEDOUT'
---| 'process.ERROR_INVAL'
---| 'process.ERROR_NOMEM'
---@alias process.streamtype
---|>'process.STREAM_STDIN'
---| 'process.STREAM_STDOUT'
---| 'process.STREAM_STDERR'
---@alias process.waittype
---|>'process.WAIT_INFINITE'
---| 'process.WAIT_DEADLINE'
---@alias process.redirecttype
---|>'process.REDIRECT_DEFAULT'
---| 'process.REDIRECT_PIPE'
---| 'process.REDIRECT_PARENT'
---| 'process.REDIRECT_DISCARD'
---| 'process.REDIRECT_STDOUT'
---
---Create a new process object
--- Options that can be passed to process.start()
---@class process.options
---@field public timeout number
---@field public cwd string
---@field public stdin process.redirecttype
---@field public stdout process.redirecttype
---@field public stderr process.redirecttype
---@field public env table<string, string>
process.options = {}
---
---@return process
function process.new() end
---Create and start a new process
---
---@param command_and_params table First index is the command to execute
---and subsequente elements are parameters for the command.
---@param options process.options
---
---@return process | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:start(command_and_params, options) end
---
---Translates an error code into a useful text message
---
---@param code integer
---
---@return string
---@return string | nil
function process.strerror(code) end
---
---Start a process
---
---@param command_and_params table First index is the command to execute
---and subsequente elements are parameters for the command.
---@param working_directory? string Path where the command will be launched.
---@param deadline? integer Maximum time in milliseconds the
---process is allowed to run on a process:wait(process.WAIT_DEADLINE) call.
---
---@return integer|boolean status Negative integer error code if could
---not start or true on success
function process:start(command_and_params, working_directory, deadline) end
---
---Get the process id.
---
---@return integer id Process id or 0 if not running.
function process:pid() end
---
---Read from the given stream type, if the process fails with a ERROR_PIPE it is
---automatically destroyed returning nil along error message and code.
---
---@param stream process.streamtype
---@param len? integer Amount of bytes to read, defaults to 2048.
---
---@return string | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:read(stream, len) end
---
---Read from stdout, if the process fails with a ERROR_PIPE it is
---automatically destroyed, so checking process status with the
---process:running() method would be advised.
---automatically destroyed returning nil along error message and code.
---
---@param len? integer Amount of bytes to read.
---@param tries? integer Retry reading the given amount of times
---if nothing was read.
---@param len? integer Amount of bytes to read, defaults to 2048.
---
---@return integer|nil bytes Amount of bytes read or nil if nothing was read.
function process:read(len, tries) end
---@return string | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:read_stdout(len) end
---
---Read from stderr, if the process fails with a ERROR_PIPE it is
---automatically destroyed, so checking process status with the
---process:running() method would be advised.
---automatically destroyed returning nil along error message and code.
---
---@param len? integer Amount of bytes to read.
---@param tries? integer Retry reading the given amount of times
---if nothing was read.
---@param len? integer Amount of bytes to read, defaults to 2048.
---
---@return integer|nil bytes Amount of bytes read or nil if nothing was read.
function process:read_errors(len, tries) end
---@return string | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:read_stderr(len) end
---
---Write to the stdin, if the process fails with a ERROR_PIPE it is
---automatically destroyed, so checking process status with the
---process:running() method would be advised.
---automatically destroyed returning nil along error message and code.
---
---@param data string
---
---@return integer bytes The amount of bytes written or negative integer
---error code: process.ERROR_PIPE, process.ERROR_WOULDBLOCK
---@return integer | nil bytes The amount of bytes written or nil if error
---@return string errmsg
---@return process.errortype | integer errcode
function process:write(data) end
---
---Allows you to close a stream pipe that you will not be using.
---
---@param stream integer Could be one of the following:
---process.STREAM_STDIN, process.STREAM_STDOUT, process.STREAM_STDERR
---@param stream process.streamtype
---
---@return integer status Negative error code process.ERROR_INVALID if
---process is not running or stream is already closed.
---@return integer | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:close_stream(stream) end
---
---Wait the specified amount of time for the process to exit.
---
---@param timeout integer Time to wait in milliseconds, if 0, the function
---will only check if process is running without waiting, also the timeout
---can be set to:
--- * process.WAIT_INFINITE - will wait until the process ends
--- * process.WAIT_DEADLINE - will wait until the deadline declared on start()
---@param timeout integer | process.waittype Time to wait in milliseconds,
---if 0, the function will only check if process is running without waiting.
---
---@return integer exit_status The process exit status or negative integer
---error code like process.ERROR_TIMEDOUT
---@return integer | nil exit_status The process exit status or nil on error
---@return string errmsg
---@return process.errortype | integer errcode
function process:wait(timeout) end
---
---Sends SIGTERM to the process
---
---@return boolean|integer status Returns true on success or a
---negative integer error code like process.ERROR_INVALID
---@return boolean | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:terminate() end
---
---Sends SIGKILL to the process
---
---@return boolean|integer status Returns true on success or a
---negative integer error code like process.ERROR_INVALID
---@return boolean | nil
---@return string errmsg
---@return process.errortype | integer errcode
function process:kill() end
---
---Get the exit code of the process or nil if still running.
---
---@return number | nil
function process:returncode() end
---
---Check if the process is running
---

View File

@ -30,7 +30,7 @@ regex.NOTEMPTY = 0x00000004
---@type integer
regex.NOTEMPTY_ATSTART = 0x00000008
---@alias RegexModifiers
---@alias regex.modifiers
---|>'"i"' # Case insesitive matching
---| '"m"' # Multiline matching
---| '"s"' # Match all characters with dot (.) metacharacter even new lines
@ -39,7 +39,7 @@ regex.NOTEMPTY_ATSTART = 0x00000008
---Compiles a regular expression pattern that can be used to search in strings.
---
---@param pattern string
---@param options? RegexModifiers A string of one or more pattern modifiers.
---@param options? regex.modifiers A string of one or more pattern modifiers.
---
---@return regex|string regex Ready to use regular expression object or error
---message if compiling the pattern failed.

View File

@ -7,19 +7,19 @@ renderer = {}
---
---Represents a color used by the rendering functions.
---@class RendererColor
---@class renderer.color
---@field public r number Red
---@field public g number Green
---@field public b number Blue
---@field public a number Alpha
RendererColor = {}
renderer.color = {}
---
---Represent options that affect a font's rendering.
---@class RendererFontOptions
---@class renderer.fontoptions
---@field public antialiasing "'grayscale'" | "'subpixel'"
---@field public hinting "'slight'" | "'none'" | '"full"'
RendererFontOptions = {}
renderer.fontoptions = {}
---
---@class renderer.font
@ -30,7 +30,7 @@ renderer.font = {}
---
---@param path string
---@param size number
---@param options RendererFontOptions
---@param options renderer.fontoptions
---
---@return renderer.font
function renderer.font.load(path, size, options) end
@ -149,7 +149,7 @@ function renderer.set_clip_rect(x, y, width, height) end
---@param y number
---@param width number
---@param height number
---@param color RendererColor
---@param color renderer.color
function renderer.draw_rect(x, y, width, height, color) end
---
@ -159,9 +159,11 @@ function renderer.draw_rect(x, y, width, height, color) end
---@param text string
---@param x number
---@param y number
---@param color RendererColor
---@param color renderer.color
---@param replace renderer.replacements
---@param color_replace RendererColor
---@param color_replace renderer.color
---
---@return number x_subpixel
function renderer.draw_text(font, text, x, y, color, replace, color_replace) end
---
@ -171,7 +173,9 @@ function renderer.draw_text(font, text, x, y, color, replace, color_replace) end
---@param text string
---@param x number
---@param y number
---@param color RendererColor
---@param color renderer.color
---@param replace renderer.replacements
---@param color_replace RendererColor
---@param color_replace renderer.color
---
---@return number x_subpixel
function renderer.draw_text_subpixel(font, text, x, y, color, replace, color_replace) end

View File

@ -5,16 +5,16 @@
---@class system
system = {}
---@alias FileInfoType
---@alias system.fileinfotype
---|>'"file"' # It is a file.
---| '"dir"' # It is a directory.
---
---@class FileInfo
---@class system.fileinfo
---@field public modified number A timestamp in seconds.
---@field public size number Size in bytes.
---@field public type FileInfoType Type of file
FileInfo = {}
---@field public type system.fileinfotype Type of file
system.fileinfo = {}
---
---Core function used to retrieve the current event been triggered by SDL.
@ -73,7 +73,7 @@ function system.set_cursor(type) end
---@param title string
function system.set_window_title(title) end
---@alias SystemWindowMode
---@alias system.windowmode
---|>'"normal"'
---| '"minimized"'
---| '"maximized"'
@ -82,13 +82,13 @@ function system.set_window_title(title) end
---
---Change the window mode.
---
---@param mode SystemWindowMode
---@param mode system.windowmode
function system.set_window_mode(mode) end
---
---Retrieve the current window mode.
---
---@return SystemWindowMode mode
---@return system.windowmode mode
function system.get_window_mode() end
---
@ -176,7 +176,7 @@ function system.absolute_path(path) end
---
---@param path string Can be a file or a directory path
---
---@return FileInfo|nil info Path details or nil if empty or error.
---@return system.fileinfo|nil info Path details or nil if empty or error.
---@return string? message Error message in case of error.
function system.get_file_info(path) end