打开/关闭搜索
搜索
打开/关闭菜单
17
78
34
2.1K
INFWiki
导航
百科首页
最近更改
随机页面
特殊页面
上传文件
人气页面
入服指南
回响地标
百科创作
介绍
语法
打开/关闭外观设置菜单
notifications
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
登录
查看“︁模块:Module toc”︁的源代码
来自INFWiki
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
Module toc
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
-- Imported from: https://runescape.wiki/w/Module:Module%20toc -- <nowiki> local p = {} local function getNewlineLocations( content ) local locs = {} local pos = 0 repeat pos = string.find( content, '\n', pos + 1, true ) table.insert( locs, pos ) until not pos return locs end local function findLineNumber( pos, newLineLocs ) local max = #newLineLocs local min = 1 repeat local i = math.ceil( (max + min) / 2 ) if newLineLocs[i] < pos then min = i elseif newLineLocs[i] >= pos then max = i end until newLineLocs[i] > pos and (newLineLocs[i - 1] or 0) < pos return max end local function getFunctionLocations( content ) local locs = {} local newLineLocs = getNewlineLocations( content ) local start = 0 repeat local name name, start = string.match( content, '%sfunction%s+([^%s%(]+)%s*%(()', start + 1 ) if start then table.insert( locs, { name=name, line = findLineNumber( start, newLineLocs ) } ) end until not start start = 0 repeat local name name, start = string.match( content, '%s([^%s=])%s*=%s*function%s*%(()', start + 1 ) if start then table.insert( locs, { name=name, line = findLineNumber( start, newLineLocs ) } ) end until not start return locs end function p.main() local title = mw.title.getCurrentTitle() local moduleName = string.gsub( title.text, '/[Dd]oc$', '' ) if not title:inNamespaces( 828 ) then return '' end local fullModuleName = string.gsub( title.fullText, '/[Dd]oc$', '' ) local content = mw.title.new( fullModuleName ):getContent() if not content then return '' end local function substMutilineComment( match ) local lineCount = #getNewlineLocations( match ) return string.rep( '\n', lineCount ) or '' end content = content:gsub( '(%-%-%[(=-)%[.-%]%2%])', substMutilineComment ):gsub( '%-%-[^\n]*', '' ) -- Strip comments local functionLocs = getFunctionLocations( content ) table.sort( functionLocs, function(lhs, rhs) return lhs.line < rhs.line end ) if #functionLocs == 0 then return '' end local res = {} for _, func in ipairs( functionLocs ) do table.insert( res, string.format( 'L %d — [%s#L-%d %s]', func.line, title:fullUrl():gsub( '/[Dd]oc$', '' ), func.line, func.name ) ) end local tbl = mw.html.create( 'table' ):addClass( 'wikitable mw-collapsible mw-collapsed' ) tbl:tag( 'tr' ) :tag( 'th' ):wikitext( 'Function list' ):done() :tag( 'tr' ) :tag( 'td' ):wikitext( table.concat( res, '<br>' ) ) return tostring( tbl ) end return p -- </nowiki>
该页面使用的模板:
Module toc/doc
(
查看源代码
)
返回
Module toc
。
查看“︁模块:Module toc”︁的源代码
来自INFWiki