├── .gitignore ├── README.md ├── lib ├── analysis.js ├── config.js ├── extraction.js ├── format.js ├── index.js ├── module-cache.js ├── options │ ├── empty.js │ ├── index.js │ ├── luacompleterc.js │ └── stdlib.js ├── provider.js ├── resolve.js ├── stdlib │ ├── 5_1.json │ ├── 5_2.json │ ├── 5_3.json │ ├── 5_4.json │ └── luajit-2_0.json └── typedefs.js ├── package.json └── scraper └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | test.lua 3 | .luacompleterc 4 | node_modules 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # atom-autocomplete-lua 2 | 3 | [![](https://img.shields.io/apm/dm/autocomplete-lua.svg)](http://atom.io/packages/autocomplete-lua) 4 | 5 | **WARNING! Unmaintained project! Use at your own risk! I don't have the time and motivations to maintain this project anymore. If somebody wants to pick up maintenance for this, please contact me.** 6 | 7 | Atom Autocomplete+ provider for Lua. 8 | 9 | This package aims to parse Lua files with [oxyc/luaparse](https://github.com/oxyc/luaparse) and generate scope and type-aware completions with syntactic analysis. 10 | 11 | ![](https://cloud.githubusercontent.com/assets/428060/19417900/ebb20426-93c0-11e6-98ef-c90b66fbf109.png) 12 | 13 | ## Features 14 | 15 | * Limited type inference mechanism 16 | * Scope-aware variable name suggestions 17 | * Table member completions on `.` and `:` 18 | * Snippets for function call arguments 19 | * Aware of `setmetatable()` and function return types 20 | * Completion for the Lua standard library 21 | * `.luacompleterc` file to define additional globals 22 | * Doc-strings in `.luacompleterc` 23 | * Configuration service for other packages to programmatically define globals 24 | * Autocomplete `require`d modules 25 | 26 | ## Available Providers 27 | 28 | - [Defold IDE](http://atom.io/packages/defold-ide) - Adds hot reloading, autocompletion and in-line API docs for the [Defold](http://www.defold.com/) game engine. 29 | - [LÖVE Atom](https://github.com/rm-code/love-atom) - Smart autocompletion for the [LÖVE](https://love2d.org/) framework in Atom. 30 | 31 | ## Configuration 32 | 33 | Besides what you can configure in Atom preferences, `atom-autocomplete-lua` 34 | looks for a `.luacompleterc` file in the parent directories of the current file. 35 | 36 | If you need to define additional global symbols for your specific Lua environment, 37 | place a `.luacompleterc` file in your project root. It's a JSON file with roughly 38 | the following structure: 39 | 40 | ```javascript 41 | { 42 | "global": { 43 | "type": "table", 44 | "fields": { 45 | "my_global_var": { /* type definition */ }, 46 | /* ... */ 47 | } 48 | }, 49 | "namedTypes": { 50 | "my_named_type": { /* type definition */ }, 51 | /* ... */ 52 | } 53 | "luaVersion": "5.2", 54 | "packagePath": "./?.lua", 55 | "cwd": "path/to/lua/module/root" 56 | } 57 | ``` 58 | 59 | All options are optional. Here's what each option does: 60 | 61 | | Option | Default | Description | 62 | |--------|---------|-------------| 63 | |`global`|`{ type: 'table', fields: {} }`|The type definition of the global environment. Define additional fields on this table to declare globals available in your Lua environment. Read the [Type definitions](#type-definitions) section for more info. 64 | |`namedTypes`|`{}`|To avoid deep nesting and allow multiple places to reference a single type, you can define named types. Read the [Named types](#named-types) section for more info. 65 | |`luaVersion`|`"5.2"`|The version of Lua your code is targeting. Valid values are `"5.1"`, `"5.2"`, `"5.3"`, `"5.4"` and `"luajit-2.0"`. 66 | |`packagePath`|`"./?.lua"`|The value of `LUA_PATH` used when resolving required modules. 67 | |`cwd`|`.`|The current directory used to resolve relative paths in `packagePath`. If `cwd` is relative, it's considered relative to the parent directory of `.luacompleterc`. 68 | 69 | 70 | ## Type definitions 71 | 72 | The general format of a type definition is: 73 | 74 | ```javascript 75 | { 76 | "type": "type_name", // one of "function", "table", "number", "boolean", "string" or "unknown", "ref" 77 | "description": "Optional short Markdown description of your symbol", 78 | "descriptionPlain": "Optional short plain text description of your symbol (if you don't want Markdown for some reason)", 79 | "link": "http://optional.link/to/full/api/docs" 80 | } 81 | ``` 82 | 83 | ### Tables 84 | 85 | Tables (`"type": "table"`) have 2 more properties: 86 | * `fields`: *Required.* An object mapping table fields to their corresponding type definition. Even though Lua allows indexing tables with any value, only string keys are supported for autocompletion purposes. 87 | * `metatable`: *Optional.* The type definition of the metatable of this table, if it has one. `autocomplete-lua` is aware of keys like `__index` in this metatable and uses them for completion. If present, the `type` of the metatable must be `"table"`. 88 | 89 | **Example:** 90 | ```javascript 91 | { // Type definition for a student 92 | "type": "table", 93 | "fields": { 94 | "name": { "type": "string" }, 95 | "surname": { "type": "string" }, 96 | "height": { "type": "number" } 97 | }, 98 | "metatable": { 99 | "type": "table", 100 | "fields": { 101 | "__index": { 102 | "type": "table", 103 | "fields": { "skip_rope": { "type": "function" } } 104 | } 105 | } 106 | } 107 | } 108 | ``` 109 | 110 | ### Functions 111 | 112 | Functions (`"type": "function"`) can have a few more optional properties: 113 | * `returnTypes`: An array of type definitions describing the types of the function's return values. 114 | * `args`: An array of argument name definitions (see below). 115 | * `argsDisplay`: In case you want your arguments to be displayed in the autocomplete dropdown in a custom way, you can provide a string of the argument list here. 116 | * `argsDisplayOmitSelf`: Same as above, but displayed when completing method calls with `:`. You should provide the same arg list string, but with the first argument removed. Defaults to `argsDisplay`. 117 | * `argTypes`: An array of argument type definitions (or `null` when type is unknown). 118 | 119 | Argument names are of the form `{ "name": "arg_name", "displayName": "display_name" }`, 120 | where `displayName` is optional. 121 | 122 | `displayName` will be displayed in the 123 | autocomplete dropdown, while `name` will be part of the inserted snippet. 124 | This is useful for things like optional arguments: 125 | 126 | ```javascript 127 | { 128 | "type": "function", 129 | "args": [{ "name": "arg1" }, { "name": "arg2", "displayName": "[arg2]" }], 130 | } 131 | ``` 132 | 133 | will produce `f(arg1, [arg2])` in the dropdown and `f(arg1, arg2)` after being inserted. 134 | 135 | In rare cases, `displayName` might be unsuitable for you. `argsDisplay` and `argsDisplayOmitSelf` can be used to manually specify the comma-separated list of 136 | arguments. 137 | 138 | For example, you can use it to customize comma placement in relation to `[`: 139 | 140 | ```javascript 141 | { 142 | "type": "function", 143 | "args": [{ "name": "self" }, { "name": "arg1" }, { "name": "arg2" }], 144 | "argsDisplay": "self[, arg1[, arg2]]", 145 | "argsDisplayOmitSelf": "[arg1[, arg2]]" 146 | } 147 | ``` 148 | 149 | This will produce `f(self[, arg1[, arg2]])` in the dropdown and `f(self, arg1, arg2)` 150 | after being inserted. 151 | 152 | ### Function variants 153 | 154 | Sometimes, you may have polymorphic functions which can be called with a number 155 | of different argument configurations. You might want to show all of these 156 | versions separately in the autocomplete dropdown. 157 | 158 | You can provide multiple versions of the same function by moving `link`, 159 | `description`, `args`, `argsDisplay` and `argsDisplayOmitSelf` inside a 160 | `variants` array like so: 161 | 162 | ```javascript 163 | { // Type definition for a get(url_or_filename) function 164 | "type": "function", 165 | "variants": [{ 166 | "args": [{ "name": "url" }], 167 | "description": "Fetches an URL and returns a string with the contents" 168 | }, { 169 | "args": [{ "name": "filename" }], 170 | "description": "Read the file at filename and returns a string with the contents" 171 | }] 172 | } 173 | ``` 174 | 175 | The autocomplete dropdown will show both `get(url)` and `get(filename)` with their 176 | corresponding descriptions. 177 | 178 | ### Named types 179 | 180 | There are often cases where you want to use the same type definition in 181 | multiple places. In these situations, you can use named types in your `.luacompleterc`. 182 | 183 | Just use `{ "type": "ref", "name": "my_named_type" }` instead of your type 184 | definition and define `my_named_type` in `namedTypes`. 185 | 186 | **Example .luacompleterc:** 187 | ```javascript 188 | { 189 | "global": { 190 | "type": "table", 191 | "fields": { 192 | "make_a_cat": { 193 | "type": "function", 194 | "returnTypes": [{ "type": "ref", "name": "cat" }] 195 | }, 196 | "make_a_cat_somehow_else": { 197 | "type": "function", 198 | "returnTypes": [{ "type": "ref", "name": "cat" }] 199 | } 200 | } 201 | }, 202 | "namedTypes": { 203 | "cat": { 204 | "type": "table", 205 | "fields": { 206 | "color": { "type": "string" }, 207 | "is_fluffy": { "type": "boolean" } 208 | } 209 | } 210 | } 211 | } 212 | ``` 213 | 214 | ## Option providers 215 | 216 | All the options provided in a `.luacompleterc` can be programmatically provided 217 | by plugin packages (like [Defold IDE](http://atom.io/packages/defold-ide)). 218 | 219 | Start by adding this to your `package.json`: 220 | 221 | ```json 222 | "providedServices": { 223 | "autocomplete-lua.options-provider": { 224 | "versions": { 225 | "1.0.0": "getOptionProvider" 226 | } 227 | } 228 | } 229 | ``` 230 | 231 | Then, in your package's JS object: 232 | 233 | ```javascript 234 | getOptionProvider () { 235 | return myProvider; // You can also return an array of providers if you have more 236 | } 237 | ``` 238 | 239 | The provider is an object (or a class) with the following interface: 240 | 241 | ```javascript 242 | const myProvider = { 243 | priority: 20, 244 | 245 | getOptions (request, getPreviousOptions, utils, cache) { 246 | // Just return the options from the previous provider 247 | return getPreviousOptions().then(previousOptions => { 248 | return { options: previousOptions } 249 | }) 250 | } 251 | 252 | dispose () { 253 | // Destroy stuff 254 | } 255 | } 256 | ``` 257 | 258 | ### `priority` and `getPreviousOptions()` 259 | 260 | Each time a completion is needed (roughly at each keystroke), `autocomplete-lua` 261 | sorts all the option providers by their priority and calls the `getOptions()` 262 | method of the highest priority option provider. 263 | 264 | The option provider can choose to call the next-highest-in-priority provider 265 | by calling `getPreviousOptions()`. `getPreviousOptions()` returns a promise 266 | to the options object provided by the next-in-line provider. 267 | 268 | There are 3 option providers that come with `autocomplete-lua`: 269 | * **[StdLibProvider]**. *Priority 100.* Adds Lua's standard library functions to the options. 270 | * **[LuaCompleteRcProvider]**. *Priority 10.* Adds the contents of `.luacompleterc` to the options. 271 | * **[EmptyProvider]**. *Priority 0.* Just returns an empty options object. Acts as fallback for `getPreviousOptions()`. 272 | 273 | [StdLibProvider]:https://github.com/dapetcu21/atom-autocomplete-lua/blob/master/lib/options/stdlib.js 274 | [LuaCompleteRcProvider]:https://github.com/dapetcu21/atom-autocomplete-lua/blob/master/lib/options/luacompleterc.js 275 | [EmptyProvider]:https://github.com/dapetcu21/atom-autocomplete-lua/blob/master/lib/options/empty.js 276 | 277 | ### `dispose()` 278 | 279 | Optional function. `dispose()` is called when your provider is not needed anymore. 280 | 281 | ### `getOptions(request, getPreviousOptions, utils, cache)` 282 | 283 | This function is called when your provider is expected to return a new set of options. 284 | 285 | `request` comes [directly from Autocomplete+](https://github.com/atom/autocomplete-plus/wiki/Provider-API#the-suggestion-requests-options-object), 286 | with the addition of `request.filePath`, the absolute path to the current file. 287 | 288 | The return value is an object of the form `{ options }`. The same object is passed 289 | to `getOptions()` as `cache` the next time the function is called on the same file, 290 | so you can store additional arbitrary properties on it that you'd like to receive 291 | in `cache`. Returning a promise to this object is also supported. 292 | 293 | It's strongly encouraged to always return the same `options` object if nothing 294 | changed from the last call. Read on about `utils.mergeOptionsCached()` for 295 | a simple way to do this. 296 | 297 | ### `utils.reviveOptions(options)` 298 | 299 | Takes an options object and resolves all references to named types. (Replaces `{ type: 'ref', name: 'myRef' }` with `namedTypes.myRef`). This should be called after you read the 300 | options object from permanent storage. 301 | 302 | Returns the same `options` object. 303 | 304 | ### `utils.mergeOptions(previousOptions, newOptions)` 305 | 306 | Takes 2 options objects, merges them and returns the result. 307 | 308 | Fields in `newOptions` overwrite fields in `previousOptions`. The `global` fields are deeply merged. 309 | 310 | ### `utils.mergeOptionsCached(previousOptions, newOptions, cache[, merger])` 311 | 312 | Uses `mergeOptions()` to merge `previousOptions` and `newOptions` if any of the 313 | two are different from `cache.previousOptions` and `cache.newOptions`, else 314 | returns `cache.options`. 315 | 316 | If the merge takes place, `merger(mergedOptions, previousOptions, newOptions)` 317 | is called on the newly merged object to do additional custom merging work. 318 | 319 | Returns an object `{ options, previousOptions, newOptions }` suitable for returning 320 | as the cache object from `getOptions()`. 321 | 322 | A recommended pattern is the following: 323 | 324 | ```javascript 325 | getOptions = async (request, getPreviousOptions, utils, cache) => { 326 | if (providerIsNotApplicableToTheCurrentFile) { 327 | return { options: await getPreviousOptions() } 328 | } 329 | const newOptions = conjureABunchOfNewOptions() 330 | const previousOptions = await getPreviousOptions() 331 | return utils.mergeOptionsCached(previousOptions, newOptions, cache, mergedOptions => { 332 | mergedOptions.oneMoreThing = 'this thing' 333 | }) 334 | } 335 | ``` 336 | 337 | ### `util.New()` 338 | 339 | Creates a new type definition for a ``. Available functions are: 340 | `tableNew()`, `booleanNew()`, `functionNew()`, `numberNew()`, `unknownNew()`, `nilNew()` 341 | 342 | ### `util.tableSet(table, key, value)` 343 | 344 | Sets the field identified by `key` in the table type definition `table` to the 345 | type definition `value`. 346 | 347 | ### `util.tableGet(table, key)` 348 | 349 | Gets the type definition corresponding to the field identified by `key` in the 350 | table type definition `table`. 351 | 352 | ### `util.tableSetMetatable(table, metatable)` 353 | 354 | Sets the metatable type definition in the table type definition `table` to the 355 | type definition `metatable`. 356 | 357 | ### `util.tableGetMetatable(table)` 358 | 359 | Gets the type definition of the metatable of the table type definition `table`. 360 | -------------------------------------------------------------------------------- /lib/analysis.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * The type analysis sweep 5 | */ 6 | 7 | import { 8 | tableNew, unknownNew, 9 | tableSet, tableGet, tableSetMetatable, tableGetMetatable, 10 | tableSearch, 11 | tableInvalidateDiffs, tableFreeze, tableDiffShallow, tableDiff, tableApplyDiff 12 | } from './typedefs' 13 | import { nodeGetType, nodeGetReturnTypes } from './resolve' 14 | import extractTypes from './extraction' 15 | import formatResults from './format' 16 | import luaparse from 'dapetcu21-luaparse' 17 | import ModuleCache from './module-cache' 18 | import config from './config' 19 | 20 | export default class Analysis { 21 | constructor (options, query) { 22 | this.query = query 23 | this.queryBase = null 24 | this.queryType = null 25 | this.chunk = null 26 | if (query && query.dot !== ':' && query.dot !== '.') { 27 | query.dot = null 28 | } 29 | 30 | const globalScope = options.global 31 | tableInvalidateDiffs() 32 | if (tableGet(globalScope, '_G') !== globalScope) { 33 | tableSet(globalScope, '_G', globalScope) 34 | } 35 | tableFreeze(globalScope) 36 | 37 | this.currentScope = globalScope 38 | this.globalScope = globalScope 39 | this.options = options 40 | options.moduleCache = options.moduleCache || new ModuleCache(options) 41 | 42 | this.iteration = [] 43 | this.requires = new Set() 44 | this.requireCache = {} 45 | 46 | const luaVersion = options.luaVersion || config.luaVersion || '5.2' 47 | if (luaVersion === 'luajit=2.0') { 48 | luaVersion = '5.1' 49 | } else if (luaVersion === '5.4') { 50 | luaVersion = '5.3' 51 | } 52 | luaparse.parse({ 53 | wait: true, 54 | comments: false, 55 | ranges: true, 56 | scope: true, 57 | luaVersion: luaVersion, 58 | onCreateNode: this._onCreateNode, 59 | onCreateScope: this._onCreateScope, 60 | onDestroyScope: this._onDestroyScope, 61 | onScopeIdentifierName: this._onScopeIdentifierName 62 | }) 63 | } 64 | 65 | _onCreateNode = (node) => { 66 | this.iteration.push(node) 67 | node.scope = this.currentScope 68 | node.globalScope = this.globalScope 69 | node.options = this.options 70 | 71 | if (node.type === 'Chunk') { 72 | this.chunk = node 73 | } 74 | 75 | if ( 76 | (node.type === 'CallExpression' || node.type === 'StringCallExpression') && 77 | node.base.type === 'Identifier' && 78 | node.base.name === 'require' 79 | ) { 80 | const argument = node.argument || (node.arguments && node.arguments[0]) 81 | if (argument && argument.type === 'StringLiteral') { 82 | this.requires.add(argument.value) 83 | node.requireValue = argument.value 84 | node.requireCache = this.requireCache 85 | } 86 | } 87 | 88 | if ( 89 | this.query && 90 | node.type === 'MemberExpression' && 91 | node.identifier.name.indexOf('__prefix_placeholder__') !== -1 92 | ) { 93 | if (this.query.dot) { 94 | this.queryBase = node.base 95 | } else { 96 | this.queryType = node.scope 97 | } 98 | node.isPlaceholder = true 99 | node.identifier.isPlaceholder = true 100 | if ( 101 | node.base && 102 | node.base.type === 'Identifier' && 103 | node.base.name.indexOf('__prefix_placeholder__') !== -1 104 | ) { 105 | node.base.isPlaceholder = true 106 | } 107 | } 108 | 109 | __LOG__ && console.log('onCreateNode', node) 110 | }; 111 | 112 | _onCreateScope = () => { 113 | __LOG__ && console.log('onCreateScope') 114 | const oldScope = this.currentScope 115 | const metatable = tableNew() 116 | tableSet(metatable, '__index', oldScope) 117 | this.currentScope = tableNew() 118 | tableSetMetatable(this.currentScope, metatable) 119 | }; 120 | 121 | _onDestroyScope = () => { 122 | __LOG__ && console.log('onDestroyScope') 123 | const parentScope = tableGet(tableGetMetatable(this.currentScope), '__index') 124 | this.currentScope = parentScope 125 | }; 126 | 127 | _onScopeIdentifierName = (newName, data) => { 128 | __LOG__ && console.log('onScopeIdentifierName', newName, data) 129 | if (newName.indexOf('__prefix_placeholder__') !== -1) { return } 130 | 131 | if (data && data.parameterOf) { 132 | const func = nodeGetType(data.parameterOf) 133 | if (func && func.type === 'function' && func.argTypes) { 134 | const argType = func.argTypes[data.parameterIndex] 135 | if (argType) { 136 | tableSet(this.currentScope, newName, argType) 137 | return 138 | } 139 | } 140 | } 141 | 142 | tableSet(this.currentScope, newName, unknownNew()) 143 | }; 144 | 145 | write (string) { 146 | luaparse.write(string) 147 | } 148 | 149 | end (string) { 150 | luaparse.end(string) 151 | } 152 | 153 | _evaluate = async (syncAction) => { 154 | if (this.requires.size && config.completeModules) { 155 | const mainDiff = tableDiffShallow(this.globalScope) 156 | await Promise.all([...this.requires].map(async moduleName => { 157 | const module = await this.options.moduleCache.get(moduleName, this._analyseModule) 158 | this.requireCache[moduleName] = module 159 | })) 160 | tableInvalidateDiffs() 161 | tableApplyDiff(mainDiff) 162 | } 163 | this.iteration.forEach(extractTypes) 164 | 165 | // Due to the stateful nature of tableDiffCount, we need to sample data 166 | // quickly before we return to the run loop and let another Analysis take 167 | // place, so .then()-ing promises is out of the question 168 | return syncAction() 169 | } 170 | 171 | _analyseModule = async (moduleData) => { 172 | const analysis = new Analysis(this.options) 173 | try { 174 | analysis.end(moduleData) 175 | } catch (ex) { 176 | __LOG__ && console.error(ex) 177 | } 178 | return await analysis.returnModule() 179 | }; 180 | 181 | returnModule = async () => { 182 | return await this._evaluate(() => { 183 | const returnTypes = this.chunk ? nodeGetReturnTypes(this.chunk.body) : [] 184 | const globalDiff = tableDiff(this.globalScope) 185 | return { returnTypes, globalDiff } 186 | }) 187 | } 188 | 189 | solveQuery = async () => { 190 | return await this._evaluate(() => { 191 | let queryType = this.queryType 192 | if (this.queryBase) { 193 | queryType = nodeGetType(this.queryBase) 194 | } 195 | 196 | if (!queryType) { return [] } 197 | 198 | let results = tableSearch(queryType, this.query.prefix) 199 | const trimSelf = this.query.dot === ':' 200 | if (trimSelf) { 201 | results = results.filter(x => x.typeDef && x.typeDef.type === 'function') 202 | } 203 | results.sort((a, b) => a.key.localeCompare(b.key)) 204 | return formatResults(results, trimSelf) 205 | }) 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Extracted-out config keys 5 | */ 6 | 7 | const config = {} 8 | const disposeables = [] 9 | 10 | const keys = ['suggestUsedMembers', 'useSnippets', 'luaVersion', 'minCharsPrefix', 'completeModules'] 11 | 12 | export function configObserve () { 13 | keys.forEach(key => { 14 | disposeables.push(window.atom.config.observe('autocomplete-lua.' + key, (value) => { 15 | config[key] = value 16 | })) 17 | }) 18 | } 19 | 20 | export function configDispose () { 21 | disposeables.forEach(d => d.dispose()) 22 | disposeables.length = 0 23 | } 24 | 25 | export default config 26 | -------------------------------------------------------------------------------- /lib/extraction.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Everything related to extracting type info and adding it to 5 | * the type database 6 | */ 7 | 8 | import config from './config' 9 | import { getLValue, nodeGetType } from './resolve' 10 | import { 11 | tableSet, tableSetMetatable, tableGet, tableGetMetatable, 12 | unknownNew, tableNew, functionNew, 13 | mergeTypeKnowledge, tableApplyDiff 14 | } from './typedefs' 15 | 16 | const __metatable__ = Symbol() 17 | const discoveredType = (table, key, newType, allowOverwrite) => { 18 | if (!table || table.type !== 'table') { return } 19 | 20 | const isMeta = key === __metatable__ 21 | const oldType = isMeta ? tableGetMetatable(table) : tableGet(table, key) 22 | 23 | const mergedType = mergeTypeKnowledge(oldType, newType) 24 | if (mergedType !== oldType) { 25 | if (isMeta) { 26 | tableSetMetatable(table, mergedType) 27 | } else { 28 | tableSet(table, key, mergedType) 29 | } 30 | } 31 | } 32 | 33 | export default function extractTypes (node) { 34 | if (!node || node.isPlaceholder) { return } 35 | const type = node.type 36 | 37 | if (node.requireCache) { 38 | const entry = node.requireCache[node.requireValue] 39 | if (!entry) { return } 40 | tableApplyDiff(node.globalScope, entry.globalDiff) 41 | return 42 | } 43 | if (type === 'AssignmentStatement' || type === 'LocalStatement') { 44 | node.variables.forEach((variable, i) => { 45 | const lvalue = getLValue(variable) 46 | if (!lvalue) { return } 47 | 48 | const initializer = node.init[i] 49 | const initType = nodeGetType(initializer) || unknownNew() 50 | discoveredType(lvalue.table, lvalue.key, initType) 51 | }) 52 | return 53 | } 54 | if (type === 'FunctionDeclaration') { 55 | const lvalue = getLValue(node.identifier) 56 | if (!lvalue) { return } 57 | 58 | const funcType = nodeGetType(node) || unknownNew() 59 | discoveredType(lvalue.table, lvalue.key, funcType) 60 | return 61 | } 62 | // An indexing expression comes with the assumption that the base is a table 63 | // Similarilly, a function call usually means that function exists 64 | if (config.suggestUsedMembers) { 65 | const isFunctionCall = type === 'CallExpression' 66 | const isMember = type === 'MemberExpression' || type === 'IndexExpression' 67 | if (isFunctionCall || isMember) { 68 | const lvalue = getLValue(node.base) 69 | if (lvalue) { 70 | const newType = isFunctionCall ? functionNew() : tableNew() 71 | discoveredType(lvalue.table, lvalue.key, newType) 72 | } 73 | } 74 | if (isMember) { 75 | const lvalue = getLValue(node) 76 | if (lvalue) { 77 | discoveredType(lvalue.table, lvalue.key, unknownNew()) 78 | } 79 | } 80 | } 81 | if (type === 'CallExpression' && node.base.type === 'Identifier' && node.base.name === 'setmetatable') { 82 | if (node.arguments.length < 2) { return } 83 | const tableType = nodeGetType(node.arguments[0]) 84 | if (!tableType || tableType.type !== 'table') { return } 85 | const metatableType = nodeGetType(node.arguments[1]) 86 | discoveredType(tableType, __metatable__, metatableType) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lib/format.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Code to format the type definitions into ready-for-display suggestions 5 | */ 6 | 7 | import config from './config' 8 | 9 | function getDefault () { 10 | for (let i = 0, n = arguments.length; i < n; i++) { 11 | const arg = arguments[i] 12 | if (arg !== null && arg !== undefined) { return arg } 13 | } 14 | } 15 | 16 | const emptyVariant = {} 17 | const emptyArray = [] 18 | function formatVariant (key, typeDef, variant, trimSelf) { 19 | const descriptionMarkdown = variant.description || typeDef.description 20 | const description = variant.descriptionPlain || typeDef.descriptionPlain 21 | const type = typeDef.type 22 | const link = variant.link || typeDef.link 23 | const args = variant.args || typeDef.args || emptyArray 24 | const argsDisplay = trimSelf 25 | ? getDefault(variant.argsDisplayOmitSelf, variant.argsDisplay, typeDef.argsDisplayOmitSelf, typeDef.argsDisplay) 26 | : getDefault(variant.argsDisplay, typeDef.argsDisplay) 27 | const isFunction = type === 'function' 28 | 29 | const suggestion = { 30 | type: isFunction ? 'function' : 'value', 31 | rightLabel: type === 'unknown' ? '' : type, 32 | description, 33 | descriptionMarkdown, 34 | descriptionMoreURL: link 35 | } 36 | 37 | let argList = args 38 | if (isFunction) { 39 | argList = (trimSelf ? args.slice(1) : args) 40 | const signature = argsDisplay || argList.map(a => a.displayName || a.name).join(', ') 41 | suggestion.displayText = key + '(' + signature + ')' 42 | } 43 | 44 | if (config.useSnippets && isFunction) { 45 | const signature = argList 46 | .map((a, i) => `\${${i + 1}:${a.name}}`) 47 | .join(', ') || '$1' 48 | suggestion.snippet = `${key}(${signature})\$${(argList.length || 1) + 1}` 49 | } else { 50 | suggestion.text = key 51 | } 52 | 53 | return suggestion 54 | } 55 | 56 | export default function formatResults (results, trimSelf) { 57 | const suggestions = [] 58 | results.forEach(({ key, typeDef }) => { 59 | if (typeDef.variants) { 60 | typeDef.variants.forEach(variant => 61 | suggestions.push(formatVariant(key, typeDef, variant, trimSelf)) 62 | ) 63 | } else { 64 | suggestions.push(formatVariant(key, typeDef, emptyVariant, trimSelf)) 65 | } 66 | }) 67 | return suggestions 68 | } 69 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | let LuaProvider 4 | 5 | function loadAutocompleteProvider () { 6 | if (!LuaProvider) { 7 | LuaProvider = require('./provider') 8 | } 9 | } 10 | 11 | let EmptyOptionProvider, StdLibProvider, LuaCompleteRcProvider 12 | 13 | function loadLuaProviders () { 14 | if (!EmptyOptionProvider) { 15 | EmptyOptionProvider = require('./options/empty') 16 | } 17 | if (!StdLibProvider) { 18 | StdLibProvider = require('./options/stdlib') 19 | } 20 | if (!LuaCompleteRcProvider) { 21 | LuaCompleteRcProvider = require('./options/luacompleterc') 22 | } 23 | } 24 | 25 | let addOptionProviders, removeOptionProviders, Disposable 26 | 27 | function loadLuaConsumer () { 28 | if (!addOptionProviders || !removeOptionProviders) { 29 | let options = require('./options') 30 | 31 | addOptionProviders = options.addOptionProviders 32 | removeOptionProviders = options.removeOptionProviders 33 | } 34 | if (!Disposable) { 35 | let atom = require('atom') 36 | 37 | Disposable = atom.Disposable 38 | } 39 | } 40 | 41 | window.__LOG__ = window.localStorage.getItem('__LOG__') 42 | 43 | export default { 44 | activate () { 45 | this.idleCallbacks = new Set() 46 | 47 | let callbackID 48 | 49 | const installAutocompleteLuaDeps = () => { 50 | loadAutocompleteProvider() 51 | loadLuaProviders() 52 | loadLuaConsumer() 53 | } 54 | 55 | callbackID = window.requestIdleCallback(installAutocompleteLuaDeps) 56 | 57 | this.idleCallbacks.add(callbackID) 58 | }, 59 | 60 | deactivate () { 61 | this.idleCallbacks.forEach(id => 62 | window.cancelIdleCallback(id) 63 | ) 64 | 65 | this.idleCallbacks.clear() 66 | }, 67 | 68 | getProvider () { 69 | loadAutocompleteProvider() 70 | 71 | return new LuaProvider() 72 | }, 73 | 74 | getOptionProviders () { 75 | loadLuaProviders() 76 | 77 | return [ 78 | new EmptyOptionProvider(), 79 | new StdLibProvider(), 80 | new LuaCompleteRcProvider() 81 | ] 82 | }, 83 | 84 | onOptionProviders (providers) { 85 | loadLuaConsumer() 86 | 87 | if (!Array.isArray(providers)) { 88 | providers = [providers] 89 | } 90 | 91 | addOptionProviders(providers) 92 | return new Disposable(() => removeOptionProviders(providers)) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /lib/module-cache.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | import path from 'path' 4 | import fs from 'fs' 5 | 6 | const promisify = f => (...args) => 7 | new Promise((resolve, reject) => { 8 | f(...args, (err, result) => { 9 | if (err) { 10 | reject(err) 11 | } else { 12 | resolve(result) 13 | } 14 | }) 15 | }) 16 | 17 | const open = promisify(fs.open.bind(fs)) 18 | const readFile = promisify(fs.readFile.bind(fs)) 19 | const fstat = promisify(fs.fstat.bind(fs)) 20 | 21 | export default class ModuleCache { 22 | fileCache = {} 23 | constructor (options) { 24 | const cwd = options.cwd 25 | this.paths = (options.packagePath || path.join('.', '?.lua')) 26 | .split(';') 27 | .filter(p => p) // Remove potentially empty entries caused by a dangling ; 28 | .map(p => path.resolve(cwd, p)) 29 | } 30 | 31 | _getFile = async (moduleName) => { 32 | const modulePathName = moduleName.replace(/\./g, path.sep) 33 | for (let i = 0, n = this.paths.length; i < n; i++) { 34 | let fd 35 | try { 36 | const fileName = this.paths[i].replace(/\?/g, modulePathName) 37 | fd = await open(fileName, 'r') 38 | const stat = await fstat(fd) 39 | const data = await readFile(fd) 40 | return { data, stat } 41 | } catch (ex) { 42 | } finally { 43 | if (fd !== undefined) { fs.close(fd) } 44 | } 45 | } 46 | } 47 | 48 | get = async (moduleName, analyse) => { 49 | const fileObj = await this._getFile(moduleName) 50 | if (!fileObj) { return } 51 | return await analyse(fileObj.data) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/options/empty.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | const empty = { 4 | global: { type: 'table', fields: {} } 5 | } 6 | 7 | export default class EmptyOptionProvider { 8 | priority = 0; 9 | 10 | getOptions () { 11 | return { options: empty } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/options/index.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | import includes from 'lodash.includes' 4 | import { 5 | tableNew, booleanNew, functionNew, numberNew, unknownNew, nilNew, 6 | tableSet, tableSetMetatable, tableGet, tableGetMetatable, tableRevertAndUnfreeze, 7 | mergeTypeKnowledge, typeDefDeepClone 8 | } from '../typedefs' 9 | 10 | function crawlAndRevive (typeDef, namedTypes, setter) { 11 | if (!typeDef) { return } 12 | switch (typeDef.type) { 13 | case 'ref': 14 | setter(namedTypes[typeDef.name]) 15 | break 16 | case 'table': 17 | crawlAndRevive(typeDef.metatable, namedTypes, v => { typeDef.metatable = v }) 18 | for (let key in typeDef.fields) { 19 | crawlAndRevive(typeDef.fields[key], namedTypes, v => { typeDef.fields[key] = v }) 20 | } 21 | break 22 | case 'function': 23 | if (typeDef.argTypes) { 24 | typeDef.argTypes.forEach((argType, index) => { 25 | crawlAndRevive(argType, namedTypes, v => { typeDef.argTypes[index] = v }) 26 | }) 27 | } 28 | if (typeDef.returnTypes) { 29 | typeDef.returnTypes.forEach((retType, index) => { 30 | crawlAndRevive(retType, namedTypes, v => { typeDef.returnTypes[index] = v }) 31 | }) 32 | } 33 | break 34 | } 35 | } 36 | 37 | function reviveOptions (options) { 38 | if (!options || !options.namedTypes) { return options } 39 | let namedTypes = options.namedTypes 40 | crawlAndRevive(options.global, namedTypes, v => { options.global = v }) 41 | for (let key in namedTypes) { 42 | crawlAndRevive(namedTypes[key], namedTypes, v => { namedTypes[key] = v }) 43 | } 44 | delete options.namedTypes 45 | return options 46 | } 47 | 48 | function mergeOptions (previousOptions, newOptions) { 49 | const newGlobal = newOptions.global 50 | const previousGlobal = previousOptions.global 51 | const mergedOptions = Object.assign({}, previousOptions, newOptions) 52 | tableRevertAndUnfreeze(newGlobal) 53 | const mergedGlobal = mergeTypeKnowledge( 54 | typeDefDeepClone(newGlobal), 55 | typeDefDeepClone(previousGlobal) 56 | ) 57 | if (mergedGlobal) { mergedOptions.global = mergedGlobal } 58 | return mergedOptions 59 | } 60 | 61 | function mergeOptionsCached (previousOptions, newOptions, cache, merger) { 62 | if (cache.newOptions === newOptions && cache.previousOptions === previousOptions) { 63 | return cache 64 | } 65 | const options = utils.mergeOptions(previousOptions, newOptions) 66 | if (merger) { merger(options, previousOptions, newOptions) } 67 | return { options, newOptions, previousOptions } 68 | } 69 | 70 | const utils = { reviveOptions, mergeOptions, mergeOptionsCached, tableNew, booleanNew, functionNew, numberNew, unknownNew, nilNew, tableSet, tableSetMetatable, tableGet, tableGetMetatable, mergeTypeKnowledge } 71 | 72 | let providers = [] 73 | 74 | export function addOptionProviders (v) { 75 | v.forEach(provider => { 76 | providers.push({ 77 | provider, 78 | cache: {} 79 | }) 80 | }) 81 | } 82 | 83 | export function removeOptionProviders (v) { 84 | providers = providers.filter(p => !includes(v, p.provider)) 85 | v.forEach(provider => provider.dispose && provider.dispose()) 86 | } 87 | 88 | export default function getOptions (request) { 89 | providers.sort((a, b) => b.provider.priority - a.provider.priority) 90 | const chainProviders = (index) => { 91 | const providerSpec = providers[index] 92 | if (!providerSpec) { return () => ({}) } 93 | return async function () { 94 | const nextGetOptions = chainProviders(index + 1) 95 | const cacheKey = request.filePath 96 | const cacheEntry = providerSpec.cache[cacheKey] || {} 97 | const newCacheEntry = (await providerSpec.provider.getOptions(request, nextGetOptions, utils, cacheEntry)) 98 | providerSpec.cache[cacheKey] = newCacheEntry 99 | return newCacheEntry.options 100 | } 101 | } 102 | return Promise.resolve(chainProviders(0)()) 103 | } 104 | -------------------------------------------------------------------------------- /lib/options/luacompleterc.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | import path from 'path' 4 | import fs from 'fs' 5 | import jsonic from 'jsonic' 6 | 7 | export default class LuaCompleteRcProvider { 8 | priority = 10; 9 | fileCache = {} 10 | 11 | getFileData = async function (fileName, modifDate, reviveOptions) { 12 | const entry = this.fileCache[fileName] 13 | const modifTime = modifDate.getTime() 14 | if (entry && entry.modifTime >= modifTime) { 15 | return entry.data 16 | } 17 | 18 | const rawData = await (new Promise((resolve, reject) => { 19 | fs.readFile(fileName, 'utf8', (err, stats) => { 20 | if (err) { reject(err) } else { resolve(stats) } 21 | }) 22 | })) 23 | 24 | const data = reviveOptions(jsonic(rawData)) 25 | const cwd = path.dirname(fileName) 26 | data.cwd = data.cwd ? path.resolve(cwd, data.cwd) : cwd 27 | this.fileCache[fileName] = { modifTime, data } 28 | return data 29 | } 30 | 31 | getOptions = async function (request, getPreviousOptions, utils, cache) { 32 | const previousOptionsPromise = getPreviousOptions() 33 | try { 34 | let filePath = request.editor.getBuffer().getPath() 35 | let rcPath = null 36 | let stat = null 37 | 38 | if (!filePath) { 39 | return { options: (await previousOptionsPromise) } 40 | } 41 | 42 | while (true) { 43 | const dirName = path.dirname(filePath) 44 | if (dirName === filePath) { break } 45 | filePath = dirName 46 | 47 | const _rcPath = path.join(dirName, '.luacompleterc') 48 | stat = await (new Promise((resolve, reject) => { 49 | fs.stat(_rcPath, (err, stats) => { 50 | if (err) { reject(err) } else { resolve(stats) } 51 | }) 52 | }).catch(err => { 53 | if (err.code === 'ENOENT') { return null } 54 | throw err 55 | })) 56 | 57 | if (stat && stat.isFile()) { 58 | rcPath = _rcPath 59 | break 60 | } 61 | } 62 | 63 | if (!rcPath) { 64 | return { options: (await previousOptionsPromise) } 65 | } 66 | 67 | const newOptions = await this.getFileData(rcPath, stat.mtime, utils.reviveOptions) 68 | const previousOptions = await previousOptionsPromise 69 | return utils.mergeOptionsCached(previousOptions, newOptions, cache) 70 | } catch (ex) { 71 | __LOG__ && console.error(ex) 72 | return { options: (await previousOptionsPromise) } 73 | } 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /lib/options/stdlib.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | import config from '../config' 4 | 5 | function getOptions (luaVersion) { 6 | switch (luaVersion) { 7 | case '5.1': 8 | return require('../stdlib/5_1.json') 9 | case '5.2': 10 | return require('../stdlib/5_2.json') 11 | case '5.3': 12 | return require('../stdlib/5_3.json') 13 | case '5.4': 14 | return require('../stdlib/5_4.json') 15 | case 'luajit-2.0': 16 | return require('../stdlib/luajit-2_0.json') 17 | } 18 | } 19 | 20 | const optionsCache = {} 21 | function getCachedOptions (luaVersion, reviveOptions) { 22 | const cachedValue = optionsCache[luaVersion] 23 | if (cachedValue) { return cachedValue } 24 | const options = reviveOptions(getOptions(luaVersion)) 25 | if (!options) { return } 26 | optionsCache[luaVersion] = options 27 | return options 28 | } 29 | 30 | export default class StdLibProvider { 31 | priority = 100; 32 | 33 | getOptions = async function (request, getPreviousOptions, utils, cache) { 34 | const previousOptions = await getPreviousOptions() 35 | const luaVersion = previousOptions.luaVersion || config.luaVersion || '5.2' 36 | const stdOptions = getCachedOptions(luaVersion, utils.reviveOptions) 37 | if (!stdOptions) { return { options: previousOptions } } 38 | return utils.mergeOptionsCached(previousOptions, stdOptions, cache) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/provider.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Autocomplete+ provider 5 | */ 6 | 7 | import Analysis from './analysis' 8 | import getOptions from './options' 9 | import config, { configObserve, configDispose } from './config' 10 | import path from 'path' 11 | 12 | function getFilePath (request) { 13 | let p 14 | const buffer = request.editor.getBuffer() 15 | p = buffer.getPath() 16 | if (p) { return [ p, window.atom.project.relativizePath(p)[0] ] } 17 | const madeUpName = buffer.madeUpName = buffer.madeUpName || `untitled-${Math.round(10000 * Math.random())}.lua` 18 | const rootDir = window.atom.project.rootDirectories[0] 19 | if (p) { return [ path.join(rootDir.getPath(), madeUpName), rootDir.getPath() ] } 20 | return [ path.join(process.cwd(), madeUpName), null ] 21 | } 22 | 23 | export default class LuaProvider { 24 | selector = '.source.lua'; 25 | disableForSelector = '.source.lua .comment'; 26 | inclusionPriority = 1; 27 | excludeLowerPriority = false; 28 | disposeables = []; 29 | 30 | constructor () { 31 | __LOG__ && console.log('new LuaProvider()') 32 | this.disposeables.push(window.atom.config.observe('autocomplete-lua.excludeLowerPriority', (value) => { 33 | this.excludeLowerPriority = value 34 | })) 35 | this.disposeables.push(window.atom.config.observe('autocomplete-lua.inclusionPriority', (value) => { 36 | this.inclusionPriority = value 37 | })) 38 | configObserve() 39 | } 40 | 41 | dispose () { 42 | this.disposeables.forEach(d => d.dispose()) 43 | this.disposeables.length = 0 44 | configDispose() 45 | } 46 | 47 | getSuggestions = async function (request) { 48 | const buffer = request.editor.getBuffer() 49 | let prefix = request.prefix 50 | const cursorIndex = buffer.characterIndexForPosition(request.bufferPosition) 51 | let charsToPrefix = cursorIndex - prefix.length 52 | 53 | prefix = prefix.replace(/\s*$/, '') // trim from back 54 | const prefLen = prefix.length 55 | prefix = prefix.replace(/^\s*/, '') // trim from front 56 | charsToPrefix += prefLen - prefix.length 57 | 58 | // is there a cleaner way of treating this? 59 | if (prefix === '.' || prefix === ':') { 60 | prefix = '' 61 | charsToPrefix++ 62 | } else { 63 | // we don't do untriggered 0-length completions 64 | if (!request.activatedManually && prefix.length === 0) { 65 | return [] 66 | } 67 | } 68 | 69 | __LOG__ && console.log('suggestions', request, prefix) 70 | 71 | const textInIndexRange = (a, b) => buffer.getTextInRange([ 72 | buffer.positionForCharacterIndex(a), 73 | buffer.positionForCharacterIndex(b) 74 | ]) 75 | const dotEndPos = buffer.positionForCharacterIndex(charsToPrefix) 76 | const dotLine = buffer.getTextInRange([[dotEndPos.row, 0], dotEndPos]) 77 | const dot = dotLine.match(/([^\s])?\s*$/)[1] 78 | 79 | if (!request.activatedManually && dot !== '.' && dot !== ':' && prefix.length < Math.max(1, config.minCharsPrefix)) { 80 | return [] 81 | } 82 | 83 | const [ filePath, projectPath ] = getFilePath(request) 84 | request.filePath = filePath 85 | const options = await getOptions(request) 86 | options.cwd = options.cwd || projectPath || path.dirname(filePath) 87 | 88 | const analysis = new Analysis(options, { prefix, charsToPrefix, dot }) 89 | 90 | try { 91 | analysis.write(textInIndexRange(0, charsToPrefix)) 92 | 93 | if (dot === '.' || dot === ':') { 94 | analysis.write('__prefix_placeholder__()') 95 | } else { 96 | analysis.write('__prefix_placeholder__.__prefix_placeholder__()') 97 | } 98 | 99 | let continuePos = cursorIndex 100 | if (request.activatedManually) { 101 | let nextChar = textInIndexRange(cursorIndex, cursorIndex + 1) 102 | if (nextChar.replace(/\s/g, '').length !== 0) { // ...and the next char is non-whitespace 103 | continuePos = charsToPrefix // parse the prefix as well 104 | } 105 | } 106 | 107 | analysis.end(textInIndexRange(continuePos, Infinity)) 108 | } catch (ex) { 109 | if (__LOG__) { console.error(ex) } 110 | } 111 | 112 | return await analysis.solveQuery() 113 | } 114 | }; 115 | -------------------------------------------------------------------------------- /lib/resolve.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Functions for resolving the types of AST nodes 5 | */ 6 | 7 | import { 8 | tableNew, functionNew, stringNew, numberNew, booleanNew, nilNew, unknownNew, 9 | tableResolve, tableSet, mergeTypeKnowledge 10 | } from './typedefs' 11 | 12 | export function nodeGetReturnTypes (nodes, returnTypes = []) { 13 | nodes.forEach(node => { 14 | switch (node.type) { 15 | case 'ReturnStatement': 16 | node.arguments.forEach((arg, index) => { 17 | returnTypes[index] = mergeTypeKnowledge(returnTypes[index], nodeGetType(arg)) 18 | }) 19 | break 20 | case 'IfStatement': 21 | node.clauses.forEach(clause => { 22 | nodeGetReturnTypes(clause.body, returnTypes) 23 | }) 24 | break 25 | case 'ForNumericStatement': 26 | case 'ForGenericStatement': 27 | case 'WhileStatement': 28 | case 'RepeatStatement': 29 | nodeGetReturnTypes(node.body, returnTypes) 30 | break 31 | } 32 | }) 33 | return returnTypes 34 | } 35 | 36 | export function identifierScope (node) { 37 | if (node.isLocal === true) { 38 | return node.scope 39 | } 40 | if (node.isLocal === false) { 41 | return node.globalScope 42 | } 43 | // if isLocal is undefined, it's not a symbol, but maybe an index 44 | } 45 | 46 | export function nodeGetType (node, multipleTypes) { 47 | if (!node || node.isPlaceholder) { return } 48 | const type = node.type 49 | 50 | if (type === 'Identifier') { 51 | return tableResolve(identifierScope(node), node.name) 52 | } 53 | if (type === 'IndexExpression') { 54 | if (node.index.type !== 'StringLiteral') { return } 55 | const baseType = nodeGetType(node.base) 56 | if (!baseType) { return } 57 | return tableResolve(baseType, node.index.value) 58 | } 59 | if (type === 'MemberExpression') { 60 | if (node.identifier.type !== 'Identifier') { return } 61 | const baseType = nodeGetType(node.base) 62 | if (!baseType) { return } 63 | return tableResolve(baseType, node.identifier.name) 64 | } 65 | if (type === 'NumericLiteral') { return numberNew() } 66 | if (type === 'StringLiteral') { return stringNew() } 67 | if (type === 'BooleanLiteral') { return booleanNew() } 68 | if (type === 'NilLiteral') { return nilNew() } 69 | if (type === 'FunctionDeclaration') { 70 | const func = functionNew() 71 | const args = [] 72 | if ( 73 | node.identifier && 74 | node.identifier.type === 'MemberExpression' && 75 | node.identifier.indexer === ':' 76 | ) { 77 | args.push({ name: 'self' }) 78 | } 79 | node.parameters.forEach(param => { 80 | args.push({ 81 | name: param.type === 'Identifier' ? param.name : `arg${args.length + 1}` 82 | }) 83 | }) 84 | func.args = args 85 | func.returnTypes = nodeGetReturnTypes(node.body) 86 | return func 87 | } 88 | if (type === 'TableConstructorExpression') { 89 | const table = tableNew() 90 | node.fields.forEach(field => { 91 | if (field.type === 'TableKeyString' || field.type === 'TableKey') { 92 | let key = null 93 | if (field.key.type === 'Identifier') { key = field.key.name } 94 | if (field.key.type === 'StringLiteral') { key = field.key.value } 95 | if (!key) { return } 96 | tableSet(table, key, nodeGetType(field.value) || unknownNew()) 97 | } 98 | }) 99 | return table 100 | } 101 | if (node.requireCache) { 102 | const entry = node.requireCache[node.requireValue] 103 | if (!entry) { return } 104 | const { returnTypes } = entry 105 | return multipleTypes ? returnTypes : returnTypes[0] 106 | } 107 | if ( 108 | type === 'CallExpression' || 109 | type === 'StringCallExpression' 110 | ) { 111 | const funcType = nodeGetType(node.base) 112 | if (!funcType) { return } 113 | const returnTypes = funcType.returnTypes 114 | if (!returnTypes) { return } 115 | return multipleTypes ? returnTypes : returnTypes[0] 116 | } 117 | } 118 | 119 | export function getLValue (node) { 120 | if (!node) { return } 121 | const type = node.type 122 | 123 | if (type === 'IndexExpression') { 124 | if (node.index.type !== 'StringLiteral') { return } 125 | const baseType = nodeGetType(node.base) 126 | if (!baseType) { return } 127 | const key = node.index.value 128 | const table = tableResolve(baseType, key, true) || baseType 129 | return { table, key } 130 | } 131 | if (type === 'MemberExpression') { 132 | if (node.identifier.type !== 'Identifier') { return } 133 | if (node.identifier.isPlaceholder) { return } 134 | const baseType = nodeGetType(node.base) 135 | if (!baseType) { return } 136 | const key = node.identifier.name 137 | const table = tableResolve(baseType, key, true) || baseType 138 | return { table, key } 139 | } 140 | if (type === 'Identifier') { 141 | if (node.isPlaceholder) { return } 142 | const scope = identifierScope(node) 143 | const table = tableResolve(scope, node.name, true) || scope 144 | return { table, key: node.name } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /lib/stdlib/5_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "global": { 3 | "type": "table", 4 | "fields": { 5 | "_VERSION": { 6 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-_VERSION", 7 | "description": "A global variable (not a function) that holds a string containing the current interpreter version. The current contents of this variable is \"Lua 5.1\".", 8 | "type": "string" 9 | }, 10 | "assert": { 11 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-assert", 12 | "description": "Issues an error when the value of its argument v is false (i.e., nil or false); otherwise, returns all its arguments. message is an error message; when absent, it defaults to \"assertion failed!\"", 13 | "type": "function", 14 | "args": [ 15 | { 16 | "name": "v" 17 | } 18 | ], 19 | "argsDisplay": "v [, message]" 20 | }, 21 | "collectgarbage": { 22 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-collectgarbage", 23 | "description": "This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:", 24 | "type": "function", 25 | "args": [], 26 | "argsDisplay": "[opt [, arg]]" 27 | }, 28 | "dofile": { 29 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-dofile", 30 | "description": "Opens the named file and executes its contents as a Lua chunk. When called without arguments, dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller (that is, dofile does not run in protected mode).", 31 | "type": "function", 32 | "args": [], 33 | "argsDisplay": "[filename]" 34 | }, 35 | "error": { 36 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-error", 37 | "description": "Terminates the last protected function called and returns message as the error message. Function error never returns.", 38 | "type": "function", 39 | "args": [ 40 | { 41 | "name": "message" 42 | } 43 | ], 44 | "argsDisplay": "message [, level]" 45 | }, 46 | "getfenv": { 47 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-getfenv", 48 | "description": "Returns the current environment in use by the function. f can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling getfenv. If the given function is not a Lua function, or if f is 0, getfenv returns the global environment. The default for f is 1.", 49 | "type": "function", 50 | "args": [], 51 | "argsDisplay": "[f]" 52 | }, 53 | "getmetatable": { 54 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-getmetatable", 55 | "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.", 56 | "type": "function", 57 | "args": [ 58 | { 59 | "name": "object" 60 | } 61 | ], 62 | "argsDisplay": "object" 63 | }, 64 | "ipairs": { 65 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-ipairs", 66 | "description": "Returns three values: an iterator function, the table t, and 0, so that the construction", 67 | "type": "function", 68 | "args": [ 69 | { 70 | "name": "t" 71 | } 72 | ], 73 | "argsDisplay": "t" 74 | }, 75 | "load": { 76 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-load", 77 | "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.", 78 | "type": "function", 79 | "args": [ 80 | { 81 | "name": "func" 82 | } 83 | ], 84 | "argsDisplay": "func [, chunkname]" 85 | }, 86 | "loadfile": { 87 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-loadfile", 88 | "description": "Similar to load, but gets the chunk from file filename or from the standard input, if no file name is given.", 89 | "type": "function", 90 | "args": [], 91 | "argsDisplay": "[filename]" 92 | }, 93 | "loadstring": { 94 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-loadstring", 95 | "description": "Similar to load, but gets the chunk from the given string.", 96 | "type": "function", 97 | "args": [ 98 | { 99 | "name": "string" 100 | } 101 | ], 102 | "argsDisplay": "string [, chunkname]" 103 | }, 104 | "module": { 105 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-module", 106 | "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.", 107 | "type": "function", 108 | "args": [ 109 | { 110 | "name": "name" 111 | } 112 | ], 113 | "argsDisplay": "name [, ···]" 114 | }, 115 | "next": { 116 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-next", 117 | "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.", 118 | "type": "function", 119 | "args": [ 120 | { 121 | "name": "table" 122 | } 123 | ], 124 | "argsDisplay": "table [, index]" 125 | }, 126 | "pairs": { 127 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-pairs", 128 | "description": "Returns three values: the next function, the table t, and nil, so that the construction", 129 | "type": "function", 130 | "args": [ 131 | { 132 | "name": "t" 133 | } 134 | ], 135 | "argsDisplay": "t" 136 | }, 137 | "pcall": { 138 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-pcall", 139 | "description": "Calls function f with the given arguments in protected mode. This means that any error inside 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.", 140 | "type": "function", 141 | "args": [ 142 | { 143 | "name": "f" 144 | }, 145 | { 146 | "name": "arg1" 147 | } 148 | ], 149 | "argsDisplay": "f, arg1, ···" 150 | }, 151 | "print": { 152 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-print", 153 | "description": "Receives any number of arguments, and prints their values to stdout, using the tostring function to convert them to strings. print is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For formatted output, use string.format.", 154 | "type": "function", 155 | "args": [], 156 | "argsDisplay": "···" 157 | }, 158 | "rawequal": { 159 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-rawequal", 160 | "description": "Checks whether v1 is equal to v2, without invoking any metamethod. Returns a boolean.", 161 | "type": "function", 162 | "args": [ 163 | { 164 | "name": "v1" 165 | }, 166 | { 167 | "name": "v2" 168 | } 169 | ], 170 | "argsDisplay": "v1, v2" 171 | }, 172 | "rawget": { 173 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-rawget", 174 | "description": "Gets the real value of table[index], without invoking any metamethod. table must be a table; index may be any value.", 175 | "type": "function", 176 | "args": [ 177 | { 178 | "name": "table" 179 | }, 180 | { 181 | "name": "index" 182 | } 183 | ], 184 | "argsDisplay": "table, index" 185 | }, 186 | "rawset": { 187 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-rawset", 188 | "description": "Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil, and value any Lua value.", 189 | "type": "function", 190 | "args": [ 191 | { 192 | "name": "table" 193 | }, 194 | { 195 | "name": "index" 196 | }, 197 | { 198 | "name": "value" 199 | } 200 | ], 201 | "argsDisplay": "table, index, value" 202 | }, 203 | "require": { 204 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-require", 205 | "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.", 206 | "type": "function", 207 | "args": [ 208 | { 209 | "name": "modname" 210 | } 211 | ], 212 | "argsDisplay": "modname" 213 | }, 214 | "select": { 215 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-select", 216 | "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.", 217 | "type": "function", 218 | "args": [ 219 | { 220 | "name": "index" 221 | } 222 | ], 223 | "argsDisplay": "index, ···" 224 | }, 225 | "setfenv": { 226 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-setfenv", 227 | "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 1 is the function calling setfenv. setfenv returns the given function.", 228 | "type": "function", 229 | "args": [ 230 | { 231 | "name": "f" 232 | }, 233 | { 234 | "name": "table" 235 | } 236 | ], 237 | "argsDisplay": "f, table" 238 | }, 239 | "setmetatable": { 240 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-setmetatable", 241 | "description": "Sets the metatable for the given table. (You cannot change the metatable of other types from Lua, only from C.) If metatable is nil, removes the metatable of the given table. If the original metatable has a \"__metatable\" field, raises an error.", 242 | "type": "function", 243 | "args": [ 244 | { 245 | "name": "table" 246 | }, 247 | { 248 | "name": "metatable" 249 | } 250 | ], 251 | "argsDisplay": "table, metatable" 252 | }, 253 | "tonumber": { 254 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-tonumber", 255 | "description": "Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.", 256 | "type": "function", 257 | "args": [ 258 | { 259 | "name": "e" 260 | } 261 | ], 262 | "argsDisplay": "e [, base]" 263 | }, 264 | "tostring": { 265 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-tostring", 266 | "description": "Receives an argument of any type and converts it to a string in a reasonable format. For complete control of how numbers are converted, use string.format.", 267 | "type": "function", 268 | "args": [ 269 | { 270 | "name": "e" 271 | } 272 | ], 273 | "argsDisplay": "e" 274 | }, 275 | "type": { 276 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-type", 277 | "description": "Returns the type of its only argument, coded as a string. The possible results of this function are \"nil\" (a string, not the value nil), \"number\", \"string\", \"boolean\", \"table\", \"function\", \"thread\", and \"userdata\".", 278 | "type": "function", 279 | "args": [ 280 | { 281 | "name": "v" 282 | } 283 | ], 284 | "argsDisplay": "v" 285 | }, 286 | "unpack": { 287 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-unpack", 288 | "description": "Returns the elements from the given table. This function is equivalent to return list[i], list[i+1], ···, list[j]", 289 | "type": "function", 290 | "args": [ 291 | { 292 | "name": "list" 293 | } 294 | ], 295 | "argsDisplay": "list [, i [, j]]" 296 | }, 297 | "xpcall": { 298 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-xpcall", 299 | "description": "This function is similar to pcall, except that you can set a new error handler.", 300 | "type": "function", 301 | "args": [ 302 | { 303 | "name": "f" 304 | }, 305 | { 306 | "name": "err" 307 | } 308 | ], 309 | "argsDisplay": "f, err" 310 | }, 311 | "coroutine": { 312 | "link": "https://www.lua.org/manual/5.1/manual.html#5.2", 313 | "description": "The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. See §2.11 for a general description of coroutines.", 314 | "type": "table", 315 | "fields": { 316 | "create": { 317 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.create", 318 | "description": "Creates a new coroutine, with body f. f must be a Lua function. Returns this new coroutine, an object with type \"thread\".", 319 | "type": "function", 320 | "args": [ 321 | { 322 | "name": "f" 323 | } 324 | ], 325 | "argsDisplay": "f" 326 | }, 327 | "resume": { 328 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.resume", 329 | "description": "Starts or continues the execution of coroutine co. The first time you resume a coroutine, it starts running its body. The values val1, ··· are passed as the arguments to the body function. If the coroutine has yielded, resume restarts it; the values val1, ··· are passed as the results from the yield.", 330 | "type": "function", 331 | "args": [ 332 | { 333 | "name": "co" 334 | } 335 | ], 336 | "argsDisplay": "co [, val1, ···]" 337 | }, 338 | "running": { 339 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.running", 340 | "description": "Returns the running coroutine, or nil when called by the main thread.", 341 | "type": "function", 342 | "args": [], 343 | "argsDisplay": "" 344 | }, 345 | "status": { 346 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.status", 347 | "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.", 348 | "type": "function", 349 | "args": [ 350 | { 351 | "name": "co" 352 | } 353 | ], 354 | "argsDisplay": "co" 355 | }, 356 | "wrap": { 357 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.wrap", 358 | "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.", 359 | "type": "function", 360 | "args": [ 361 | { 362 | "name": "f" 363 | } 364 | ], 365 | "argsDisplay": "f" 366 | }, 367 | "yield": { 368 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-coroutine.yield", 369 | "description": "Suspends the execution of the calling coroutine. The coroutine cannot be running a C function, a metamethod, or an iterator. Any arguments to yield are passed as extra results to resume.", 370 | "type": "function", 371 | "args": [], 372 | "argsDisplay": "···" 373 | } 374 | } 375 | }, 376 | "debug": { 377 | "link": "https://www.lua.org/manual/5.1/manual.html#5.9", 378 | "description": "This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. The functions provided here should be used exclusively for debugging and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: they can be very slow. Moreover, several of these functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or that userdata metatables cannot be changed by Lua code) and therefore can compromise otherwise secure code.", 379 | "type": "table", 380 | "fields": { 381 | "debug": { 382 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.debug", 383 | "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.", 384 | "type": "function", 385 | "args": [], 386 | "argsDisplay": "" 387 | }, 388 | "getfenv": { 389 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getfenv", 390 | "description": "Returns the environment of object o.", 391 | "type": "function", 392 | "args": [ 393 | { 394 | "name": "o" 395 | } 396 | ], 397 | "argsDisplay": "o" 398 | }, 399 | "gethook": { 400 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.gethook", 401 | "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).", 402 | "type": "function", 403 | "args": [], 404 | "argsDisplay": "[thread]" 405 | }, 406 | "getinfo": { 407 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo", 408 | "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 0 is the current function (getinfo itself); level 1 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.", 409 | "type": "function", 410 | "args": [], 411 | "argsDisplay": "[thread,] function [, what]" 412 | }, 413 | "getlocal": { 414 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getlocal", 415 | "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 1, 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.)", 416 | "type": "function", 417 | "args": [], 418 | "argsDisplay": "[thread,] level, local" 419 | }, 420 | "getmetatable": { 421 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getmetatable", 422 | "description": "Returns the metatable of the given object or nil if it does not have a metatable.", 423 | "type": "function", 424 | "args": [ 425 | { 426 | "name": "object" 427 | } 428 | ], 429 | "argsDisplay": "object" 430 | }, 431 | "getregistry": { 432 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getregistry", 433 | "description": "Returns the registry table (see §3.5).", 434 | "type": "function", 435 | "args": [], 436 | "argsDisplay": "" 437 | }, 438 | "getupvalue": { 439 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.getupvalue", 440 | "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.", 441 | "type": "function", 442 | "args": [ 443 | { 444 | "name": "func" 445 | }, 446 | { 447 | "name": "up" 448 | } 449 | ], 450 | "argsDisplay": "func, up" 451 | }, 452 | "setfenv": { 453 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.setfenv", 454 | "description": "Sets the environment of the given object to the given table. Returns object.", 455 | "type": "function", 456 | "args": [ 457 | { 458 | "name": "object" 459 | }, 460 | { 461 | "name": "table" 462 | } 463 | ], 464 | "argsDisplay": "object, table" 465 | }, 466 | "sethook": { 467 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.sethook", 468 | "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:", 469 | "type": "function", 470 | "args": [], 471 | "argsDisplay": "[thread,] hook, mask [, count]" 472 | }, 473 | "setlocal": { 474 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.setlocal", 475 | "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.", 476 | "type": "function", 477 | "args": [], 478 | "argsDisplay": "[thread,] level, local, value" 479 | }, 480 | "setmetatable": { 481 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.setmetatable", 482 | "description": "Sets the metatable for the given object to the given table (which can be nil).", 483 | "type": "function", 484 | "args": [ 485 | { 486 | "name": "object" 487 | }, 488 | { 489 | "name": "table" 490 | } 491 | ], 492 | "argsDisplay": "object, table" 493 | }, 494 | "setupvalue": { 495 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.setupvalue", 496 | "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.", 497 | "type": "function", 498 | "args": [ 499 | { 500 | "name": "func" 501 | }, 502 | { 503 | "name": "up" 504 | }, 505 | { 506 | "name": "value" 507 | } 508 | ], 509 | "argsDisplay": "func, up, value" 510 | }, 511 | "traceback": { 512 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-debug.traceback", 513 | "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).", 514 | "type": "function", 515 | "args": [], 516 | "argsDisplay": "[thread,] [message [, level]]" 517 | } 518 | } 519 | }, 520 | "io": { 521 | "link": "https://www.lua.org/manual/5.1/manual.html#5.7", 522 | "description": "The I/O library provides two different styles for file manipulation. The first one uses implicit file descriptors; that is, there are operations to set a default input file and a default output file, and all input/output operations are over these default files. The second style uses explicit file descriptors.", 523 | "type": "table", 524 | "fields": { 525 | "close": { 526 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.close", 527 | "description": "Equivalent to file:close(). Without a file, closes the default output file.", 528 | "type": "function", 529 | "args": [], 530 | "argsDisplay": "[file]" 531 | }, 532 | "flush": { 533 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.flush", 534 | "description": "Equivalent to file:flush over the default output file.", 535 | "type": "function", 536 | "args": [], 537 | "argsDisplay": "" 538 | }, 539 | "input": { 540 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.input", 541 | "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.", 542 | "type": "function", 543 | "args": [], 544 | "argsDisplay": "[file]" 545 | }, 546 | "lines": { 547 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.lines", 548 | "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", 549 | "type": "function", 550 | "args": [], 551 | "argsDisplay": "[filename]" 552 | }, 553 | "open": { 554 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.open", 555 | "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.", 556 | "type": "function", 557 | "args": [ 558 | { 559 | "name": "filename" 560 | } 561 | ], 562 | "argsDisplay": "filename [, mode]", 563 | "returnTypes": [ 564 | { 565 | "type": "ref", 566 | "name": "file" 567 | } 568 | ] 569 | }, 570 | "output": { 571 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.output", 572 | "description": "Similar to io.input, but operates over the default output file.", 573 | "type": "function", 574 | "args": [], 575 | "argsDisplay": "[file]" 576 | }, 577 | "popen": { 578 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.popen", 579 | "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\").", 580 | "type": "function", 581 | "args": [ 582 | { 583 | "name": "prog" 584 | } 585 | ], 586 | "argsDisplay": "prog [, mode]", 587 | "returnTypes": [ 588 | { 589 | "type": "ref", 590 | "name": "file" 591 | } 592 | ] 593 | }, 594 | "read": { 595 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.read", 596 | "description": "Equivalent to io.input():read.", 597 | "type": "function", 598 | "args": [], 599 | "argsDisplay": "···" 600 | }, 601 | "stderr": { 602 | "type": "ref", 603 | "name": "file" 604 | }, 605 | "stdin": { 606 | "type": "ref", 607 | "name": "file" 608 | }, 609 | "stdout": { 610 | "type": "ref", 611 | "name": "file" 612 | }, 613 | "tmpfile": { 614 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.tmpfile", 615 | "description": "Returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.", 616 | "type": "function", 617 | "args": [], 618 | "argsDisplay": "", 619 | "returnTypes": [ 620 | { 621 | "type": "ref", 622 | "name": "file" 623 | } 624 | ] 625 | }, 626 | "type": { 627 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.type", 628 | "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.", 629 | "type": "function", 630 | "args": [ 631 | { 632 | "name": "obj" 633 | } 634 | ], 635 | "argsDisplay": "obj" 636 | }, 637 | "write": { 638 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-io.write", 639 | "description": "Equivalent to io.output():write.", 640 | "type": "function", 641 | "args": [], 642 | "argsDisplay": "···" 643 | } 644 | } 645 | }, 646 | "math": { 647 | "link": "https://www.lua.org/manual/5.1/manual.html#5.6", 648 | "description": "This library is an interface to the standard C math library. It provides all its functions inside the table math.", 649 | "type": "table", 650 | "fields": { 651 | "abs": { 652 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.abs", 653 | "description": "Returns the absolute value of x.", 654 | "type": "function", 655 | "args": [ 656 | { 657 | "name": "x" 658 | } 659 | ], 660 | "argsDisplay": "x" 661 | }, 662 | "acos": { 663 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.acos", 664 | "description": "Returns the arc cosine of x (in radians).", 665 | "type": "function", 666 | "args": [ 667 | { 668 | "name": "x" 669 | } 670 | ], 671 | "argsDisplay": "x" 672 | }, 673 | "asin": { 674 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.asin", 675 | "description": "Returns the arc sine of x (in radians).", 676 | "type": "function", 677 | "args": [ 678 | { 679 | "name": "x" 680 | } 681 | ], 682 | "argsDisplay": "x" 683 | }, 684 | "atan": { 685 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.atan", 686 | "description": "Returns the arc tangent of x (in radians).", 687 | "type": "function", 688 | "args": [ 689 | { 690 | "name": "x" 691 | } 692 | ], 693 | "argsDisplay": "x" 694 | }, 695 | "atan2": { 696 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.atan2", 697 | "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.)", 698 | "type": "function", 699 | "args": [ 700 | { 701 | "name": "y" 702 | }, 703 | { 704 | "name": "x" 705 | } 706 | ], 707 | "argsDisplay": "y, x" 708 | }, 709 | "ceil": { 710 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.ceil", 711 | "description": "Returns the smallest integer larger than or equal to x.", 712 | "type": "function", 713 | "args": [ 714 | { 715 | "name": "x" 716 | } 717 | ], 718 | "argsDisplay": "x" 719 | }, 720 | "cos": { 721 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.cos", 722 | "description": "Returns the cosine of x (assumed to be in radians).", 723 | "type": "function", 724 | "args": [ 725 | { 726 | "name": "x" 727 | } 728 | ], 729 | "argsDisplay": "x" 730 | }, 731 | "cosh": { 732 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.cosh", 733 | "description": "Returns the hyperbolic cosine of x.", 734 | "type": "function", 735 | "args": [ 736 | { 737 | "name": "x" 738 | } 739 | ], 740 | "argsDisplay": "x" 741 | }, 742 | "deg": { 743 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.deg", 744 | "description": "Returns the angle x (given in radians) in degrees.", 745 | "type": "function", 746 | "args": [ 747 | { 748 | "name": "x" 749 | } 750 | ], 751 | "argsDisplay": "x" 752 | }, 753 | "exp": { 754 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.exp", 755 | "description": "Returns the value ex.", 756 | "type": "function", 757 | "args": [ 758 | { 759 | "name": "x" 760 | } 761 | ], 762 | "argsDisplay": "x" 763 | }, 764 | "floor": { 765 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.floor", 766 | "description": "Returns the largest integer smaller than or equal to x.", 767 | "type": "function", 768 | "args": [ 769 | { 770 | "name": "x" 771 | } 772 | ], 773 | "argsDisplay": "x" 774 | }, 775 | "fmod": { 776 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.fmod", 777 | "description": "Returns the remainder of the division of x by y that rounds the quotient towards zero.", 778 | "type": "function", 779 | "args": [ 780 | { 781 | "name": "x" 782 | }, 783 | { 784 | "name": "y" 785 | } 786 | ], 787 | "argsDisplay": "x, y" 788 | }, 789 | "frexp": { 790 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.frexp", 791 | "description": "Returns m and e such that x = m2e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).", 792 | "type": "function", 793 | "args": [ 794 | { 795 | "name": "x" 796 | } 797 | ], 798 | "argsDisplay": "x" 799 | }, 800 | "huge": { 801 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.huge", 802 | "description": "The value HUGE_VAL, a value larger than or equal to any other numerical value.", 803 | "type": "unknown" 804 | }, 805 | "ldexp": { 806 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.ldexp", 807 | "description": "Returns m2e (e should be an integer).", 808 | "type": "function", 809 | "args": [ 810 | { 811 | "name": "m" 812 | }, 813 | { 814 | "name": "e" 815 | } 816 | ], 817 | "argsDisplay": "m, e" 818 | }, 819 | "log": { 820 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.log", 821 | "description": "Returns the natural logarithm of x.", 822 | "type": "function", 823 | "args": [ 824 | { 825 | "name": "x" 826 | } 827 | ], 828 | "argsDisplay": "x" 829 | }, 830 | "log10": { 831 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.log10", 832 | "description": "Returns the base-10 logarithm of x.", 833 | "type": "function", 834 | "args": [ 835 | { 836 | "name": "x" 837 | } 838 | ], 839 | "argsDisplay": "x" 840 | }, 841 | "max": { 842 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.max", 843 | "description": "Returns the maximum value among its arguments.", 844 | "type": "function", 845 | "args": [ 846 | { 847 | "name": "x" 848 | } 849 | ], 850 | "argsDisplay": "x, ···" 851 | }, 852 | "min": { 853 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.min", 854 | "description": "Returns the minimum value among its arguments.", 855 | "type": "function", 856 | "args": [ 857 | { 858 | "name": "x" 859 | } 860 | ], 861 | "argsDisplay": "x, ···" 862 | }, 863 | "modf": { 864 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.modf", 865 | "description": "Returns two numbers, the integral part of x and the fractional part of x.", 866 | "type": "function", 867 | "args": [ 868 | { 869 | "name": "x" 870 | } 871 | ], 872 | "argsDisplay": "x" 873 | }, 874 | "pi": { 875 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.pi", 876 | "description": "The value of pi.", 877 | "type": "number" 878 | }, 879 | "pow": { 880 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.pow", 881 | "description": "Returns xy. (You can also use the expression x^y to compute this value.)", 882 | "type": "function", 883 | "args": [ 884 | { 885 | "name": "x" 886 | }, 887 | { 888 | "name": "y" 889 | } 890 | ], 891 | "argsDisplay": "x, y" 892 | }, 893 | "rad": { 894 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.rad", 895 | "description": "Returns the angle x (given in degrees) in radians.", 896 | "type": "function", 897 | "args": [ 898 | { 899 | "name": "x" 900 | } 901 | ], 902 | "argsDisplay": "x" 903 | }, 904 | "random": { 905 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.random", 906 | "description": "This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.)", 907 | "type": "function", 908 | "args": [], 909 | "argsDisplay": "[m [, n]]" 910 | }, 911 | "randomseed": { 912 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.randomseed", 913 | "description": "Sets x as the \"seed\" for the pseudo-random generator: equal seeds produce equal sequences of numbers.", 914 | "type": "function", 915 | "args": [ 916 | { 917 | "name": "x" 918 | } 919 | ], 920 | "argsDisplay": "x" 921 | }, 922 | "sin": { 923 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.sin", 924 | "description": "Returns the sine of x (assumed to be in radians).", 925 | "type": "function", 926 | "args": [ 927 | { 928 | "name": "x" 929 | } 930 | ], 931 | "argsDisplay": "x" 932 | }, 933 | "sinh": { 934 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.sinh", 935 | "description": "Returns the hyperbolic sine of x.", 936 | "type": "function", 937 | "args": [ 938 | { 939 | "name": "x" 940 | } 941 | ], 942 | "argsDisplay": "x" 943 | }, 944 | "sqrt": { 945 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.sqrt", 946 | "description": "Returns the square root of x. (You can also use the expression x^0.5 to compute this value.)", 947 | "type": "function", 948 | "args": [ 949 | { 950 | "name": "x" 951 | } 952 | ], 953 | "argsDisplay": "x" 954 | }, 955 | "tan": { 956 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.tan", 957 | "description": "Returns the tangent of x (assumed to be in radians).", 958 | "type": "function", 959 | "args": [ 960 | { 961 | "name": "x" 962 | } 963 | ], 964 | "argsDisplay": "x" 965 | }, 966 | "tanh": { 967 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-math.tanh", 968 | "description": "Returns the hyperbolic tangent of x.", 969 | "type": "function", 970 | "args": [ 971 | { 972 | "name": "x" 973 | } 974 | ], 975 | "argsDisplay": "x" 976 | } 977 | } 978 | }, 979 | "os": { 980 | "link": "https://www.lua.org/manual/5.1/manual.html#5.8", 981 | "description": "This library is implemented through table os.", 982 | "type": "table", 983 | "fields": { 984 | "clock": { 985 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.clock", 986 | "description": "Returns an approximation of the amount in seconds of CPU time used by the program.", 987 | "type": "function", 988 | "args": [], 989 | "argsDisplay": "" 990 | }, 991 | "date": { 992 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.date", 993 | "description": "Returns a string or a table containing date and time, formatted according to the given string format.", 994 | "type": "function", 995 | "args": [], 996 | "argsDisplay": "[format [, time]]" 997 | }, 998 | "difftime": { 999 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.difftime", 1000 | "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.", 1001 | "type": "function", 1002 | "args": [ 1003 | { 1004 | "name": "t2" 1005 | }, 1006 | { 1007 | "name": "t1" 1008 | } 1009 | ], 1010 | "argsDisplay": "t2, t1" 1011 | }, 1012 | "execute": { 1013 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.execute", 1014 | "description": "This function is equivalent to the C function 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.", 1015 | "type": "function", 1016 | "args": [], 1017 | "argsDisplay": "[command]" 1018 | }, 1019 | "exit": { 1020 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.exit", 1021 | "description": "Calls the C function exit, with an optional code, to terminate the host program. The default value for code is the success code.", 1022 | "type": "function", 1023 | "args": [], 1024 | "argsDisplay": "[code]" 1025 | }, 1026 | "getenv": { 1027 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.getenv", 1028 | "description": "Returns the value of the process environment variable varname, or nil if the variable is not defined.", 1029 | "type": "function", 1030 | "args": [ 1031 | { 1032 | "name": "varname" 1033 | } 1034 | ], 1035 | "argsDisplay": "varname" 1036 | }, 1037 | "remove": { 1038 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.remove", 1039 | "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.", 1040 | "type": "function", 1041 | "args": [ 1042 | { 1043 | "name": "filename" 1044 | } 1045 | ], 1046 | "argsDisplay": "filename" 1047 | }, 1048 | "rename": { 1049 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.rename", 1050 | "description": "Renames file or directory named oldname to newname. If this function fails, it returns nil, plus a string describing the error.", 1051 | "type": "function", 1052 | "args": [ 1053 | { 1054 | "name": "oldname" 1055 | }, 1056 | { 1057 | "name": "newname" 1058 | } 1059 | ], 1060 | "argsDisplay": "oldname, newname" 1061 | }, 1062 | "setlocale": { 1063 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.setlocale", 1064 | "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.", 1065 | "type": "function", 1066 | "args": [ 1067 | { 1068 | "name": "locale" 1069 | } 1070 | ], 1071 | "argsDisplay": "locale [, category]" 1072 | }, 1073 | "time": { 1074 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.time", 1075 | "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).", 1076 | "type": "function", 1077 | "args": [], 1078 | "argsDisplay": "[table]" 1079 | }, 1080 | "tmpname": { 1081 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-os.tmpname", 1082 | "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.", 1083 | "type": "function", 1084 | "args": [], 1085 | "argsDisplay": "" 1086 | } 1087 | } 1088 | }, 1089 | "package": { 1090 | "link": "https://www.lua.org/manual/5.1/manual.html#5.3", 1091 | "description": "The package library provides basic facilities for loading and building modules in Lua. It exports two of its functions directly in the global environment: require and module. Everything else is exported in a table package.", 1092 | "type": "table", 1093 | "fields": { 1094 | "cpath": { 1095 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.cpath", 1096 | "description": "The path used by require to search for a C loader.", 1097 | "type": "unknown" 1098 | }, 1099 | "loaded": { 1100 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.loaded", 1101 | "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.", 1102 | "type": "unknown" 1103 | }, 1104 | "loaders": { 1105 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.loaders", 1106 | "description": "A table used by require to control how to load modules.", 1107 | "type": "unknown" 1108 | }, 1109 | "loadlib": { 1110 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.loadlib", 1111 | "description": "Dynamically links the host program with the C library libname. Inside this library, looks for a function funcname and returns this function as a C function. (So, funcname must follow the protocol (see lua_CFunction)).", 1112 | "type": "function", 1113 | "args": [ 1114 | { 1115 | "name": "libname" 1116 | }, 1117 | { 1118 | "name": "funcname" 1119 | } 1120 | ], 1121 | "argsDisplay": "libname, funcname" 1122 | }, 1123 | "path": { 1124 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.path", 1125 | "description": "The path used by require to search for a Lua loader.", 1126 | "type": "unknown" 1127 | }, 1128 | "preload": { 1129 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.preload", 1130 | "description": "A table to store loaders for specific modules (see require).", 1131 | "type": "unknown" 1132 | }, 1133 | "seeall": { 1134 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-package.seeall", 1135 | "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.", 1136 | "type": "function", 1137 | "args": [ 1138 | { 1139 | "name": "module" 1140 | } 1141 | ], 1142 | "argsDisplay": "module" 1143 | } 1144 | } 1145 | }, 1146 | "string": { 1147 | "link": "https://www.lua.org/manual/5.1/manual.html#5.4", 1148 | "description": "This library provides generic functions for string manipulation, such as finding and extracting substrings, and pattern matching. When indexing a string in Lua, the first character is at position 1 (not at 0, as in C). Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on.", 1149 | "type": "table", 1150 | "fields": { 1151 | "byte": { 1152 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.byte", 1153 | "description": "Returns the internal numerical codes of the characters s[i], s[i+1], ···, s[j]. The default value for i is 1; the default value for j is i.", 1154 | "type": "function", 1155 | "args": [ 1156 | { 1157 | "name": "s" 1158 | } 1159 | ], 1160 | "argsDisplay": "s [, i [, j]]" 1161 | }, 1162 | "char": { 1163 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.char", 1164 | "description": "Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.", 1165 | "type": "function", 1166 | "args": [], 1167 | "argsDisplay": "···" 1168 | }, 1169 | "dump": { 1170 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.dump", 1171 | "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.", 1172 | "type": "function", 1173 | "args": [ 1174 | { 1175 | "name": "function" 1176 | } 1177 | ], 1178 | "argsDisplay": "function" 1179 | }, 1180 | "find": { 1181 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.find", 1182 | "description": "Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain \"find substring\" operation, with no characters in pattern being considered \"magic\". Note that if plain is given, then init must be given as well.", 1183 | "type": "function", 1184 | "args": [ 1185 | { 1186 | "name": "s" 1187 | }, 1188 | { 1189 | "name": "pattern" 1190 | } 1191 | ], 1192 | "argsDisplay": "s, pattern [, init [, plain]]" 1193 | }, 1194 | "format": { 1195 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.format", 1196 | "description": "Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the printf family of standard C functions. The only differences are that the options/modifiers *, l, L, n, p, and h are not supported and that there is an extra option, q. The q option formats a string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. For instance, the call string.format('%q', 'a string with \"quotes\" and \\n new line')", 1197 | "type": "function", 1198 | "args": [ 1199 | { 1200 | "name": "formatstring" 1201 | } 1202 | ], 1203 | "argsDisplay": "formatstring, ···" 1204 | }, 1205 | "gmatch": { 1206 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.gmatch", 1207 | "description": "Returns an iterator function that, each time it is called, returns the next captures from pattern over string s. If pattern specifies no captures, then the whole match is produced in each call.", 1208 | "type": "function", 1209 | "args": [ 1210 | { 1211 | "name": "s" 1212 | }, 1213 | { 1214 | "name": "pattern" 1215 | } 1216 | ], 1217 | "argsDisplay": "s, pattern" 1218 | }, 1219 | "gsub": { 1220 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.gsub", 1221 | "description": "Returns a copy of s in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.", 1222 | "type": "function", 1223 | "args": [ 1224 | { 1225 | "name": "s" 1226 | }, 1227 | { 1228 | "name": "pattern" 1229 | }, 1230 | { 1231 | "name": "repl" 1232 | } 1233 | ], 1234 | "argsDisplay": "s, pattern, repl [, n]" 1235 | }, 1236 | "len": { 1237 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.len", 1238 | "description": "Receives a string and returns its length. The empty string \"\" has length 0. Embedded zeros are counted, so \"a\\000bc\\000\" has length 5.", 1239 | "type": "function", 1240 | "args": [ 1241 | { 1242 | "name": "s" 1243 | } 1244 | ], 1245 | "argsDisplay": "s" 1246 | }, 1247 | "lower": { 1248 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.lower", 1249 | "description": "Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.", 1250 | "type": "function", 1251 | "args": [ 1252 | { 1253 | "name": "s" 1254 | } 1255 | ], 1256 | "argsDisplay": "s" 1257 | }, 1258 | "match": { 1259 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.match", 1260 | "description": "Looks for the first match of pattern in the string s. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative.", 1261 | "type": "function", 1262 | "args": [ 1263 | { 1264 | "name": "s" 1265 | }, 1266 | { 1267 | "name": "pattern" 1268 | } 1269 | ], 1270 | "argsDisplay": "s, pattern [, init]" 1271 | }, 1272 | "rep": { 1273 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.rep", 1274 | "description": "Returns a string that is the concatenation of n copies of the string s.", 1275 | "type": "function", 1276 | "args": [ 1277 | { 1278 | "name": "s" 1279 | }, 1280 | { 1281 | "name": "n" 1282 | } 1283 | ], 1284 | "argsDisplay": "s, n" 1285 | }, 1286 | "reverse": { 1287 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.reverse", 1288 | "description": "Returns a string that is the string s reversed.", 1289 | "type": "function", 1290 | "args": [ 1291 | { 1292 | "name": "s" 1293 | } 1294 | ], 1295 | "argsDisplay": "s" 1296 | }, 1297 | "sub": { 1298 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.sub", 1299 | "description": "Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.", 1300 | "type": "function", 1301 | "args": [ 1302 | { 1303 | "name": "s" 1304 | }, 1305 | { 1306 | "name": "i" 1307 | } 1308 | ], 1309 | "argsDisplay": "s, i [, j]" 1310 | }, 1311 | "upper": { 1312 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-string.upper", 1313 | "description": "Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.", 1314 | "type": "function", 1315 | "args": [ 1316 | { 1317 | "name": "s" 1318 | } 1319 | ], 1320 | "argsDisplay": "s" 1321 | } 1322 | } 1323 | }, 1324 | "table": { 1325 | "link": "https://www.lua.org/manual/5.1/manual.html#5.5", 1326 | "description": "This library provides generic functions for table manipulation. It provides all its functions inside the table table.", 1327 | "type": "table", 1328 | "fields": { 1329 | "concat": { 1330 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-table.concat", 1331 | "description": "Given an array where all elements are strings or numbers, returns table[i]..sep..table[i+1] ··· sep..table[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table. If i is greater than j, returns the empty string.", 1332 | "type": "function", 1333 | "args": [ 1334 | { 1335 | "name": "table" 1336 | } 1337 | ], 1338 | "argsDisplay": "table [, sep [, i [, j]]]" 1339 | }, 1340 | "insert": { 1341 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-table.insert", 1342 | "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 §2.5.5), so that a call table.insert(t,x) inserts x at the end of table t.", 1343 | "type": "function", 1344 | "args": [ 1345 | { 1346 | "name": "table" 1347 | } 1348 | ], 1349 | "argsDisplay": "table, [pos,] value" 1350 | }, 1351 | "maxn": { 1352 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn", 1353 | "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.)", 1354 | "type": "function", 1355 | "args": [ 1356 | { 1357 | "name": "table" 1358 | } 1359 | ], 1360 | "argsDisplay": "table" 1361 | }, 1362 | "remove": { 1363 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-table.remove", 1364 | "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.", 1365 | "type": "function", 1366 | "args": [ 1367 | { 1368 | "name": "table" 1369 | } 1370 | ], 1371 | "argsDisplay": "table [, pos]" 1372 | }, 1373 | "sort": { 1374 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-table.sort", 1375 | "description": "Sorts table elements in a given order, in-place, from table[1] to table[n], where n is the length of the table. If comp is given, then it must be a function that receives two table elements, and returns true when the first is less than the second (so that not comp(a[i+1],a[i]) will be true after the sort). If comp is not given, then the standard Lua operator < is used instead.", 1376 | "type": "function", 1377 | "args": [ 1378 | { 1379 | "name": "table" 1380 | } 1381 | ], 1382 | "argsDisplay": "table [, comp]" 1383 | } 1384 | } 1385 | } 1386 | } 1387 | }, 1388 | "namedTypes": { 1389 | "file": { 1390 | "type": "table", 1391 | "fields": {}, 1392 | "metatable": { 1393 | "type": "table", 1394 | "fields": { 1395 | "__index": { 1396 | "type": "table", 1397 | "fields": { 1398 | "close": { 1399 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:close", 1400 | "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.", 1401 | "type": "function", 1402 | "args": [ 1403 | { 1404 | "name": "self" 1405 | } 1406 | ], 1407 | "argsDisplay": "self", 1408 | "argsDisplayOmitSelf": "" 1409 | }, 1410 | "flush": { 1411 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:flush", 1412 | "description": "Saves any written data to file.", 1413 | "type": "function", 1414 | "args": [ 1415 | { 1416 | "name": "self" 1417 | } 1418 | ], 1419 | "argsDisplay": "self", 1420 | "argsDisplayOmitSelf": "" 1421 | }, 1422 | "lines": { 1423 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:lines", 1424 | "description": "Returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction", 1425 | "type": "function", 1426 | "args": [ 1427 | { 1428 | "name": "self" 1429 | } 1430 | ], 1431 | "argsDisplay": "self", 1432 | "argsDisplayOmitSelf": "" 1433 | }, 1434 | "read": { 1435 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:read", 1436 | "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).", 1437 | "type": "function", 1438 | "args": [ 1439 | { 1440 | "name": "self" 1441 | } 1442 | ], 1443 | "argsDisplay": "self, ···", 1444 | "argsDisplayOmitSelf": "···" 1445 | }, 1446 | "seek": { 1447 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:seek", 1448 | "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:", 1449 | "type": "function", 1450 | "args": [ 1451 | { 1452 | "name": "self" 1453 | } 1454 | ], 1455 | "argsDisplay": "self, [whence] [, offset]", 1456 | "argsDisplayOmitSelf": "[whence] [, offset]" 1457 | }, 1458 | "setvbuf": { 1459 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:setvbuf", 1460 | "description": "Sets the buffering mode for an output file. There are three available modes:", 1461 | "type": "function", 1462 | "args": [ 1463 | { 1464 | "name": "self" 1465 | }, 1466 | { 1467 | "name": "mode" 1468 | } 1469 | ], 1470 | "argsDisplay": "self, mode [, size]", 1471 | "argsDisplayOmitSelf": "mode [, size]" 1472 | }, 1473 | "write": { 1474 | "link": "https://www.lua.org/manual/5.1/manual.html#pdf-file:write", 1475 | "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.", 1476 | "type": "function", 1477 | "args": [ 1478 | { 1479 | "name": "self" 1480 | } 1481 | ], 1482 | "argsDisplay": "self, ···", 1483 | "argsDisplayOmitSelf": "···" 1484 | } 1485 | } 1486 | } 1487 | } 1488 | } 1489 | } 1490 | } 1491 | } -------------------------------------------------------------------------------- /lib/stdlib/5_3.json: -------------------------------------------------------------------------------- 1 | { 2 | "global": { 3 | "type": "table", 4 | "fields": { 5 | "_VERSION": { 6 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-_VERSION", 7 | "description": "A global variable (not a function) that holds a string containing the running Lua version. The current value of this variable is \"Lua 5.3\".", 8 | "type": "string" 9 | }, 10 | "assert": { 11 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-assert", 12 | "description": "Calls error if the value of its argument v is false (i.e., nil or false); otherwise, returns all its arguments. In case of error, message is the error object; when absent, it defaults to \"assertion failed!\"", 13 | "type": "function", 14 | "args": [ 15 | { 16 | "name": "v" 17 | } 18 | ], 19 | "argsDisplay": "v [, message]" 20 | }, 21 | "collectgarbage": { 22 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-collectgarbage", 23 | "description": "This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:", 24 | "type": "function", 25 | "args": [], 26 | "argsDisplay": "[opt [, arg]]" 27 | }, 28 | "dofile": { 29 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-dofile", 30 | "description": "Opens the named file and executes its contents as a Lua chunk. When called without arguments, dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller (that is, dofile does not run in protected mode).", 31 | "type": "function", 32 | "args": [], 33 | "argsDisplay": "[filename]" 34 | }, 35 | "error": { 36 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-error", 37 | "description": "Terminates the last protected function called and returns message as the error object. Function error never returns.", 38 | "type": "function", 39 | "args": [ 40 | { 41 | "name": "message" 42 | } 43 | ], 44 | "argsDisplay": "message [, level]" 45 | }, 46 | "getmetatable": { 47 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-getmetatable", 48 | "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.", 49 | "type": "function", 50 | "args": [ 51 | { 52 | "name": "object" 53 | } 54 | ], 55 | "argsDisplay": "object" 56 | }, 57 | "ipairs": { 58 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-ipairs", 59 | "description": "Returns three values (an iterator function, the table t, and 0) so that the construction", 60 | "type": "function", 61 | "args": [ 62 | { 63 | "name": "t" 64 | } 65 | ], 66 | "argsDisplay": "t" 67 | }, 68 | "load": { 69 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-load", 70 | "description": "Loads a chunk.", 71 | "type": "function", 72 | "args": [ 73 | { 74 | "name": "chunk" 75 | } 76 | ], 77 | "argsDisplay": "chunk [, chunkname [, mode [, env]]]" 78 | }, 79 | "loadfile": { 80 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-loadfile", 81 | "description": "Similar to load, but gets the chunk from file filename or from the standard input, if no file name is given.", 82 | "type": "function", 83 | "args": [], 84 | "argsDisplay": "[filename [, mode [, env]]]" 85 | }, 86 | "next": { 87 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-next", 88 | "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.", 89 | "type": "function", 90 | "args": [ 91 | { 92 | "name": "table" 93 | } 94 | ], 95 | "argsDisplay": "table [, index]" 96 | }, 97 | "pairs": { 98 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-pairs", 99 | "description": "If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.", 100 | "type": "function", 101 | "args": [ 102 | { 103 | "name": "t" 104 | } 105 | ], 106 | "argsDisplay": "t" 107 | }, 108 | "pcall": { 109 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-pcall", 110 | "description": "Calls function f with the given arguments in protected mode. This means that any error inside 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.", 111 | "type": "function", 112 | "args": [ 113 | { 114 | "name": "f" 115 | } 116 | ], 117 | "argsDisplay": "f [, arg1, ···]" 118 | }, 119 | "print": { 120 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-print", 121 | "description": "Receives any number of arguments and prints their values to stdout, using the tostring function to convert each argument to a string. print is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use string.format and io.write.", 122 | "type": "function", 123 | "args": [], 124 | "argsDisplay": "···" 125 | }, 126 | "rawequal": { 127 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-rawequal", 128 | "description": "Checks whether v1 is equal to v2, without invoking the __eq metamethod. Returns a boolean.", 129 | "type": "function", 130 | "args": [ 131 | { 132 | "name": "v1" 133 | }, 134 | { 135 | "name": "v2" 136 | } 137 | ], 138 | "argsDisplay": "v1, v2" 139 | }, 140 | "rawget": { 141 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-rawget", 142 | "description": "Gets the real value of table[index], without invoking the __index metamethod. table must be a table; index may be any value.", 143 | "type": "function", 144 | "args": [ 145 | { 146 | "name": "table" 147 | }, 148 | { 149 | "name": "index" 150 | } 151 | ], 152 | "argsDisplay": "table, index" 153 | }, 154 | "rawlen": { 155 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-rawlen", 156 | "description": "Returns the length of the object v, which must be a table or a string, without invoking the __len metamethod. Returns an integer.", 157 | "type": "function", 158 | "args": [ 159 | { 160 | "name": "v" 161 | } 162 | ], 163 | "argsDisplay": "v" 164 | }, 165 | "rawset": { 166 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-rawset", 167 | "description": "Sets the real value of table[index] to value, without invoking the __newindex metamethod. table must be a table, index any value different from nil and NaN, and value any Lua value.", 168 | "type": "function", 169 | "args": [ 170 | { 171 | "name": "table" 172 | }, 173 | { 174 | "name": "index" 175 | }, 176 | { 177 | "name": "value" 178 | } 179 | ], 180 | "argsDisplay": "table, index, value" 181 | }, 182 | "require": { 183 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-require", 184 | "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.", 185 | "type": "function", 186 | "args": [ 187 | { 188 | "name": "modname" 189 | } 190 | ], 191 | "argsDisplay": "modname" 192 | }, 193 | "select": { 194 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-select", 195 | "description": "If index is a number, returns all arguments after argument number index; a negative number indexes from the end (-1 is the last argument). Otherwise, index must be the string \"#\", and select returns the total number of extra arguments it received.", 196 | "type": "function", 197 | "args": [ 198 | { 199 | "name": "index" 200 | } 201 | ], 202 | "argsDisplay": "index, ···" 203 | }, 204 | "setmetatable": { 205 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-setmetatable", 206 | "description": "Sets the metatable for the given table. (To change the metatable of other types from Lua code, you must use the debug library (§6.10).) If metatable is nil, removes the metatable of the given table. If the original metatable has a __metatable field, raises an error.", 207 | "type": "function", 208 | "args": [ 209 | { 210 | "name": "table" 211 | }, 212 | { 213 | "name": "metatable" 214 | } 215 | ], 216 | "argsDisplay": "table, metatable" 217 | }, 218 | "tonumber": { 219 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-tonumber", 220 | "description": "When called with no base, tonumber tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.", 221 | "type": "function", 222 | "args": [ 223 | { 224 | "name": "e" 225 | } 226 | ], 227 | "argsDisplay": "e [, base]" 228 | }, 229 | "tostring": { 230 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-tostring", 231 | "description": "Receives a value of any type and converts it to a string in a human-readable format. (For complete control of how numbers are converted, use string.format.)", 232 | "type": "function", 233 | "args": [ 234 | { 235 | "name": "v" 236 | } 237 | ], 238 | "argsDisplay": "v" 239 | }, 240 | "type": { 241 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-type", 242 | "description": "Returns the type of its only argument, coded as a string. The possible results of this function are \"nil\" (a string, not the value nil), \"number\", \"string\", \"boolean\", \"table\", \"function\", \"thread\", and \"userdata\".", 243 | "type": "function", 244 | "args": [ 245 | { 246 | "name": "v" 247 | } 248 | ], 249 | "argsDisplay": "v" 250 | }, 251 | "xpcall": { 252 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-xpcall", 253 | "description": "This function is similar to pcall, except that it sets a new message handler msgh.", 254 | "type": "function", 255 | "args": [ 256 | { 257 | "name": "f" 258 | }, 259 | { 260 | "name": "msgh" 261 | } 262 | ], 263 | "argsDisplay": "f, msgh [, arg1, ···]" 264 | }, 265 | "coroutine": { 266 | "link": "https://www.lua.org/manual/5.3/manual.html#6.2", 267 | "description": "This library comprises the operations to manipulate coroutines, which come inside the table coroutine. See §2.6 for a general description of coroutines.", 268 | "type": "table", 269 | "fields": { 270 | "create": { 271 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.create", 272 | "description": "Creates a new coroutine, with body f. f must be a function. Returns this new coroutine, an object with type \"thread\".", 273 | "type": "function", 274 | "args": [ 275 | { 276 | "name": "f" 277 | } 278 | ], 279 | "argsDisplay": "f" 280 | }, 281 | "isyieldable": { 282 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.isyieldable", 283 | "description": "Returns true when the running coroutine can yield.", 284 | "type": "function", 285 | "args": [], 286 | "argsDisplay": "" 287 | }, 288 | "resume": { 289 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.resume", 290 | "description": "Starts or continues the execution of coroutine co. The first time you resume a coroutine, it starts running its body. The values val1, ... are passed as the arguments to the body function. If the coroutine has yielded, resume restarts it; the values val1, ... are passed as the results from the yield.", 291 | "type": "function", 292 | "args": [ 293 | { 294 | "name": "co" 295 | } 296 | ], 297 | "argsDisplay": "co [, val1, ···]" 298 | }, 299 | "running": { 300 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.running", 301 | "description": "Returns the running coroutine plus a boolean, true when the running coroutine is the main one.", 302 | "type": "function", 303 | "args": [], 304 | "argsDisplay": "" 305 | }, 306 | "status": { 307 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.status", 308 | "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.", 309 | "type": "function", 310 | "args": [ 311 | { 312 | "name": "co" 313 | } 314 | ], 315 | "argsDisplay": "co" 316 | }, 317 | "wrap": { 318 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.wrap", 319 | "description": "Creates a new coroutine, with body f. f must be a 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.", 320 | "type": "function", 321 | "args": [ 322 | { 323 | "name": "f" 324 | } 325 | ], 326 | "argsDisplay": "f" 327 | }, 328 | "yield": { 329 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-coroutine.yield", 330 | "description": "Suspends the execution of the calling coroutine. Any arguments to yield are passed as extra results to resume.", 331 | "type": "function", 332 | "args": [], 333 | "argsDisplay": "···" 334 | } 335 | } 336 | }, 337 | "debug": { 338 | "link": "https://www.lua.org/manual/5.3/manual.html#6.10", 339 | "description": "This library provides the functionality of the debug interface (§4.9) to Lua programs. You should exert care when using this library. Several of its functions violate basic assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside; that userdata metatables cannot be changed by Lua code; that Lua programs do not crash) and therefore can compromise otherwise secure code. Moreover, some functions in this library may be slow.", 340 | "type": "table", 341 | "fields": { 342 | "debug": { 343 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.debug", 344 | "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.", 345 | "type": "function", 346 | "args": [], 347 | "argsDisplay": "" 348 | }, 349 | "gethook": { 350 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.gethook", 351 | "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).", 352 | "type": "function", 353 | "args": [], 354 | "argsDisplay": "[thread]" 355 | }, 356 | "getinfo": { 357 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getinfo", 358 | "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 f, which means the function running at level f of the call stack of the given thread: level 0 is the current function (getinfo itself); level 1 is the function that called getinfo (except for tail calls, which do not count on the stack); and so on. If f is a number larger than the number of active functions, then getinfo returns nil.", 359 | "type": "function", 360 | "args": [], 361 | "argsDisplay": "[thread,] f [, what]" 362 | }, 363 | "getlocal": { 364 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getlocal", 365 | "description": "This function returns the name and the value of the local variable with index local of the function at level f of the stack. This function accesses not only explicit local variables, but also parameters, temporaries, etc.", 366 | "type": "function", 367 | "args": [], 368 | "argsDisplay": "[thread,] f, local" 369 | }, 370 | "getmetatable": { 371 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getmetatable", 372 | "description": "Returns the metatable of the given value or nil if it does not have a metatable.", 373 | "type": "function", 374 | "args": [ 375 | { 376 | "name": "value" 377 | } 378 | ], 379 | "argsDisplay": "value" 380 | }, 381 | "getregistry": { 382 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getregistry", 383 | "description": "Returns the registry table (see §4.5).", 384 | "type": "function", 385 | "args": [], 386 | "argsDisplay": "" 387 | }, 388 | "getupvalue": { 389 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getupvalue", 390 | "description": "This function returns the name and the value of the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index.", 391 | "type": "function", 392 | "args": [ 393 | { 394 | "name": "f" 395 | }, 396 | { 397 | "name": "up" 398 | } 399 | ], 400 | "argsDisplay": "f, up" 401 | }, 402 | "getuservalue": { 403 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.getuservalue", 404 | "description": "Returns the Lua value associated to u. If u is not a userdata, returns nil.", 405 | "type": "function", 406 | "args": [ 407 | { 408 | "name": "u" 409 | } 410 | ], 411 | "argsDisplay": "u" 412 | }, 413 | "sethook": { 414 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.sethook", 415 | "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 any combination of the following characters, with the given meaning:", 416 | "type": "function", 417 | "args": [], 418 | "argsDisplay": "[thread,] hook, mask [, count]" 419 | }, 420 | "setlocal": { 421 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.setlocal", 422 | "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.", 423 | "type": "function", 424 | "args": [], 425 | "argsDisplay": "[thread,] level, local, value" 426 | }, 427 | "setmetatable": { 428 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.setmetatable", 429 | "description": "Sets the metatable for the given value to the given table (which can be nil). Returns value.", 430 | "type": "function", 431 | "args": [ 432 | { 433 | "name": "value" 434 | }, 435 | { 436 | "name": "table" 437 | } 438 | ], 439 | "argsDisplay": "value, table" 440 | }, 441 | "setupvalue": { 442 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.setupvalue", 443 | "description": "This function assigns the value value to the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue.", 444 | "type": "function", 445 | "args": [ 446 | { 447 | "name": "f" 448 | }, 449 | { 450 | "name": "up" 451 | }, 452 | { 453 | "name": "value" 454 | } 455 | ], 456 | "argsDisplay": "f, up, value" 457 | }, 458 | "setuservalue": { 459 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.setuservalue", 460 | "description": "Sets the given value as the Lua value associated to the given udata. udata must be a full userdata.", 461 | "type": "function", 462 | "args": [ 463 | { 464 | "name": "udata" 465 | }, 466 | { 467 | "name": "value" 468 | } 469 | ], 470 | "argsDisplay": "udata, value" 471 | }, 472 | "traceback": { 473 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.traceback", 474 | "description": "If message is present but is neither a string nor nil, this function returns message without further processing. Otherwise, it returns a string with a traceback of the call stack. The 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).", 475 | "type": "function", 476 | "args": [], 477 | "argsDisplay": "[thread,] [message [, level]]" 478 | }, 479 | "upvalueid": { 480 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.upvalueid", 481 | "description": "Returns a unique identifier (as a light userdata) for the upvalue numbered n from the given function.", 482 | "type": "function", 483 | "args": [ 484 | { 485 | "name": "f" 486 | }, 487 | { 488 | "name": "n" 489 | } 490 | ], 491 | "argsDisplay": "f, n" 492 | }, 493 | "upvaluejoin": { 494 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-debug.upvaluejoin", 495 | "description": "Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2.", 496 | "type": "function", 497 | "args": [ 498 | { 499 | "name": "f1" 500 | }, 501 | { 502 | "name": "n1" 503 | }, 504 | { 505 | "name": "f2" 506 | }, 507 | { 508 | "name": "n2" 509 | } 510 | ], 511 | "argsDisplay": "f1, n1, f2, n2" 512 | } 513 | } 514 | }, 515 | "io": { 516 | "link": "https://www.lua.org/manual/5.3/manual.html#6.8", 517 | "description": "The I/O library provides two different styles for file manipulation. The first one uses implicit file handles; that is, there are operations to set a default input file and a default output file, and all input/output operations are over these default files. The second style uses explicit file handles.", 518 | "type": "table", 519 | "fields": { 520 | "close": { 521 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.close", 522 | "description": "Equivalent to file:close(). Without a file, closes the default output file.", 523 | "type": "function", 524 | "args": [], 525 | "argsDisplay": "[file]" 526 | }, 527 | "flush": { 528 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.flush", 529 | "description": "Equivalent to io.output():flush().", 530 | "type": "function", 531 | "args": [], 532 | "argsDisplay": "" 533 | }, 534 | "input": { 535 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.input", 536 | "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.", 537 | "type": "function", 538 | "args": [], 539 | "argsDisplay": "[file]" 540 | }, 541 | "lines": { 542 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.lines", 543 | "description": "Opens the given file name in read mode and returns an iterator function that works like file:lines(···) over the opened file. When the iterator function detects the end of file, it returns no values (to finish the loop) and automatically closes the file.", 544 | "type": "function", 545 | "args": [], 546 | "argsDisplay": "[filename, ···]" 547 | }, 548 | "open": { 549 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.open", 550 | "description": "This function opens a file, in the mode specified in the string mode. In case of success, it returns a new file handle.", 551 | "type": "function", 552 | "args": [ 553 | { 554 | "name": "filename" 555 | } 556 | ], 557 | "argsDisplay": "filename [, mode]", 558 | "returnTypes": [ 559 | { 560 | "type": "ref", 561 | "name": "file" 562 | } 563 | ] 564 | }, 565 | "output": { 566 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.output", 567 | "description": "Similar to io.input, but operates over the default output file.", 568 | "type": "function", 569 | "args": [], 570 | "argsDisplay": "[file]" 571 | }, 572 | "popen": { 573 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.popen", 574 | "description": "This function is system dependent and is not available on all platforms.", 575 | "type": "function", 576 | "args": [ 577 | { 578 | "name": "prog" 579 | } 580 | ], 581 | "argsDisplay": "prog [, mode]", 582 | "returnTypes": [ 583 | { 584 | "type": "ref", 585 | "name": "file" 586 | } 587 | ] 588 | }, 589 | "read": { 590 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.read", 591 | "description": "Equivalent to io.input():read(···).", 592 | "type": "function", 593 | "args": [], 594 | "argsDisplay": "···" 595 | }, 596 | "stderr": { 597 | "type": "ref", 598 | "name": "file" 599 | }, 600 | "stdin": { 601 | "type": "ref", 602 | "name": "file" 603 | }, 604 | "stdout": { 605 | "type": "ref", 606 | "name": "file" 607 | }, 608 | "tmpfile": { 609 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.tmpfile", 610 | "description": "In case of success, returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.", 611 | "type": "function", 612 | "args": [], 613 | "argsDisplay": "", 614 | "returnTypes": [ 615 | { 616 | "type": "ref", 617 | "name": "file" 618 | } 619 | ] 620 | }, 621 | "type": { 622 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.type", 623 | "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.", 624 | "type": "function", 625 | "args": [ 626 | { 627 | "name": "obj" 628 | } 629 | ], 630 | "argsDisplay": "obj" 631 | }, 632 | "write": { 633 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-io.write", 634 | "description": "Equivalent to io.output():write(···).", 635 | "type": "function", 636 | "args": [], 637 | "argsDisplay": "···" 638 | } 639 | } 640 | }, 641 | "math": { 642 | "link": "https://www.lua.org/manual/5.3/manual.html#6.7", 643 | "description": "This library provides basic mathematical functions. It provides all its functions and constants inside the table math. Functions with the annotation \"integer/float\" give integer results for integer arguments and float results for float (or mixed) arguments. Rounding functions (math.ceil, math.floor, and math.modf) return an integer when the result fits in the range of an integer, or a float otherwise.", 644 | "type": "table", 645 | "fields": { 646 | "abs": { 647 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.abs", 648 | "description": "Returns the absolute value of x. (integer/float)", 649 | "type": "function", 650 | "args": [ 651 | { 652 | "name": "x" 653 | } 654 | ], 655 | "argsDisplay": "x" 656 | }, 657 | "acos": { 658 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.acos", 659 | "description": "Returns the arc cosine of x (in radians).", 660 | "type": "function", 661 | "args": [ 662 | { 663 | "name": "x" 664 | } 665 | ], 666 | "argsDisplay": "x" 667 | }, 668 | "asin": { 669 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.asin", 670 | "description": "Returns the arc sine of x (in radians).", 671 | "type": "function", 672 | "args": [ 673 | { 674 | "name": "x" 675 | } 676 | ], 677 | "argsDisplay": "x" 678 | }, 679 | "atan": { 680 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.atan", 681 | "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.)", 682 | "type": "function", 683 | "args": [ 684 | { 685 | "name": "y" 686 | } 687 | ], 688 | "argsDisplay": "y [, x]" 689 | }, 690 | "ceil": { 691 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.ceil", 692 | "description": "Returns the smallest integral value larger than or equal to x.", 693 | "type": "function", 694 | "args": [ 695 | { 696 | "name": "x" 697 | } 698 | ], 699 | "argsDisplay": "x" 700 | }, 701 | "cos": { 702 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.cos", 703 | "description": "Returns the cosine of x (assumed to be in radians).", 704 | "type": "function", 705 | "args": [ 706 | { 707 | "name": "x" 708 | } 709 | ], 710 | "argsDisplay": "x" 711 | }, 712 | "deg": { 713 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.deg", 714 | "description": "Converts the angle x from radians to degrees.", 715 | "type": "function", 716 | "args": [ 717 | { 718 | "name": "x" 719 | } 720 | ], 721 | "argsDisplay": "x" 722 | }, 723 | "exp": { 724 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.exp", 725 | "description": "Returns the value ex (where e is the base of natural logarithms).", 726 | "type": "function", 727 | "args": [ 728 | { 729 | "name": "x" 730 | } 731 | ], 732 | "argsDisplay": "x" 733 | }, 734 | "floor": { 735 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.floor", 736 | "description": "Returns the largest integral value smaller than or equal to x.", 737 | "type": "function", 738 | "args": [ 739 | { 740 | "name": "x" 741 | } 742 | ], 743 | "argsDisplay": "x" 744 | }, 745 | "fmod": { 746 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.fmod", 747 | "description": "Returns the remainder of the division of x by y that rounds the quotient towards zero. (integer/float)", 748 | "type": "function", 749 | "args": [ 750 | { 751 | "name": "x" 752 | }, 753 | { 754 | "name": "y" 755 | } 756 | ], 757 | "argsDisplay": "x, y" 758 | }, 759 | "huge": { 760 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.huge", 761 | "description": "The float value HUGE_VAL, a value larger than any other numeric value.", 762 | "type": "unknown" 763 | }, 764 | "log": { 765 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.log", 766 | "description": "Returns the logarithm of x in the given base. The default for base is e (so that the function returns the natural logarithm of x).", 767 | "type": "function", 768 | "args": [ 769 | { 770 | "name": "x" 771 | } 772 | ], 773 | "argsDisplay": "x [, base]" 774 | }, 775 | "max": { 776 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.max", 777 | "description": "Returns the argument with the maximum value, according to the Lua operator <. (integer/float)", 778 | "type": "function", 779 | "args": [ 780 | { 781 | "name": "x" 782 | } 783 | ], 784 | "argsDisplay": "x, ···" 785 | }, 786 | "maxinteger": { 787 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.maxinteger", 788 | "description": "An integer with the maximum value for an integer.", 789 | "type": "unknown" 790 | }, 791 | "min": { 792 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.min", 793 | "description": "Returns the argument with the minimum value, according to the Lua operator <. (integer/float)", 794 | "type": "function", 795 | "args": [ 796 | { 797 | "name": "x" 798 | } 799 | ], 800 | "argsDisplay": "x, ···" 801 | }, 802 | "mininteger": { 803 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.mininteger", 804 | "description": "An integer with the minimum value for an integer.", 805 | "type": "unknown" 806 | }, 807 | "modf": { 808 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.modf", 809 | "description": "Returns the integral part of x and the fractional part of x. Its second result is always a float.", 810 | "type": "function", 811 | "args": [ 812 | { 813 | "name": "x" 814 | } 815 | ], 816 | "argsDisplay": "x" 817 | }, 818 | "pi": { 819 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.pi", 820 | "description": "The value of π.", 821 | "type": "number" 822 | }, 823 | "rad": { 824 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.rad", 825 | "description": "Converts the angle x from degrees to radians.", 826 | "type": "function", 827 | "args": [ 828 | { 829 | "name": "x" 830 | } 831 | ], 832 | "argsDisplay": "x" 833 | }, 834 | "random": { 835 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.random", 836 | "description": "When called without arguments, returns a pseudo-random float with uniform distribution in the range [0,1). When called with two integers m and n, math.random returns a pseudo-random integer with uniform distribution in the range [m, n]. (The value n-m cannot be negative and must fit in a Lua integer.) The call math.random(n) is equivalent to math.random(1,n).", 837 | "type": "function", 838 | "args": [], 839 | "argsDisplay": "[m [, n]]" 840 | }, 841 | "randomseed": { 842 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.randomseed", 843 | "description": "Sets x as the \"seed\" for the pseudo-random generator: equal seeds produce equal sequences of numbers.", 844 | "type": "function", 845 | "args": [ 846 | { 847 | "name": "x" 848 | } 849 | ], 850 | "argsDisplay": "x" 851 | }, 852 | "sin": { 853 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.sin", 854 | "description": "Returns the sine of x (assumed to be in radians).", 855 | "type": "function", 856 | "args": [ 857 | { 858 | "name": "x" 859 | } 860 | ], 861 | "argsDisplay": "x" 862 | }, 863 | "sqrt": { 864 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.sqrt", 865 | "description": "Returns the square root of x. (You can also use the expression x^0.5 to compute this value.)", 866 | "type": "function", 867 | "args": [ 868 | { 869 | "name": "x" 870 | } 871 | ], 872 | "argsDisplay": "x" 873 | }, 874 | "tan": { 875 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.tan", 876 | "description": "Returns the tangent of x (assumed to be in radians).", 877 | "type": "function", 878 | "args": [ 879 | { 880 | "name": "x" 881 | } 882 | ], 883 | "argsDisplay": "x" 884 | }, 885 | "tointeger": { 886 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.tointeger", 887 | "description": "If the value x is convertible to an integer, returns that integer. Otherwise, returns nil.", 888 | "type": "function", 889 | "args": [ 890 | { 891 | "name": "x" 892 | } 893 | ], 894 | "argsDisplay": "x" 895 | }, 896 | "type": { 897 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.type", 898 | "description": "Returns \"integer\" if x is an integer, \"float\" if it is a float, or nil if x is not a number.", 899 | "type": "function", 900 | "args": [ 901 | { 902 | "name": "x" 903 | } 904 | ], 905 | "argsDisplay": "x" 906 | }, 907 | "ult": { 908 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-math.ult", 909 | "description": "Returns a boolean, true if integer m is below integer n when they are compared as unsigned integers.", 910 | "type": "function", 911 | "args": [ 912 | { 913 | "name": "m" 914 | }, 915 | { 916 | "name": "n" 917 | } 918 | ], 919 | "argsDisplay": "m, n" 920 | } 921 | } 922 | }, 923 | "os": { 924 | "link": "https://www.lua.org/manual/5.3/manual.html#6.9", 925 | "description": "This library is implemented through table os.", 926 | "type": "table", 927 | "fields": { 928 | "clock": { 929 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.clock", 930 | "description": "Returns an approximation of the amount in seconds of CPU time used by the program.", 931 | "type": "function", 932 | "args": [], 933 | "argsDisplay": "" 934 | }, 935 | "date": { 936 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.date", 937 | "description": "Returns a string or a table containing date and time, formatted according to the given string format.", 938 | "type": "function", 939 | "args": [], 940 | "argsDisplay": "[format [, time]]" 941 | }, 942 | "difftime": { 943 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.difftime", 944 | "description": "Returns the difference, in seconds, from time t1 to time t2 (where the times are values returned by os.time). In POSIX, Windows, and some other systems, this value is exactly t2-t1.", 945 | "type": "function", 946 | "args": [ 947 | { 948 | "name": "t2" 949 | }, 950 | { 951 | "name": "t1" 952 | } 953 | ], 954 | "argsDisplay": "t2, t1" 955 | }, 956 | "execute": { 957 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.execute", 958 | "description": "This function is equivalent to the ISO C function system. It passes command to be executed by an operating system shell. Its first result is true if the command terminated successfully, or nil otherwise. After this first result the function returns a string plus a number, as follows:", 959 | "type": "function", 960 | "args": [], 961 | "argsDisplay": "[command]" 962 | }, 963 | "exit": { 964 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.exit", 965 | "description": "Calls the ISO C function exit to terminate the host program. If code is true, the returned status is EXIT_SUCCESS; if code is false, the returned status is EXIT_FAILURE; if code is a number, the returned status is this number. The default value for code is true.", 966 | "type": "function", 967 | "args": [], 968 | "argsDisplay": "[code [, close]]" 969 | }, 970 | "getenv": { 971 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.getenv", 972 | "description": "Returns the value of the process environment variable varname, or nil if the variable is not defined.", 973 | "type": "function", 974 | "args": [ 975 | { 976 | "name": "varname" 977 | } 978 | ], 979 | "argsDisplay": "varname" 980 | }, 981 | "remove": { 982 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.remove", 983 | "description": "Deletes the file (or empty directory, on POSIX systems) with the given name. If this function fails, it returns nil, plus a string describing the error and the error code.", 984 | "type": "function", 985 | "args": [ 986 | { 987 | "name": "filename" 988 | } 989 | ], 990 | "argsDisplay": "filename" 991 | }, 992 | "rename": { 993 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.rename", 994 | "description": "Renames file or directory named oldname to newname. If this function fails, it returns nil, plus a string describing the error and the error code.", 995 | "type": "function", 996 | "args": [ 997 | { 998 | "name": "oldname" 999 | }, 1000 | { 1001 | "name": "newname" 1002 | } 1003 | ], 1004 | "argsDisplay": "oldname, newname" 1005 | }, 1006 | "setlocale": { 1007 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.setlocale", 1008 | "description": "Sets the current locale of the program. locale is a system-dependent 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.", 1009 | "type": "function", 1010 | "args": [ 1011 | { 1012 | "name": "locale" 1013 | } 1014 | ], 1015 | "argsDisplay": "locale [, category]" 1016 | }, 1017 | "time": { 1018 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.time", 1019 | "description": "Returns the current time when called without arguments, or a time representing the local date and time specified by the given table. This table must have fields year, month, and day, and may have fields hour (default is 12), min (default is 0), sec (default is 0), and isdst (default is nil). Other fields are ignored. For a description of these fields, see the os.date function.", 1020 | "type": "function", 1021 | "args": [], 1022 | "argsDisplay": "[table]" 1023 | }, 1024 | "tmpname": { 1025 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-os.tmpname", 1026 | "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.", 1027 | "type": "function", 1028 | "args": [], 1029 | "argsDisplay": "" 1030 | } 1031 | } 1032 | }, 1033 | "package": { 1034 | "link": "https://www.lua.org/manual/5.3/manual.html#6.3", 1035 | "description": "The package library provides basic facilities for loading modules in Lua. It exports one function directly in the global environment: require. Everything else is exported in a table package.", 1036 | "type": "table", 1037 | "fields": { 1038 | "config": { 1039 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.config", 1040 | "description": "A string describing some compile-time configurations for packages. This string is a sequence of lines:", 1041 | "type": "unknown" 1042 | }, 1043 | "cpath": { 1044 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.cpath", 1045 | "description": "The path used by require to search for a C loader.", 1046 | "type": "unknown" 1047 | }, 1048 | "loaded": { 1049 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.loaded", 1050 | "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.", 1051 | "type": "unknown" 1052 | }, 1053 | "loadlib": { 1054 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.loadlib", 1055 | "description": "Dynamically links the host program with the C library libname.", 1056 | "type": "function", 1057 | "args": [ 1058 | { 1059 | "name": "libname" 1060 | }, 1061 | { 1062 | "name": "funcname" 1063 | } 1064 | ], 1065 | "argsDisplay": "libname, funcname" 1066 | }, 1067 | "path": { 1068 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.path", 1069 | "description": "The path used by require to search for a Lua loader.", 1070 | "type": "unknown" 1071 | }, 1072 | "preload": { 1073 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.preload", 1074 | "description": "A table to store loaders for specific modules (see require).", 1075 | "type": "unknown" 1076 | }, 1077 | "searchers": { 1078 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.searchers", 1079 | "description": "A table used by require to control how to load modules.", 1080 | "type": "unknown" 1081 | }, 1082 | "searchpath": { 1083 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-package.searchpath", 1084 | "description": "Searches for the given name in the given path.", 1085 | "type": "function", 1086 | "args": [ 1087 | { 1088 | "name": "name" 1089 | }, 1090 | { 1091 | "name": "path" 1092 | } 1093 | ], 1094 | "argsDisplay": "name, path [, sep [, rep]]" 1095 | } 1096 | } 1097 | }, 1098 | "string": { 1099 | "link": "https://www.lua.org/manual/5.3/manual.html#6.4", 1100 | "description": "This library provides generic functions for string manipulation, such as finding and extracting substrings, and pattern matching. When indexing a string in Lua, the first character is at position 1 (not at 0, as in C). Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on.", 1101 | "type": "table", 1102 | "fields": { 1103 | "byte": { 1104 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.byte", 1105 | "description": "Returns the internal numeric codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i. These indices are corrected following the same rules of function string.sub.", 1106 | "type": "function", 1107 | "args": [ 1108 | { 1109 | "name": "s" 1110 | } 1111 | ], 1112 | "argsDisplay": "s [, i [, j]]" 1113 | }, 1114 | "char": { 1115 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.char", 1116 | "description": "Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.", 1117 | "type": "function", 1118 | "args": [], 1119 | "argsDisplay": "···" 1120 | }, 1121 | "dump": { 1122 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.dump", 1123 | "description": "Returns a string containing a binary representation (a binary chunk) of the given function, so that a later load on this string returns a copy of the function (but with new upvalues). If strip is a true value, the binary representation may not include all debug information about the function, to save space.", 1124 | "type": "function", 1125 | "args": [ 1126 | { 1127 | "name": "function" 1128 | } 1129 | ], 1130 | "argsDisplay": "function [, strip]" 1131 | }, 1132 | "find": { 1133 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.find", 1134 | "description": "Looks for the first match of pattern (see §6.4.1) in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numeric argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain \"find substring\" operation, with no characters in pattern being considered magic. Note that if plain is given, then init must be given as well.", 1135 | "type": "function", 1136 | "args": [ 1137 | { 1138 | "name": "s" 1139 | }, 1140 | { 1141 | "name": "pattern" 1142 | } 1143 | ], 1144 | "argsDisplay": "s, pattern [, init [, plain]]" 1145 | }, 1146 | "format": { 1147 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.format", 1148 | "description": "Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the ISO C function sprintf. The only differences are that the options/modifiers *, h, L, l, n, and p are not supported and that there is an extra option, q.", 1149 | "type": "function", 1150 | "args": [ 1151 | { 1152 | "name": "formatstring" 1153 | } 1154 | ], 1155 | "argsDisplay": "formatstring, ···" 1156 | }, 1157 | "gmatch": { 1158 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.gmatch", 1159 | "description": "Returns an iterator function that, each time it is called, returns the next captures from pattern (see §6.4.1) over the string s. If pattern specifies no captures, then the whole match is produced in each call.", 1160 | "type": "function", 1161 | "args": [ 1162 | { 1163 | "name": "s" 1164 | }, 1165 | { 1166 | "name": "pattern" 1167 | } 1168 | ], 1169 | "argsDisplay": "s, pattern" 1170 | }, 1171 | "gsub": { 1172 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.gsub", 1173 | "description": "Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see §6.4.1) have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred. The name gsub comes from Global SUBstitution.", 1174 | "type": "function", 1175 | "args": [ 1176 | { 1177 | "name": "s" 1178 | }, 1179 | { 1180 | "name": "pattern" 1181 | }, 1182 | { 1183 | "name": "repl" 1184 | } 1185 | ], 1186 | "argsDisplay": "s, pattern, repl [, n]" 1187 | }, 1188 | "len": { 1189 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.len", 1190 | "description": "Receives a string and returns its length. The empty string \"\" has length 0. Embedded zeros are counted, so \"a\\000bc\\000\" has length 5.", 1191 | "type": "function", 1192 | "args": [ 1193 | { 1194 | "name": "s" 1195 | } 1196 | ], 1197 | "argsDisplay": "s" 1198 | }, 1199 | "lower": { 1200 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.lower", 1201 | "description": "Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.", 1202 | "type": "function", 1203 | "args": [ 1204 | { 1205 | "name": "s" 1206 | } 1207 | ], 1208 | "argsDisplay": "s" 1209 | }, 1210 | "match": { 1211 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.match", 1212 | "description": "Looks for the first match of pattern (see §6.4.1) in the string s. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numeric argument init specifies where to start the search; its default value is 1 and can be negative.", 1213 | "type": "function", 1214 | "args": [ 1215 | { 1216 | "name": "s" 1217 | }, 1218 | { 1219 | "name": "pattern" 1220 | } 1221 | ], 1222 | "argsDisplay": "s, pattern [, init]" 1223 | }, 1224 | "pack": { 1225 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.pack", 1226 | "description": "Returns a binary string containing the values v1, v2, etc. packed (that is, serialized in binary form) according to the format string fmt (see §6.4.2).", 1227 | "type": "function", 1228 | "args": [ 1229 | { 1230 | "name": "fmt" 1231 | }, 1232 | { 1233 | "name": "v1" 1234 | }, 1235 | { 1236 | "name": "v2" 1237 | } 1238 | ], 1239 | "argsDisplay": "fmt, v1, v2, ···" 1240 | }, 1241 | "packsize": { 1242 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.packsize", 1243 | "description": "Returns the size of a string resulting from string.pack with the given format. The format string cannot have the variable-length options 's' or 'z' (see §6.4.2).", 1244 | "type": "function", 1245 | "args": [ 1246 | { 1247 | "name": "fmt" 1248 | } 1249 | ], 1250 | "argsDisplay": "fmt" 1251 | }, 1252 | "rep": { 1253 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.rep", 1254 | "description": "Returns a string that is the concatenation of n copies of the string s separated by the string sep. The default value for sep is the empty string (that is, no separator). Returns the empty string if n is not positive.", 1255 | "type": "function", 1256 | "args": [ 1257 | { 1258 | "name": "s" 1259 | }, 1260 | { 1261 | "name": "n" 1262 | } 1263 | ], 1264 | "argsDisplay": "s, n [, sep]" 1265 | }, 1266 | "reverse": { 1267 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.reverse", 1268 | "description": "Returns a string that is the string s reversed.", 1269 | "type": "function", 1270 | "args": [ 1271 | { 1272 | "name": "s" 1273 | } 1274 | ], 1275 | "argsDisplay": "s" 1276 | }, 1277 | "sub": { 1278 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.sub", 1279 | "description": "Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.", 1280 | "type": "function", 1281 | "args": [ 1282 | { 1283 | "name": "s" 1284 | }, 1285 | { 1286 | "name": "i" 1287 | } 1288 | ], 1289 | "argsDisplay": "s, i [, j]" 1290 | }, 1291 | "unpack": { 1292 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.unpack", 1293 | "description": "Returns the values packed in string s (see string.pack) according to the format string fmt (see §6.4.2). An optional pos marks where to start reading in s (default is 1). After the read values, this function also returns the index of the first unread byte in s.", 1294 | "type": "function", 1295 | "args": [ 1296 | { 1297 | "name": "fmt" 1298 | }, 1299 | { 1300 | "name": "s" 1301 | } 1302 | ], 1303 | "argsDisplay": "fmt, s [, pos]" 1304 | }, 1305 | "upper": { 1306 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-string.upper", 1307 | "description": "Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.", 1308 | "type": "function", 1309 | "args": [ 1310 | { 1311 | "name": "s" 1312 | } 1313 | ], 1314 | "argsDisplay": "s" 1315 | } 1316 | } 1317 | }, 1318 | "table": { 1319 | "link": "https://www.lua.org/manual/5.3/manual.html#6.6", 1320 | "description": "This library provides generic functions for table manipulation. It provides all its functions inside the table table.", 1321 | "type": "table", 1322 | "fields": { 1323 | "concat": { 1324 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.concat", 1325 | "description": "Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ··· sep..list[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is #list. If i is greater than j, returns the empty string.", 1326 | "type": "function", 1327 | "args": [ 1328 | { 1329 | "name": "list" 1330 | } 1331 | ], 1332 | "argsDisplay": "list [, sep [, i [, j]]]" 1333 | }, 1334 | "insert": { 1335 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.insert", 1336 | "description": "Inserts element value at position pos in list, shifting up the elements list[pos], list[pos+1], ···, list[#list]. The default value for pos is #list+1, so that a call table.insert(t,x) inserts x at the end of list t.", 1337 | "type": "function", 1338 | "args": [ 1339 | { 1340 | "name": "list" 1341 | } 1342 | ], 1343 | "argsDisplay": "list, [pos,] value" 1344 | }, 1345 | "move": { 1346 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.move", 1347 | "description": "Moves elements from table a1 to table a2, performing the equivalent to the following multiple assignment: a2[t],··· = a1[f],···,a1[e]. The default for a2 is a1. The destination range can overlap with the source range. The number of elements to be moved must fit in a Lua integer.", 1348 | "type": "function", 1349 | "args": [ 1350 | { 1351 | "name": "a1" 1352 | }, 1353 | { 1354 | "name": "f" 1355 | }, 1356 | { 1357 | "name": "e" 1358 | }, 1359 | { 1360 | "name": "t" 1361 | } 1362 | ], 1363 | "argsDisplay": "a1, f, e, t [,a2]" 1364 | }, 1365 | "pack": { 1366 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.pack", 1367 | "description": "Returns a new table with all parameters stored into keys 1, 2, etc. and with a field \"n\" with the total number of parameters. Note that the resulting table may not be a sequence.", 1368 | "type": "function", 1369 | "args": [], 1370 | "argsDisplay": "···" 1371 | }, 1372 | "remove": { 1373 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.remove", 1374 | "description": "Removes from list the element at position pos, returning the value of the removed element. When pos is an integer between 1 and #list, it shifts down the elements list[pos+1], list[pos+2], ···, list[#list] and erases element list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; in those cases, the function erases the element list[pos].", 1375 | "type": "function", 1376 | "args": [ 1377 | { 1378 | "name": "list" 1379 | } 1380 | ], 1381 | "argsDisplay": "list [, pos]" 1382 | }, 1383 | "sort": { 1384 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.sort", 1385 | "description": "Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that, after the sort, i < j implies not comp(list[j],list[i])). If comp is not given, then the standard Lua operator < is used instead.", 1386 | "type": "function", 1387 | "args": [ 1388 | { 1389 | "name": "list" 1390 | } 1391 | ], 1392 | "argsDisplay": "list [, comp]" 1393 | }, 1394 | "unpack": { 1395 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-table.unpack", 1396 | "description": "Returns the elements from the given list. This function is equivalent to", 1397 | "type": "function", 1398 | "args": [ 1399 | { 1400 | "name": "list" 1401 | } 1402 | ], 1403 | "argsDisplay": "list [, i [, j]]" 1404 | } 1405 | } 1406 | }, 1407 | "utf8": { 1408 | "link": "https://www.lua.org/manual/5.3/manual.html#6.5", 1409 | "description": "This library provides basic support for UTF-8 encoding. It provides all its functions inside the table utf8. This library does not provide any support for Unicode other than the handling of the encoding. Any operation that needs the meaning of a character, such as character classification, is outside its scope.", 1410 | "type": "table", 1411 | "fields": { 1412 | "char": { 1413 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.char", 1414 | "description": "Receives zero or more integers, converts each one to its corresponding UTF-8 byte sequence and returns a string with the concatenation of all these sequences.", 1415 | "type": "function", 1416 | "args": [], 1417 | "argsDisplay": "···" 1418 | }, 1419 | "charpattern": { 1420 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.charpattern", 1421 | "description": "The pattern (a string, not a function) \"[\\0-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*\" (see §6.4.1), which matches exactly one UTF-8 byte sequence, assuming that the subject is a valid UTF-8 string.", 1422 | "type": "unknown" 1423 | }, 1424 | "codepoint": { 1425 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.codepoint", 1426 | "description": "Returns the codepoints (as integers) from all characters in s that start between byte position i and j (both included). The default for i is 1 and for j is i. It raises an error if it meets any invalid byte sequence.", 1427 | "type": "function", 1428 | "args": [ 1429 | { 1430 | "name": "s" 1431 | } 1432 | ], 1433 | "argsDisplay": "s [, i [, j]]" 1434 | }, 1435 | "codes": { 1436 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.codes", 1437 | "description": "Returns values so that the construction", 1438 | "type": "function", 1439 | "args": [ 1440 | { 1441 | "name": "s" 1442 | } 1443 | ], 1444 | "argsDisplay": "s" 1445 | }, 1446 | "len": { 1447 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.len", 1448 | "description": "Returns the number of UTF-8 characters in string s that start between positions i and j (both inclusive). The default for i is 1 and for j is -1. If it finds any invalid byte sequence, returns a false value plus the position of the first invalid byte.", 1449 | "type": "function", 1450 | "args": [ 1451 | { 1452 | "name": "s" 1453 | } 1454 | ], 1455 | "argsDisplay": "s [, i [, j]]" 1456 | }, 1457 | "offset": { 1458 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-utf8.offset", 1459 | "description": "Returns the position (in bytes) where the encoding of the n-th character of s (counting from position i) starts. A negative n gets characters before position i. The default for i is 1 when n is non-negative and #s + 1 otherwise, so that utf8.offset(s, -n) gets the offset of the n-th character from the end of the string. If the specified character is neither in the subject nor right after its end, the function returns nil.", 1460 | "type": "function", 1461 | "args": [ 1462 | { 1463 | "name": "s" 1464 | }, 1465 | { 1466 | "name": "n" 1467 | } 1468 | ], 1469 | "argsDisplay": "s, n [, i]" 1470 | } 1471 | } 1472 | } 1473 | } 1474 | }, 1475 | "namedTypes": { 1476 | "file": { 1477 | "type": "table", 1478 | "fields": {}, 1479 | "metatable": { 1480 | "type": "table", 1481 | "fields": { 1482 | "__index": { 1483 | "type": "table", 1484 | "fields": { 1485 | "close": { 1486 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:close", 1487 | "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.", 1488 | "type": "function", 1489 | "args": [ 1490 | { 1491 | "name": "self" 1492 | } 1493 | ], 1494 | "argsDisplay": "self", 1495 | "argsDisplayOmitSelf": "" 1496 | }, 1497 | "flush": { 1498 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:flush", 1499 | "description": "Saves any written data to file.", 1500 | "type": "function", 1501 | "args": [ 1502 | { 1503 | "name": "self" 1504 | } 1505 | ], 1506 | "argsDisplay": "self", 1507 | "argsDisplayOmitSelf": "" 1508 | }, 1509 | "lines": { 1510 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:lines", 1511 | "description": "Returns an iterator function that, each time it is called, reads the file according to the given formats. When no format is given, uses \"l\" as a default. As an example, the construction", 1512 | "type": "function", 1513 | "args": [ 1514 | { 1515 | "name": "self" 1516 | } 1517 | ], 1518 | "argsDisplay": "self, ···", 1519 | "argsDisplayOmitSelf": "···" 1520 | }, 1521 | "read": { 1522 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:read", 1523 | "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. (In this latter case, the function does not read subsequent formats.) When called without formats, it uses a default format that reads the next line (see below).", 1524 | "type": "function", 1525 | "args": [ 1526 | { 1527 | "name": "self" 1528 | } 1529 | ], 1530 | "argsDisplay": "self, ···", 1531 | "argsDisplayOmitSelf": "···" 1532 | }, 1533 | "seek": { 1534 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:seek", 1535 | "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:", 1536 | "type": "function", 1537 | "args": [ 1538 | { 1539 | "name": "self" 1540 | } 1541 | ], 1542 | "argsDisplay": "self, [whence [, offset]]", 1543 | "argsDisplayOmitSelf": "[whence [, offset]]" 1544 | }, 1545 | "setvbuf": { 1546 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:setvbuf", 1547 | "description": "Sets the buffering mode for an output file. There are three available modes:", 1548 | "type": "function", 1549 | "args": [ 1550 | { 1551 | "name": "self" 1552 | }, 1553 | { 1554 | "name": "mode" 1555 | } 1556 | ], 1557 | "argsDisplay": "self, mode [, size]", 1558 | "argsDisplayOmitSelf": "mode [, size]" 1559 | }, 1560 | "write": { 1561 | "link": "https://www.lua.org/manual/5.3/manual.html#pdf-file:write", 1562 | "description": "Writes the value of each of its arguments to file. The arguments must be strings or numbers.", 1563 | "type": "function", 1564 | "args": [ 1565 | { 1566 | "name": "self" 1567 | } 1568 | ], 1569 | "argsDisplay": "self, ···", 1570 | "argsDisplayOmitSelf": "···" 1571 | } 1572 | } 1573 | } 1574 | } 1575 | } 1576 | } 1577 | } 1578 | } -------------------------------------------------------------------------------- /lib/typedefs.js: -------------------------------------------------------------------------------- 1 | 'use babel' 2 | 3 | /* 4 | * Utility functions for working with type definitions 5 | */ 6 | 7 | import cloneDeepWith from 'lodash.clonedeepwith' 8 | 9 | let tableDiffCount = 0 10 | 11 | export const tableNew = () => ({ 12 | type: 'table', 13 | fields: {} 14 | }) 15 | 16 | export const unknownNew = () => ({ type: 'unknown' }) 17 | export const numberNew = () => ({ type: 'number' }) 18 | export const stringNew = () => ({ type: 'string' }) 19 | export const booleanNew = () => ({ type: 'boolean' }) 20 | export const nilNew = () => ({ type: 'nil' }) 21 | export const functionNew = () => ({ type: 'function' }) 22 | export const tableSet = (table, key, type) => { 23 | if (table.readOnly) { 24 | if (table.diffCount !== tableDiffCount) { 25 | table.diffCount = tableDiffCount 26 | table.extraFields = {} 27 | table.extraMetatable = undefined 28 | } 29 | table.extraFields[key] = type 30 | } else { 31 | table.fields[key] = type 32 | } 33 | } 34 | 35 | export const tableGet = (table, key) => { 36 | if (table.readOnly && table.diffCount === tableDiffCount) { 37 | const extraValue = table.extraFields[key] 38 | if (extraValue !== undefined) { return extraValue } 39 | } 40 | return table.fields[key] 41 | } 42 | 43 | export const tableSetMetatable = (table, metatable) => { 44 | if (table.readOnly) { 45 | if (table.diffCount !== tableDiffCount) { 46 | table.diffCount = tableDiffCount 47 | table.extraFields = {} 48 | } 49 | table.extraMetatable = metatable || null 50 | } else { 51 | table.metatable = metatable 52 | } 53 | } 54 | 55 | export const tableGetMetatable = (table, metatable) => { 56 | if (table.readOnly && table.diffCount === tableDiffCount) { 57 | const extraMetatable = table.extraMetatable 58 | if (extraMetatable !== undefined) { return extraMetatable } 59 | } 60 | return table.metatable 61 | } 62 | 63 | export const tableResolve = (table, field, returnParent) => { 64 | if (!table || table.type !== 'table') { return } 65 | 66 | const value = tableGet(table, field) 67 | if (value) { return returnParent ? table : value } 68 | 69 | const metatable = tableGetMetatable(table) 70 | if (metatable && metatable.type === 'table') { 71 | return tableResolve(tableGet(metatable, '__index'), field, returnParent) 72 | } 73 | } 74 | 75 | export function* tableIterate (table) { 76 | if (!table) { return } 77 | if (!table.readOnly || table.diffCount !== tableDiffCount) { 78 | for (let key in table.fields) { 79 | yield [key, table.fields[key]] 80 | } 81 | } else { 82 | for (let key in table.extraFields) { 83 | yield [key, table.extraFields[key]] 84 | } 85 | for (let key in table.fields) { 86 | if (table.extraFields[key] === undefined) { 87 | yield [key, table.fields[key]] 88 | } 89 | } 90 | } 91 | } 92 | 93 | export const tableSearch = (table, prefix) => { 94 | const results = [] 95 | const search = (table) => { 96 | if (!table || table.type !== 'table') { 97 | return 98 | } 99 | for (let [key, value] of tableIterate(table)) { 100 | if (key.indexOf(prefix) !== 0) { continue } 101 | results.push({ key, typeDef: value }) 102 | } 103 | const metatable = tableGetMetatable(table) 104 | if (metatable && metatable.type === 'table') { 105 | search(tableGet(metatable, '__index')) 106 | } 107 | } 108 | search(table) 109 | return results 110 | } 111 | 112 | const cloneDeepCustomizers = { 113 | table: (value, key) => { 114 | if (key === 'fields') { return {} } 115 | if (key === 'metatable') { return null } 116 | }, 117 | function: (value, key, object, stack) => { 118 | if (key === 'returnTypes') { return [] } 119 | if (key === 'argTypes') { return [] } 120 | } 121 | } 122 | 123 | export function typeDefDeepClone (_typeDef) { 124 | const cache = new Map() 125 | 126 | function _deepClone (typeDef, setter) { 127 | if (typeof typeDef !== 'object') { 128 | return 129 | } 130 | 131 | // Fetch memoized value 132 | const cacheEntry = cache.get(typeDef) 133 | if (cacheEntry) { 134 | if (Array.isArray(cacheEntry)) { 135 | cacheEntry.push(setter) 136 | } else { 137 | setter(cacheEntry) 138 | } 139 | return 140 | } 141 | const setters = [] 142 | cache.set(typeDef, setters) 143 | 144 | // Do the actual cloning 145 | const clone = cloneDeepWith(typeDef, cloneDeepCustomizers[typeDef.type]) 146 | 147 | switch (typeDef.type) { 148 | case 'table': 149 | _deepClone(typeDef.metatable, v => { clone.metatable = v }) 150 | for (let key in typeDef.fields) { 151 | _deepClone(typeDef.fields[key], v => { clone.fields[key] = v }) 152 | } 153 | break 154 | case 'function': 155 | if (typeDef.argTypes) { 156 | typeDef.argTypes.forEach((argType, index) => { 157 | _deepClone(argType, v => { clone.argTypes[index] = v }) 158 | }) 159 | } 160 | if (typeDef.returnTypes) { 161 | typeDef.returnTypes.forEach((retType, index) => { 162 | _deepClone(retType, v => { clone.returnTypes[index] = v }) 163 | }) 164 | } 165 | break 166 | } 167 | 168 | // Memoize and call all pending setters for this object 169 | setters.forEach(s => s(clone)) 170 | cache.set(typeDef, clone) 171 | setter(clone) 172 | } 173 | 174 | let result 175 | _deepClone(_typeDef, r => { result = r }) 176 | return result 177 | } 178 | 179 | export function tableInvalidateDiffs () { 180 | tableDiffCount++ 181 | } 182 | 183 | export function tableFreeze (table) { 184 | if (!table || table.readOnly || table.type !== 'table') { return } 185 | table.readOnly = true 186 | table.extraFields = {} 187 | table.diffCount = tableDiffCount 188 | tableFreeze(table.metatable) 189 | for (let k in table.fields) { 190 | tableFreeze(table.fields[k]) 191 | } 192 | } 193 | 194 | export function tableRevertAndUnfreeze (table) { 195 | if (!table || !table.readOnly || table.type !== 'table') { return } 196 | table.readOnly = false 197 | table.extraFields = undefined 198 | tableRevertAndUnfreeze(table.metatable) 199 | for (let k in table.fields) { 200 | tableRevertAndUnfreeze(table.fields[k]) 201 | } 202 | } 203 | 204 | const typePriority = { 205 | 'nil': 0, 206 | 'unknown': 1, 207 | 'boolean': 2, 208 | 'number': 2, 209 | 'string': 2, 210 | 'userdata': 2, 211 | 'thread': 3, 212 | 'function': 4, 213 | 'table': 5 214 | } 215 | 216 | export function mergeTypeKnowledge (oldType, newType) { 217 | if (oldType === newType) { return oldType } 218 | const oldPriority = typePriority[oldType ? oldType.type : 'nil'] 219 | const newPriority = typePriority[newType ? newType.type : 'nil'] 220 | if (oldPriority === newPriority && newPriority === 5) { // table 221 | for (let [key, newValue] of tableIterate(newType)) { 222 | const oldValue = tableGet(oldType, key) 223 | const mergedValue = mergeTypeKnowledge(oldValue, newValue) 224 | if (mergedValue !== oldValue) { 225 | tableSet(oldType, key, mergedValue) 226 | } 227 | } 228 | const oldValue = tableGetMetatable(oldType) 229 | const newValue = tableGetMetatable(newType) 230 | const mergedValue = mergeTypeKnowledge(oldValue, newValue) 231 | if (mergedValue !== oldValue) { 232 | tableSetMetatable(oldType, mergedValue) 233 | } 234 | } 235 | return newPriority > oldPriority ? newType : oldType 236 | } 237 | 238 | const metatableKey = Symbol() 239 | export function tableDiffShallow (table) { 240 | if (!table || !table.readOnly || table.type !== 'table') { return } 241 | const actual = table.diffCount === tableDiffCount 242 | const extraFields = actual ? table.extraFields : {} 243 | const extraMetatable = actual ? table.extraMetatable : undefined 244 | return { extraFields, extraMetatable, children: [] } 245 | } 246 | 247 | export function tableDiff (table) { 248 | if (!table || !table.readOnly || table.type !== 'table') { return } 249 | const actual = table.diffCount === tableDiffCount 250 | const extraFields = actual ? table.extraFields : {} 251 | const extraMetatable = actual ? table.extraMetatable : undefined 252 | // TODO: Deeply check for changes. Avoid cycles 253 | return { extraFields, extraMetatable, children: [] } 254 | } 255 | 256 | export function tableApplyDiff (table, diff) { 257 | if (!table || !diff || table.type !== 'table') { return } 258 | const { extraFields, extraMetatable, children } = diff 259 | for (let key in extraFields) { 260 | tableSet(table, key, mergeTypeKnowledge(tableGet(table, key), extraFields[key])) 261 | } 262 | if (extraMetatable) { 263 | tableSetMetatable(table, mergeTypeKnowledge(tableGetMetatable(table), extraMetatable)) 264 | } 265 | children.forEach(({ key, childDiff }) => { 266 | const child = key === metatableKey ? tableGetMetatable(table) : tableGet(key) 267 | tableApplyDiff(child, childDiff) 268 | }) 269 | } 270 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autocomplete-lua", 3 | "version": "0.9.2", 4 | "description": "Extensible autocomplete+ provider for Lua", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/dapetcu21/atom-autocomplete-lua.git" 8 | }, 9 | "bugs": { 10 | "url": "https://github.com/dapetcu21/atom-autocomplete-lua/issues" 11 | }, 12 | "main": "lib/index.js", 13 | "configSchema": { 14 | "luaVersion": { 15 | "order": 0, 16 | "type": "string", 17 | "default": "5.2", 18 | "enum": [ 19 | "5.1", 20 | "5.2", 21 | "5.3", 22 | "5.4", 23 | "luajit-2.0" 24 | ], 25 | "title": "Default Lua version", 26 | "description": "Can be overriden in .luacompleterc or by plugins" 27 | }, 28 | "useSnippets": { 29 | "order": 1, 30 | "type": "boolean", 31 | "default": true, 32 | "title": "Suggest snippets", 33 | "description": "Complete functions with snippets of their arguments" 34 | }, 35 | "suggestUsedMembers": { 36 | "order": 2, 37 | "type": "boolean", 38 | "default": true, 39 | "title": "Suggest used table members", 40 | "description": "Suggest table members that you've used in your code as opposed to just those you have explicitly set or defined" 41 | }, 42 | "minCharsPrefix": { 43 | "order": 3, 44 | "type": "integer", 45 | "default": 2, 46 | "minimum": 1, 47 | "title": "Min chars to start completion", 48 | "description": "The minimum number of typed characters required to start a completion" 49 | }, 50 | "completeModules": { 51 | "order": 3.5, 52 | "type": "boolean", 53 | "default": true, 54 | "title": "Complete modules", 55 | "description": "Parse require()-d modules for type information" 56 | }, 57 | "excludeLowerPriority": { 58 | "order": 4, 59 | "type": "boolean", 60 | "default": false, 61 | "title": "Override lower priority providers", 62 | "description": "Disable Atom's default keyword-based autocompletion provider and other lower priority providers" 63 | }, 64 | "inclusionPriority": { 65 | "order": 5, 66 | "type": "integer", 67 | "default": 1, 68 | "minimum": 0, 69 | "title": "Provider inclusion priority", 70 | "description": "Priority relative to other autocomplete providers" 71 | } 72 | }, 73 | "providedServices": { 74 | "autocomplete.provider": { 75 | "versions": { 76 | "2.0.0": "getProvider" 77 | } 78 | }, 79 | "autocomplete-lua.options-provider": { 80 | "versions": { 81 | "1.0.0": "getOptionProviders" 82 | } 83 | } 84 | }, 85 | "consumedServices": { 86 | "autocomplete-lua.options-provider": { 87 | "versions": { 88 | "^1.0.0": "onOptionProviders" 89 | } 90 | } 91 | }, 92 | "author": "", 93 | "license": "MIT", 94 | "engines": { 95 | "atom": "*" 96 | }, 97 | "devDependencies": { 98 | "babel-eslint": "^7.0.0", 99 | "jsdom": "^9.7.1", 100 | "standard": "^8.3.0" 101 | }, 102 | "standard": { 103 | "parser": "babel-eslint", 104 | "globals": [ 105 | "__LOG__" 106 | ] 107 | }, 108 | "dependencies": { 109 | "dapetcu21-luaparse": "^0.2.1", 110 | "jsonic": "^0.3.1", 111 | "lodash.clonedeepwith": "^4.5.0", 112 | "lodash.includes": "^4.3.0" 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /scraper/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | 4 | const jsdom = require('jsdom') 5 | const includes = require('lodash.includes') 6 | const fs = require('fs') 7 | const path = require('path') 8 | const luaVersion = process.argv[2] 9 | const blacklist = ['basic', '_G'] 10 | 11 | if (!luaVersion) { 12 | console.log('usage: node scraper ') 13 | return 14 | } 15 | 16 | const pagesToCrawl = {} 17 | const symbols = [] 18 | function onSymbol (name, link) { 19 | if (includes(blacklist, name)) { return } 20 | const split = link.split('#') 21 | const page = split[0] 22 | const hash = split[1] 23 | 24 | if (!pagesToCrawl[page]) { 25 | pagesToCrawl[page] = [] 26 | } 27 | const symbol = { name, link, page, hash } 28 | pagesToCrawl[page].push(symbol) 29 | symbols.push(symbol) 30 | } 31 | 32 | function unescapeHtml (html) { 33 | return html.replace(/[\s\n]+/g, ' ') 34 | } 35 | 36 | function getFirstParagraph (node) { 37 | while (node && node.textContent.match(/^[\s\n]*$/)) { 38 | node = node.nextSibling 39 | } 40 | 41 | if (!node) { return '' } 42 | 43 | if (node.nodeName === 'P') { 44 | return unescapeHtml(node.textContent) 45 | } 46 | 47 | let text = [] 48 | while (node && !node.nodeName.match(/^(P|H[1-9])$/)) { 49 | text.push(unescapeHtml(node.textContent)) 50 | node = node.nextSibling 51 | } 52 | return text.join('') 53 | } 54 | 55 | function onEnd () { 56 | Promise 57 | .all(Object.keys(pagesToCrawl).map(page => 58 | new Promise((resolve, reject) => { 59 | jsdom.env(page, (err, window) => { 60 | if (err) { reject(err); return } 61 | pagesToCrawl[page].forEach(symbol => { 62 | const a = window.document.getElementsByName(symbol.hash)[0] 63 | symbol.title = a.textContent 64 | const description = getFirstParagraph(a.parentElement.nextSibling).trim() 65 | symbol.description = description.replace(/^\s*|\s*$/g, '') 66 | }) 67 | resolve() 68 | }) 69 | }) 70 | )) 71 | .then(processSymbols) 72 | } 73 | 74 | function processSymbols () { 75 | const options = { 76 | global: { type: 'table', fields: {} }, 77 | namedTypes: {} 78 | } 79 | const _setField = (table, components, value) => { 80 | if (components.length === 1) { 81 | table.fields[components[0]] = value 82 | return 83 | } 84 | let nextTable = table.fields[components[0]] 85 | if (!nextTable) { 86 | nextTable = table.fields[components[0]] = { type: 'table', fields: {} } 87 | } 88 | if (nextTable.type !== 'table') { 89 | nextTable.type = 'table' 90 | nextTable.fields = {} 91 | } 92 | _setField(nextTable, components.slice(1), value) 93 | } 94 | const setField = (name, value) => _setField(options.global, name.split('.'), value) 95 | 96 | const setFieldInNamedType = (base, name, value) => { 97 | let type = options.namedTypes[base] 98 | if (!type) { 99 | type = options.namedTypes[base] = { 100 | type: 'table', 101 | fields: {}, 102 | metatable: { 103 | type: 'table', 104 | fields: { __index: { type: 'table', fields: {} } } 105 | } 106 | } 107 | } 108 | type.metatable.fields.__index.fields[name] = value 109 | } 110 | 111 | symbols.forEach(symbol => { 112 | const nameSplit = symbol.name.split(':') 113 | const hasSelf = nameSplit.length > 1 114 | 115 | const match = symbol.title.match(/\((.*)\)$/) 116 | let type = 'unknown' 117 | let args, argsDisplay, argsDisplayOmitSelf 118 | 119 | if (match) { 120 | type = 'function' 121 | argsDisplay = match[1] 122 | args = argsDisplay 123 | .split('[')[0] 124 | .replace(/[\[\]]/g, '') 125 | .split(',') 126 | .map(s => ({ name: s.replace(/^\s*|\s*$/g, '') })) 127 | .filter(arg => arg.name.replace(/[^a-zA-Z0-9]/g, '').length) 128 | 129 | if (hasSelf) { 130 | argsDisplayOmitSelf = argsDisplay 131 | argsDisplay = argsDisplay ? ('self, ' + argsDisplay) : 'self' 132 | args.splice(0, 0, { name: 'self' }) 133 | } 134 | } 135 | 136 | const typeDef = { 137 | link: symbol.link, 138 | description: symbol.description, 139 | type, 140 | args, 141 | argsDisplay, 142 | argsDisplayOmitSelf 143 | } 144 | 145 | if (hasSelf) { 146 | setFieldInNamedType(nameSplit[0], nameSplit[1], typeDef) 147 | } else { 148 | setField(symbol.name, typeDef) 149 | } 150 | }) 151 | 152 | const io = options.global.fields.io; 153 | (['open', 'popen', 'tmpfile']).forEach(fname => { 154 | io.fields[fname].returnTypes = [{ type: 'ref', name: 'file' }] 155 | }); 156 | (['stdin', 'stdout', 'stderr']).forEach(varname => { 157 | io.fields[varname] = { type: 'ref', name: 'file' } 158 | }) 159 | options.global.fields._VERSION.type = 'string' 160 | options.global.fields.math.fields.pi.type = 'number' 161 | 162 | const filePath = path.join(__dirname, '..', 'lib', 'stdlib', `${luaVersion.replace(/\./g, '_')}.json`) 163 | fs.writeFile(filePath, JSON.stringify(options, null, 2), () => {}) 164 | } 165 | 166 | let parsingFunctions = false 167 | jsdom.env(`http://lua.org/manual/${luaVersion}/`, (err, window) => { 168 | if (err) { 169 | console.log(err) 170 | return 171 | } 172 | 173 | Array.from(window.document.querySelectorAll('h2 + table')).forEach(table => { 174 | Array.from(table.querySelectorAll('td')).forEach(column => { 175 | Array.from(column.children).forEach(element => { 176 | if (element.tagName === 'H3') { 177 | if (!element.textContent.replace(/\s/g, '').length) { return } 178 | parsingFunctions = (element.children[0] && element.children[0].name === 'functions') 179 | return 180 | } 181 | if (!parsingFunctions) { return } 182 | Array.from(element.querySelectorAll('a')).forEach(linkEl => { 183 | const name = linkEl.textContent 184 | const link = linkEl.href 185 | onSymbol(name, link) 186 | }) 187 | }) 188 | }) 189 | }) 190 | 191 | onEnd() 192 | }) 193 | --------------------------------------------------------------------------------