{"library":"luaparse","title":"luaparse","description":"luaparse is a JavaScript-based Lua parser that generates an Abstract Syntax Tree (AST) from Lua source code. Originally developed by Oskar Schöldström for his bachelor's thesis, it supports various Lua versions including '5.1', '5.2', '5.3', and 'LuaJIT'. The current stable version is 0.3.1, primarily a maintenance release addressing issues from 0.3.0. The library offers flexible parsing options, allowing control over comment storage, scope tracking, location and range information, and custom node/scope creation callbacks. It can be used in CommonJS environments, AMD, and directly in browsers via a global `luaparse` object. A key differentiator is its detailed configuration for handling different Lua versions and its comprehensive AST output, including specific options for character encoding interpretation due to the difference between JavaScript's Unicode strings and Lua's bytestrings.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install luaparse"],"cli":null},"imports":["var parser = require('luaparse');","var ast = luaparse.parse('i = 0');","luaparse.defaultOptions.comments = true;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const luaparse = require('luaparse');\n\nconst luaCode = `\n-- This is a simple Lua script\nlocal function greet(name)\n  print(\"Hello, \" .. name .. \"!\")\nend\n\ngreet(\"World\")\n\ni = 0\nwhile i < 3 do\n  i = i + 1\nend\n`;\n\nconst ast = luaparse.parse(luaCode, {\n  comments: true,      // Store comments in the AST\n  locations: true,     // Store location information for each node\n  luaVersion: '5.3'    // Target Lua 5.3 grammar\n});\n\nconsole.log(JSON.stringify(ast, null, 2));\n\n// Example of accessing a specific node type (StringLiteral value change in v0.3.0)\nconst firstStringLiteral = ast.body[0].body[0].args[0].value;\nconsole.log(`First string literal value: ${firstStringLiteral}`);\n","lang":"javascript","description":"Parses a simple Lua script, including comments and location data, and logs the resulting AST. Also demonstrates accessing node properties.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}