从Lua引擎获取所有Lua库和关键字

3
我正在为我的Lua IDE开发代码自动完成控件。
我使用反射来获取可以从脚本中访问的C#对象信息,但我还想在列表中添加Lua特定的内容,比如数学库等。
有没有办法获取这些内容?也想获取所有关键字,例如if、then、end等。
GitHub链接:https://github.com/AndersMalmgren/FreePIE

Visual Studio支持LUA。那为什么我们还需要另一个IDE呢? - Security Hound
1
这是一款定制软件,请在发布前检查URL。 - Anders
1
略微相关 - [Lua中类似于Matlab“whos”命令的等效命令](https://dev59.com/MmLVa4cB1Zd3GeqPsQRQ#9893157) - 您只需要为模块“深入”即可。 - Michal Kottman
1个回答

6

有没有获取这些内容的方法?

这个手册包含了一切,但你也可以在启动时遍历全局命名空间来获取所有内容(你必须在向命名空间添加任何内容之前尽早执行此操作!)。如果某个东西是一个表格,则它也像 字符串表格 一样是一个命名空间,你可以遍历其中的方法。

local exclude = { _G = true, _VERSION = true, arg = true }
for name, value in pairs(_G) do
    if not exclude[name] then
        print(name)
        if type(value) == 'table' then
            for name, value in pairs(value) do
                print('\t', name)
            end
        end
    end
end

产生以下结果:
string
                sub
                upper
                len
                gfind
                rep
                find
                match
                char
                dump
                gmatch
                reverse
                byte
                format
                gsub
                lower
xpcall
package
                preload
                loadlib
                loaded
                loaders
                cpath
                config
                path
                seeall
tostring
print
os
                exit
                setlocale
                date
                getenv
                difftime
                remove
                time
                clock
                tmpname
                rename
                execute
unpack
require
getfenv
setmetatable
next
assert
tonumber
io
                lines
                write
                close
                flush
                open
                output
                type
                read
                stderr
                stdin
                input
                stdout
                popen
                tmpfile
rawequal
collectgarbage
getmetatable
module
rawset
math
                log
                max
                acos
                huge
                ldexp
                pi
                cos
                tanh
                pow
                deg
                tan
                cosh
                sinh
                random
                randomseed
                frexp
                ceil
                floor
                rad
                abs
                sqrt
                modf
                asin
                min
                mod
                fmod
                log10
                atan2
                exp
                sin
                atan
debug
                getupvalue
                debug
                sethook
                getmetatable
                gethook
                setmetatable
                setlocal
                traceback
                setfenv
                getinfo
                setupvalue
                getlocal
                getregistry
                getfenv
pcall
table
                setn
                insert
                getn
                foreachi
                maxn
                foreach
                concat
                sort
                remove
newproxy
type
coroutine
                resume
                yield
                status
                wrap
                create
                running
select
gcinfo
pairs
rawget
loadstring
ipairs
dofile
setfenv
load
error
loadfile

能否获取下一级的参数?内部值不是一个表格,没有这些信息,上面的树结构就没什么用了,谢谢。 - Anders

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接