Open Lefty-Lex opened 1 year ago
This is a bit out of the scope of this library, but the way to do what you're asking for probably involves writing a lexer / parser that takes lua code and spits out some representation (eg. some tree like an AST) that you can then use to figure out the declared variables (and other code constructs). Lua publishes the grammar of the language as part of its reference manual, and you can use that and either write a lexer / parser by hand (you can find helpful resources online on how to get started with something like that) or use some existing parser generator tool to do it for you (unfortunately you can't use lua's own parser since that's very deeply tied to its execution engine).
To add to what OrfeasZ said above, LuaSrcDiet is a tool for doing all kinds of things with lua like minifying a source file. It is also MIT licenced, so you might be able to use it or parts of it to achieve what you want. For example, you could reuse the parser and lexer from it possibly. It is also pure lua in case that is what you need. (Like I did)
I was wondering if there is any way to get all the variables in a script without running it.
Reason being i am attempting a intellisense - ish feature for my editor and would make life so much easier if i could get the names and type of each variable.