Skip to content

Instantly share code, notes, and snippets.

@StevenWarren
Created June 28, 2020 19:00
Show Gist options
  • Save StevenWarren/0e8c57a33d4adedb66de6c55fa025d2e to your computer and use it in GitHub Desktop.
Save StevenWarren/0e8c57a33d4adedb66de6c55fa025d2e to your computer and use it in GitHub Desktop.
VSCode snippets for LUA and Solar2d
{
"Spec Describe": {
"prefix": "describe",
"body": [
"describe('$1', function() $0 end)"
],
"description": "Busted spec descibe statement"
},
"Spec It": {
"prefix": "it",
"body": [
"it('$1', function() $0 end)"
],
"description": "Busted spec it statement"
},
"Bindable Model": {
"prefix": "modelBindable",
"body": [
"local model = {}",
"",
"model.new = function(options)",
" local instance = {}",
" local _bindings = {}",
" local data = {}",
"",
" local options = options or {}",
"",
" -- Initialize underlying values",
" -- data.credits = options.credits or 0",
"",
" local _data = data",
" data = {}",
"",
" local _MT = {",
" __index = function(t, k)",
" return _data[k]",
" end,",
" __newindex = function(t, k, v)",
" -- changes to the data is updated in the textfield; other UI elements can be applied according to type",
" if _bindings[tostring(k)] and type(_bindings[tostring(k)]['set_' .. tostring(k)]) == 'function' then",
" _bindings[tostring(k)]['set_' .. tostring(k)](v)",
" end",
" -- update the original data",
" _data[k] = v",
" end",
" }",
" setmetatable(data, _MT)",
"",
" -- getters",
" ",
"",
" -- setters",
" ",
"",
" -- binder",
" instance.bind = function(ctrl, val)",
" _bindings[val] = ctrl",
" end",
"",
" -- methods",
" ",
"",
" instance.tostring = function()",
" local dump = {",
" Private = _data,",
" Public = instance,",
" }",
" print(dump)",
" end",
"",
" return instance",
"end",
"",
"return model"
],
"description": "Bindable model based on https://swfoo.com/2016/10/08/ui-data-binding-for-corona-sdk/"
},
"Getter": {
"prefix": "getter",
"body": [
"instance.get_$0 = function() return data.$0 end"
],
"description": "Getter method for Bindable Models"
},
"Setter": {
"prefix": "setter",
"body": [
"instance.set_$0 = function(val) data.$0 = val end"
],
"description": "Setter method for Bindable Models"
},
"Corona UI Control": {
"prefix": "ctrl",
"body": [
"local ctrl = {}",
" ",
"ctrl.new = function(parent, options)",
" local options = options or {}",
" local x = options.x or 0",
" local y = options.y or 0",
" ",
" -- setup display group to hold control and assign to parent",
" local container = display.newGroup()",
" if parent then",
" parent:insert(container)",
" end",
" container.x, container.y = x, y",
" ",
" return container",
"end",
" ",
"return ctrl"
],
"description": "Base class for UI control"
},
"Corona Scene": {
"prefix": "scene",
"body": [
"local composer = require( 'composer' )",
"local scene = composer.newScene()",
"",
" ",
"-- -----------------------------------------------------------------------------------",
"-- Scene event functions",
"-- -----------------------------------------------------------------------------------",
" ",
"-- create()",
"function scene:create( event )",
" ",
" local sceneGroup = self.view",
" -- Code here runs when the scene is first created but has not yet appeared on screen",
" ",
"end",
" ",
" ",
"-- show()",
"function scene:show( event )",
" ",
" local sceneGroup = self.view",
" local phase = event.phase",
" ",
" if ( phase == 'will' ) then",
" -- Code here runs when the scene is still off screen (but is about to come on screen)",
" ",
" elseif ( phase == 'did' ) then",
" -- Code here runs when the scene is entirely on screen",
" ",
" end",
"end",
" ",
" ",
"-- hide()",
"function scene:hide( event )",
" ",
" local sceneGroup = self.view",
" local phase = event.phase",
" ",
" if ( phase == 'will' ) then",
" -- Code here runs when the scene is on screen (but is about to go off screen)",
" ",
" elseif ( phase == 'did' ) then",
" -- Code here runs immediately after the scene goes entirely off screen",
" ",
" end",
"end",
" ",
" ",
"-- destroy()",
"function scene:destroy( event )",
" ",
" local sceneGroup = self.view",
" -- Code here runs prior to the removal of scene's view",
" ",
"end",
" ",
" ",
"-- -----------------------------------------------------------------------------------",
"-- Scene event function listeners",
"-- -----------------------------------------------------------------------------------",
"scene:addEventListener( 'create', scene )",
"scene:addEventListener( 'show', scene )",
"scene:addEventListener( 'hide', scene )",
"scene:addEventListener( 'destroy', scene )",
"-- -----------------------------------------------------------------------------------",
" ",
"return scene"
],
"description": "Base scene template"
},
"io.tmpfile": {
"body": "io.tmpfile ()",
"prefix": "io.tmpfile",
"description": "Returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends."
},
"coroutine.wrap": {
"body": "coroutine.wrap (${1:f})",
"prefix": "coroutine.wrap",
"description": "Creates a new coroutine, with body f . f must be a Lua function. Returns a function that resumes the coroutine each time it is called. Any arguments passed to the function behave as the extra arguments to resume . Returns the same values returned by resume , except the first boolean. In case of error, propagates the error."
},
"math.rad": {
"body": "math.rad (${1:x})",
"prefix": "math.rad",
"description": "Returns the angle x (given in degrees) in radians."
},
"package.preload": {
"body": "package.preload",
"prefix": "package.preload",
"description": "A table to store loaders for specific modules (see require )."
},
"rawequal": {
"body": "rawequal (${1:v1}, ${2:v2})",
"prefix": "rawequal",
"description": ""
},
"_G": {
"body": "_G",
"prefix": "_G",
"description": ""
},
"table.sort": {
"body": "table.sort (${1:table}, ${2:comp})",
"prefix": "table.sort",
"description": "The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort."
},
"dofile": {
"body": "dofile (${1:filename})",
"prefix": "dofile",
"description": ""
},
"math.floor": {
"body": "math.floor (${1:x})",
"prefix": "math.floor",
"description": "Returns the largest integer smaller than or equal to x ."
},
"math.huge": {
"body": "math.huge",
"prefix": "math.huge",
"description": "The value HUGE_VAL , a value larger than or equal to any other numerical value."
},
"ipairs": {
"body": "ipairs (${1:t})",
"prefix": "ipairs",
"description": "Returns three values: an iterator function, the table t , and 0, so that the construction"
},
"table.insert": {
"body": "table.insert (${1:table}, ${2:pos}, ${3:value})",
"prefix": "table.insert",
"description": "Inserts element value at position pos in table , shifting up other elements to open space, if necessary. The default value for pos is n+1 , where n is the length of the table (see \u00a72.5.5 ), so that a call table.insert(t,x) inserts x at the end of table t ."
},
"package.loadlib": {
"body": "package.loadlib (${1:libname}, ${2:funcname})",
"prefix": "package.loadlib",
"description": "Dynamically links the host program with the C\u00a0library libname . Inside this library, looks for a function funcname and returns this function as a C\u00a0function. (So, funcname must follow the protocol (see lua_CFunction ))."
},
"string.find": {
"body": "string.find (${1:s}, ${2:pattern}, ${3:init}, ${4:plain})",
"prefix": "string.find",
"description": "If the pattern has captures, then in a successful match the captured values are also returned, after the two indices."
},
"coroutine.yield": {
"body": "coroutine.yield (\u00b7\u00b7\u00b7)",
"prefix": "coroutine.yield",
"description": "Suspends the execution of the calling coroutine. The coroutine cannot be running a C\u00a0function, a metamethod, or an iterator. Any arguments to yield are passed as extra results to resume ."
},
"print": {
"body": "print (\u00b7\u00b7\u00b7)",
"prefix": "print",
"description": ""
},
"os.rename": {
"body": "os.rename (${1:oldname}, ${2:newname})",
"prefix": "os.rename",
"description": "Renames file or directory named oldname to newname . If this function fails, it returns nil , plus a string describing the error."
},
"tostring": {
"body": "tostring (${1:e})",
"prefix": "tostring",
"description": "If the metatable of e has a \"__tostring\" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result."
},
"io.open": {
"body": "io.open (${1:filename}, ${2:mode})",
"prefix": "io.open",
"description": "This function opens a file, in the mode specified in the string mode . It returns a new file handle, or, in case of errors, nil plus an error message."
},
"coroutine.running": {
"body": "coroutine.running ()",
"prefix": "coroutine.running",
"description": "Returns the running coroutine, or nil when called by the main thread."
},
"debug.getfenv": {
"body": "debug.getfenv (${1:o})",
"prefix": "debug.getfenv",
"description": ""
},
"debug.setfenv": {
"body": "debug.setfenv (${1:object}, ${2:table})",
"prefix": "debug.setfenv",
"description": "Sets the environment of the given object to the given table . Returns object ."
},
"table.remove": {
"body": "table.remove (${1:table}, ${2:pos})",
"prefix": "table.remove",
"description": "Removes from table the element at position pos , shifting down other elements to close the space, if necessary. Returns the value of the removed element. The default value for pos is n , where n is the length of the table, so that a call table.remove(t) removes the last element of table t ."
},
"debug.traceback": {
"body": "debug.traceback (${1:thread}, ${2:message}, ${3:level})",
"prefix": "debug.traceback",
"description": "Returns a string with a traceback of the call stack. An optional message string is appended at the beginning of the traceback. An optional level number tells at which level to start the traceback (default is 1, the function calling traceback )."
},
"file:setvbuf": {
"body": "file:setvbuf (${1:mode}, ${2:size})",
"prefix": "file:setvbuf",
"description": "Sets the buffering mode for an output file. There are three available modes:"
},
"debug.getregistry": {
"body": "debug.getregistry ()",
"prefix": "debug.getregistry",
"description": "Returns the registry table (see \u00a73.5 )."
},
"debug.getinfo": {
"body": "debug.getinfo (${1:thread}, ${2:function}, ${3:what})",
"prefix": "debug.getinfo",
"description": "Returns a table with information about a function. You can give the function directly, or you can give a number as the value of function , which means the function running at level function of the call stack of the given thread: level\u00a00 is the current function ( getinfo itself); level\u00a01 is the function that called getinfo ; and so on. If function is a number larger than the number of active functions, then getinfo returns nil ."
},
"math.pow": {
"body": "math.pow (${1:x}, ${2:y})",
"prefix": "math.pow",
"description": "Returns x y . (You can also use the expression x^y to compute this value.)"
},
"coroutine.resume": {
"body": "coroutine.resume (${1:co}, ${2:val1}, \u00b7\u00b7\u00b7)",
"prefix": "coroutine.resume",
"description": "Starts or continues the execution of coroutine co . The first time you resume a coroutine, it starts running its body. The values val1 , \u00b7\u00b7\u00b7 are passed as the arguments to the body function. If the coroutine has yielded, resume restarts it; the values val1 , \u00b7\u00b7\u00b7 are passed as the results from the yield."
},
"string.dump": {
"body": "string.dump (${1:function})",
"prefix": "string.dump",
"description": "Returns a string containing a binary representation of the given function, so that a later loadstring on this string returns a copy of the function. function must be a Lua function without upvalues."
},
"io.output": {
"body": "io.output (${1:file})",
"prefix": "io.output",
"description": "Similar to io.input , but operates over the default output file."
},
"os.difftime": {
"body": "os.difftime (${1:t2}, ${2:t1})",
"prefix": "os.difftime",
"description": "Returns the number of seconds from time t1 to time t2 . In POSIX, Windows, and some other systems, this value is exactly t2 - t1 ."
},
"module": {
"body": "module (${1:name}, \u00b7\u00b7\u00b7)",
"prefix": "module",
"description": "Creates a module. If there is a table in package.loaded[name] , this table is the module. Otherwise, if there is a global table t with the given name, this table is the module. Otherwise creates a new table t and sets it as the value of the global name and the value of package.loaded[name] . This function also initializes t._NAME with the given name, t._M with the module ( t itself), and t._PACKAGE with the package name (the full module name minus last component; see below). Finally, module sets t as the new environment of the current function and the new value of package.loaded[name] , so that require returns t ."
},
"package.cpath": {
"body": "package.cpath",
"prefix": "package.cpath",
"description": "The path used by require to search for a C\u00a0loader."
},
"table.concat": {
"body": "table.concat (${1:table}, ${2:sep}, ${3:i}, ${4:j})",
"prefix": "table.concat",
"description": ""
},
"math.ldexp": {
"body": "math.ldexp (${1:m}, ${2:e})",
"prefix": "math.ldexp",
"description": "Returns m2 e ( e should be an integer)."
},
"math.sqrt": {
"body": "math.sqrt (${1:x})",
"prefix": "math.sqrt",
"description": "Returns the square root of x . (You can also use the expression x^0.5 to compute this value.)"
},
"debug.setupvalue": {
"body": "debug.setupvalue (${1:func}, ${2:up}, ${3:value})",
"prefix": "debug.setupvalue",
"description": "This function assigns the value value to the upvalue with index up of the function func . The function returns nil if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue."
},
"math.asin": {
"body": "math.asin (${1:x})",
"prefix": "math.asin",
"description": "Returns the arc sine of x (in radians)."
},
"math.log": {
"body": "math.log (${1:x})",
"prefix": "math.log",
"description": "Returns the natural logarithm of x ."
},
"math.log10": {
"body": "math.log10 (${1:x})",
"prefix": "math.log10",
"description": "Returns the base-10 logarithm of x ."
},
"math.sin": {
"body": "math.sin (${1:x})",
"prefix": "math.sin",
"description": "Returns the sine of x (assumed to be in radians)."
},
"math.abs": {
"body": "math.abs (${1:x})",
"prefix": "math.abs",
"description": "Returns the absolute value of x ."
},
"math.sinh": {
"body": "math.sinh (${1:x})",
"prefix": "math.sinh",
"description": "Returns the hyperbolic sine of x ."
},
"math.frexp": {
"body": "math.frexp (${1:x})",
"prefix": "math.frexp",
"description": "Returns m and e such that x = m2 e , e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero)."
},
"string.gsub": {
"body": "string.gsub (${1:s}, ${2:pattern}, ${3:repl}, ${4:n})",
"prefix": "string.gsub",
"description": "If repl is a string, then its value is used for replacement. The character\u00a0 % works as an escape character: any sequence in repl of the form % n , with n between 1 and 9, stands for the value of the n -th captured substring (see below). The sequence %0 stands for the whole match. The sequence %% stands for a single\u00a0 % ."
},
"rawset": {
"body": "rawset (${1:table}, ${2:index}, ${3:value})",
"prefix": "rawset",
"description": "This function returns table ."
},
"string.match": {
"body": "string.match (${1:s}, ${2:pattern}, ${3:init})",
"prefix": "string.match",
"description": ""
},
"os.date": {
"body": "os.date (${1:format}, ${2:time})",
"prefix": "os.date",
"description": "Returns a string or a table containing date and time, formatted according to the given string format ."
},
"os.exit": {
"body": "os.exit (${1:code})",
"prefix": "os.exit",
"description": "Calls the C\u00a0function exit , with an optional code , to terminate the host program. The default value for code is the success code."
},
"tonumber": {
"body": "tonumber (${1:e}, ${2:base})",
"prefix": "tonumber",
"description": "An optional argument specifies the base to interpret the numeral. The base may be any integer between 2 and 36, inclusive. In bases above\u00a010, the letter ' A ' (in either upper or lower case) represents\u00a010, ' B ' represents\u00a011, and so forth, with ' Z ' representing 35. In base 10 (the default), the number can have a decimal part, as well as an optional exponent part (see \u00a72.1 ). In other bases, only unsigned integers are accepted."
},
"string.sub": {
"body": "string.sub (${1:s}, ${2:i}, ${3:j})",
"prefix": "string.sub",
"description": ""
},
"math.randomseed": {
"body": "math.randomseed (${1:x})",
"prefix": "math.randomseed",
"description": "Sets x as the \"seed\" for the pseudo-random generator: equal seeds produce equal sequences of numbers."
},
"pairs": {
"body": "pairs (${1:t})",
"prefix": "pairs",
"description": "Returns three values: the next function, the table t , and nil , so that the construction"
},
"math.modf": {
"body": "math.modf (${1:x})",
"prefix": "math.modf",
"description": "Returns two numbers, the integral part of x and the fractional part of x ."
},
"rawget": {
"body": "rawget (${1:table}, ${2:index})",
"prefix": "rawget",
"description": ""
},
"debug.getlocal": {
"body": "debug.getlocal (${1:thread}, ${2:level}, ${3:local})",
"prefix": "debug.getlocal",
"description": "This function returns the name and the value of the local variable with index local of the function at level level of the stack. (The first parameter or local variable has index\u00a01, and so on, until the last active local variable.) The function returns nil if there is no local variable with the given index, and raises an error when called with a level out of range. (You can call debug.getinfo to check whether the level is valid.)"
},
"math.deg": {
"body": "math.deg (${1:x})",
"prefix": "math.deg",
"description": "Returns the angle x (given in radians) in degrees."
},
"math.acos": {
"body": "math.acos (${1:x})",
"prefix": "math.acos",
"description": "Returns the arc cosine of x (in radians)."
},
"file:flush": {
"body": "file:flush ()",
"prefix": "file:flush",
"description": "Saves any written data to file ."
},
"load": {
"body": "load (${1:func}, ${2:chunkname})",
"prefix": "load",
"description": "Loads a chunk using function func to get its pieces. Each call to func must return a string that concatenates with previous results. A return of an empty string, nil , or no value signals the end of the chunk."
},
"os.execute": {
"body": "os.execute (${1:command})",
"prefix": "os.execute",
"description": "This function is equivalent to the C\u00a0function system . It passes command to be executed by an operating system shell. It returns a status code, which is system-dependent. If command is absent, then it returns nonzero if a shell is available and zero otherwise."
},
"io.type": {
"body": "io.type (${1:obj})",
"prefix": "io.type",
"description": "Checks whether obj is a valid file handle. Returns the string \"file\" if obj is an open file handle, \"closed file\" if obj is a closed file handle, or nil if obj is not a file handle."
},
"string.gmatch": {
"body": "string.gmatch (${1:s}, ${2:pattern})",
"prefix": "string.gmatch",
"description": "As an example, the following loop"
},
"math.tan": {
"body": "math.tan (${1:x})",
"prefix": "math.tan",
"description": "Returns the tangent of x (assumed to be in radians)."
},
"io.input": {
"body": "io.input (${1:file})",
"prefix": "io.input",
"description": "When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file."
},
"package.seeall": {
"body": "package.seeall (${1:module})",
"prefix": "package.seeall",
"description": "Sets a metatable for module with its __index field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function module ."
},
"os.remove": {
"body": "os.remove (${1:filename})",
"prefix": "os.remove",
"description": "Deletes the file or directory with the given name. Directories must be empty to be removed. If this function fails, it returns nil , plus a string describing the error."
},
"select": {
"body": "select (${1:index}, \u00b7\u00b7\u00b7)",
"prefix": "select",
"description": "If index is a number, returns all arguments after argument number index . Otherwise, index must be the string \"#\" , and select returns the total number of extra arguments it received."
},
"debug.getupvalue": {
"body": "debug.getupvalue (${1:func}, ${2:up})",
"prefix": "debug.getupvalue",
"description": "This function returns the name and the value of the upvalue with index up of the function func . The function returns nil if there is no upvalue with the given index."
},
"string.char": {
"body": "string.char (\u00b7\u00b7\u00b7)",
"prefix": "string.char",
"description": "Note that numerical codes are not necessarily portable across platforms."
},
"pcall": {
"body": "pcall (${1:f}, ${2:arg1}, \u00b7\u00b7\u00b7)",
"prefix": "pcall",
"description": "Calls function f with the given arguments in protected mode . This means that any error inside\u00a0 f is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message."
},
"io.lines": {
"body": "io.lines (${1:filename})",
"prefix": "io.lines",
"description": "Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction"
},
"string.rep": {
"body": "string.rep (${1:s}, ${2:n})",
"prefix": "string.rep",
"description": ""
},
"string.byte": {
"body": "string.byte (${1:s}, ${2:i}, ${3:j})",
"prefix": "string.byte",
"description": "Note that numerical codes are not necessarily portable across platforms."
},
"next": {
"body": "next (${1:table}, ${2:index})",
"prefix": "next",
"description": "Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. next returns the next index of the table and its associated value. When called with nil as its second argument, next returns an initial index and its associated value. When called with the last index, or with nil in an empty table, next returns nil . If the second argument is absent, then it is interpreted as nil . In particular, you can use next(t) to check whether a table is empty."
},
"setmetatable": {
"body": "setmetatable (${1:table}, ${2:metatable})",
"prefix": "setmetatable",
"description": "Sets the metatable for the given table. (You cannot change the metatable of other types from Lua, only from\u00a0C.) If metatable is nil , removes the metatable of the given table. If the original metatable has a \"__metatable\" field, raises an error."
},
"type": {
"body": "type (${1:v})",
"prefix": "type",
"description": ""
},
"math.ceil": {
"body": "math.ceil (${1:x})",
"prefix": "math.ceil",
"description": "Returns the smallest integer larger than or equal to x ."
},
"getfenv": {
"body": "getfenv (${1:f})",
"prefix": "getfenv",
"description": ""
},
"xpcall": {
"body": "xpcall (${1:f}, ${2:err})",
"prefix": "xpcall",
"description": "This function is similar to pcall , except that you can set a new error handler."
},
"package.path": {
"body": "package.path",
"prefix": "package.path",
"description": "The path used by require to search for a Lua loader."
},
"assert": {
"body": "assert (${1:v}, ${2:message})",
"prefix": "assert",
"description": ""
},
"file:read": {
"body": "file:read (\u00b7\u00b7\u00b7)",
"prefix": "file:read",
"description": "Reads the file file , according to the given formats, which specify what to read. For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format. When called without formats, it uses a default format that reads the entire next line (see below)."
},
"coroutine.status": {
"body": "coroutine.status (${1:co})",
"prefix": "coroutine.status",
"description": "Returns the status of coroutine co , as a string: \"running\" , if the coroutine is running (that is, it called status ); \"suspended\" , if the coroutine is suspended in a call to yield , or if it has not started running yet; \"normal\" if the coroutine is active but not running (that is, it has resumed another coroutine); and \"dead\" if the coroutine has finished its body function, or if it has stopped with an error."
},
"os.setlocale": {
"body": "os.setlocale (${1:locale}, ${2:category})",
"prefix": "os.setlocale",
"description": "Sets the current locale of the program. locale is a string specifying a locale; category is an optional string describing which category to change: \"all\" , \"collate\" , \"ctype\" , \"monetary\" , \"numeric\" , or \"time\" ; the default category is \"all\" . The function returns the name of the new locale, or nil if the request cannot be honored."
},
"unpack": {
"body": "unpack (${1:list}, ${2:i}, ${3:j})",
"prefix": "unpack",
"description": "except that the above code can be written only for a fixed number of elements. By default, i is\u00a01 and j is the length of the list, as defined by the length operator (see \u00a72.5.5 )."
},
"getmetatable": {
"body": "getmetatable (${1:object})",
"prefix": "getmetatable",
"description": "If object does not have a metatable, returns nil . Otherwise, if the object's metatable has a \"__metatable\" field, returns the associated value. Otherwise, returns the metatable of the given object."
},
"loadstring": {
"body": "loadstring (${1:string}, ${2:chunkname})",
"prefix": "loadstring",
"description": "Similar to load , but gets the chunk from the given string."
},
"debug.debug": {
"body": "debug.debug ()",
"prefix": "debug.debug",
"description": "Enters an interactive mode with the user, running each string that the user enters. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. A line containing only the word cont finishes this function, so that the caller continues its execution."
},
"table.maxn": {
"body": "table.maxn (${1:table})",
"prefix": "table.maxn",
"description": "Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. (To do its job this function does a linear traversal of the whole table.)"
},
"os.clock": {
"body": "os.clock ()",
"prefix": "os.clock",
"description": "Returns an approximation of the amount in seconds of CPU time used by the program."
},
"string.reverse": {
"body": "string.reverse (${1:s})",
"prefix": "string.reverse",
"description": ""
},
"debug.setlocal": {
"body": "debug.setlocal (${1:thread}, ${2:level}, ${3:local}, ${4:value})",
"prefix": "debug.setlocal",
"description": "This function assigns the value value to the local variable with index local of the function at level level of the stack. The function returns nil if there is no local variable with the given index, and raises an error when called with a level out of range. (You can call getinfo to check whether the level is valid.) Otherwise, it returns the name of the local variable."
},
"file:write": {
"body": "file:write (\u00b7\u00b7\u00b7)",
"prefix": "file:write",
"description": "Writes the value of each of its arguments to the file . The arguments must be strings or numbers. To write other values, use tostring or string.format before write ."
},
"os.tmpname": {
"body": "os.tmpname ()",
"prefix": "os.tmpname",
"description": "Returns a string with a file name that can be used for a temporary file. The file must be explicitly opened before its use and explicitly removed when no longer needed."
},
"error": {
"body": "error (${1:message}, ${2:level})",
"prefix": "error",
"description": "Usually, error adds some information about the error position at the beginning of the message. The level argument specifies how to get the error position. With level\u00a01 (the default), the error position is where the error function was called. Level\u00a02 points the error to where the function that called error was called; and so on. Passing a level\u00a00 avoids the addition of error position information to the message."
},
"math.cosh": {
"body": "math.cosh (${1:x})",
"prefix": "math.cosh",
"description": "Returns the hyperbolic cosine of x ."
},
"math.random": {
"body": "math.random (${1:m}, ${2:n})",
"prefix": "math.random",
"description": "This function is an interface to the simple pseudo-random generator function rand provided by ANSI\u00a0C. (No guarantees can be given for its statistical properties.)"
},
"_VERSION": {
"body": "_VERSION",
"prefix": "_VERSION",
"description": ""
},
"io.flush": {
"body": "io.flush ()",
"prefix": "io.flush",
"description": "Equivalent to file:flush over the default output file."
},
"file:close": {
"body": "file:close ()",
"prefix": "file:close",
"description": "Closes file . Note that files are automatically closed when their handles are garbage collected, but that takes an unpredictable amount of time to happen."
},
"debug.sethook": {
"body": "debug.sethook (${1:thread}, ${2:hook}, ${3:mask}, ${4:count})",
"prefix": "debug.sethook",
"description": "Sets the given function as a hook. The string mask and the number count describe when the hook will be called. The string mask may have the following characters, with the given meaning:"
},
"os.time": {
"body": "os.time (${1:table})",
"prefix": "os.time",
"description": "Returns the current time when called without arguments, or a time representing the date and time specified by the given table. This table must have fields year , month , and day , and may have fields hour , min , sec , and isdst (for a description of these fields, see the os.date function)."
},
"string.lower": {
"body": "string.lower (${1:s})",
"prefix": "string.lower",
"description": ""
},
"debug.getmetatable": {
"body": "debug.getmetatable (${1:object})",
"prefix": "debug.getmetatable",
"description": "Returns the metatable of the given object or nil if it does not have a metatable."
},
"math.min": {
"body": "math.min (${1:x}, \u00b7\u00b7\u00b7)",
"prefix": "math.min",
"description": "Returns the minimum value among its arguments."
},
"file:seek": {
"body": "file:seek (${1:whence}, ${2:offset})",
"prefix": "file:seek",
"description": "Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence , as follows:"
},
"setfenv": {
"body": "setfenv (${1:f}, ${2:table})",
"prefix": "setfenv",
"description": "Sets the environment to be used by the given function. f can be a Lua function or a number that specifies the function at that stack level: Level\u00a01 is the function calling setfenv . setfenv returns the given function."
},
"string.format": {
"body": "string.format (${1:formatstring}, \u00b7\u00b7\u00b7)",
"prefix": "string.format",
"description": "will produce the string:"
},
"math.pi": {
"body": "math.pi",
"prefix": "math.pi",
"description": "The value of pi ."
},
"math.max": {
"body": "math.max (${1:x}, \u00b7\u00b7\u00b7)",
"prefix": "math.max",
"description": "Returns the maximum value among its arguments."
},
"math.atan": {
"body": "math.atan (${1:x})",
"prefix": "math.atan",
"description": "Returns the arc tangent of x (in radians)."
},
"require": {
"body": "require (${1:modname})",
"prefix": "require",
"description": "Loads the given module. The function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname] . Otherwise, it tries to find a loader for the module."
},
"io.write": {
"body": "io.write (\u00b7\u00b7\u00b7)",
"prefix": "io.write",
"description": "Equivalent to io.output():write ."
},
"os.getenv": {
"body": "os.getenv (${1:varname})",
"prefix": "os.getenv",
"description": "Returns the value of the process environment variable varname , or nil if the variable is not defined."
},
"loadfile": {
"body": "loadfile (${1:filename})",
"prefix": "loadfile",
"description": "Similar to load , but gets the chunk from file filename or from the standard input, if no file name is given."
},
"coroutine.create": {
"body": "coroutine.create (${1:f})",
"prefix": "coroutine.create",
"description": "Creates a new coroutine, with body f . f must be a Lua function. Returns this new coroutine, an object with type \"thread\" ."
},
"package.loaders": {
"body": "package.loaders",
"prefix": "package.loaders",
"description": "A table used by require to control how to load modules."
},
"debug.setmetatable": {
"body": "debug.setmetatable (${1:object}, ${2:table})",
"prefix": "debug.setmetatable",
"description": "Sets the metatable for the given object to the given table (which can be nil )."
},
"file:lines": {
"body": "file:lines ()",
"prefix": "file:lines",
"description": "Returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction"
},
"debug.gethook": {
"body": "debug.gethook (${1:thread})",
"prefix": "debug.gethook",
"description": "Returns the current hook settings of the thread, as three values: the current hook function, the current hook mask, and the current hook count (as set by the debug.sethook function)."
},
"collectgarbage": {
"body": "collectgarbage (${1:opt}, ${2:arg})",
"prefix": "collectgarbage",
"description": "This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt :"
},
"math.cos": {
"body": "math.cos (${1:x})",
"prefix": "math.cos",
"description": "Returns the cosine of x (assumed to be in radians)."
},
"math.tanh": {
"body": "math.tanh (${1:x})",
"prefix": "math.tanh",
"description": "Returns the hyperbolic tangent of x ."
},
"io.read": {
"body": "io.read (\u00b7\u00b7\u00b7)",
"prefix": "io.read",
"description": "Equivalent to io.input():read ."
},
"string.len": {
"body": "string.len (${1:s})",
"prefix": "string.len",
"description": ""
},
"package.loaded": {
"body": "package.loaded",
"prefix": "package.loaded",
"description": "A table used by require to control which modules are already loaded. When you require a module modname and package.loaded[modname] is not false, require simply returns the value stored there."
},
"string.upper": {
"body": "string.upper (${1:s})",
"prefix": "string.upper",
"description": "A character class is used to represent a set of characters. The following combinations are allowed in describing a character class:"
},
"math.atan2": {
"body": "math.atan2 (${1:y}, ${2:x})",
"prefix": "math.atan2",
"description": "Returns the arc tangent of y\/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.)"
},
"io.popen": {
"body": "io.popen (${1:prog}, ${2:mode})",
"prefix": "io.popen",
"description": "Starts program prog in a separated process and returns a file handle that you can use to read data from this program (if mode is \"r\" , the default) or to write data to this program (if mode is \"w\" )."
},
"math.fmod": {
"body": "math.fmod (${1:x}, ${2:y})",
"prefix": "math.fmod",
"description": "Returns the remainder of the division of x by y that rounds the quotient towards zero."
},
"math.exp": {
"body": "math.exp (${1:x})",
"prefix": "math.exp",
"description": "Returns the value e x ."
},
"io.close": {
"body": "io.close (${1:file})",
"prefix": "io.close",
"description": "Equivalent to file:close() . Without a file , closes the default output file."
},
"if": {
"body": [
"if ${1} then",
"\t${0}",
"end"
],
"prefix": "if",
"description": "If Conditional"
},
"if single line": {
"body": [
"if ${1} then ${0} end"
],
"prefix": "if",
"description": "If Conditional"
},
"elseif": {
"body": [
"elseif ${1} then",
"\t${0}"
],
"prefix": "elseif",
"description": "IfElse Conditional"
},
"else": {
"body": [
"else ${1}",
"\t${0}"
],
"prefix": "else",
"description": "Else Conditional"
},
"while": {
"body": [
"while ${1} do",
"\t${0}",
"end"
],
"prefix": "while",
"description": "While loop"
},
"repeat": {
"body": [
"repeat",
"\t${0}",
"until ${1}"
],
"prefix": "repeat",
"description": "Condition checked after the first iteration, so the code is guaranteed to run at least once."
},
"Numeric for loop": {
"body": [
"for ${1:variable} = ${2:start}, ${3:stop}, ${4:step} do",
"\t${0}",
"end"
],
"prefix": "for",
"description": "Runs the block with variable first being equal to start, then keeps incrementing it step amount and running the block again until it's greater than stop. step defaults to 1."
},
"Iterator for loop indexed": {
"body": [
"for k, v in ipairs(${1:table}) do",
"\t${0}",
"end"
],
"prefix": "for",
"description": "Runs the block with variable first being equal to start, then keeps incrementing it step amount and running the block again until it's greater than stop. step defaults to 1."
},
"Iterator for loop": {
"body": [
"for k, v in pairs(${1:table}) do",
"\t${0}",
"end"
],
"prefix": "for",
"description": "Runs the block with variable first being equal to start, then keeps incrementing it step amount and running the block again until it's greater than stop. step defaults to 1."
},
"function": {
"body": [
"function(${1})",
"\t${0}",
"end"
],
"prefix": "function",
"description": "Function"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment