Skip to content

Commit aba5828

Browse files
authored
Merge pull request mapbase-source#171 from samisalreadytaken/docsort
Add vscript documentation sorting
2 parents 4ac26f2 + 9c51012 commit aba5828

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

sp/src/vscript/vscript_squirrel.nut

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
static char g_Script_vscript_squirrel[] = R"vscript(
22
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
33
//
4-
// Purpose:
5-
//
4+
// Purpose:
5+
//
66
//=============================================================================//
77
88
Warning <- error;
@@ -452,20 +452,28 @@ if (developer)
452452
printdocl(text);
453453
}
454454

455-
local function PrintMatchesInDocList(pattern, list, printfunc)
455+
local function PrintMatches( pattern, docs, printfunc )
456456
{
457-
local foundMatches = 0;
457+
local matches = [];
458+
local always = pattern == "*";
458459

459-
foreach(name, doc in list)
460+
foreach( name, doc in docs )
460461
{
461-
if (pattern == "*" || name.tolower().find(pattern) != null || (doc[1].len() && doc[1].tolower().find(pattern) != null))
462+
if (always || name.tolower().find(pattern) != null || (doc[1].len() && doc[1].tolower().find(pattern) != null))
462463
{
463-
foundMatches = 1;
464-
printfunc(name, doc)
464+
matches.append( name );
465465
}
466466
}
467467

468-
return foundMatches;
468+
if ( !matches.len() )
469+
return 0;
470+
471+
matches.sort();
472+
473+
foreach( name in matches )
474+
printfunc( name, docs[name] );
475+
476+
return 1;
469477
}
470478

471479
function __Documentation::PrintHelp(pattern = "*")
@@ -474,12 +482,12 @@ if (developer)
474482

475483
// Have a specific order
476484
if (!(
477-
PrintMatchesInDocList( patternLower, DocumentedEnums, PrintEnum ) |
478-
PrintMatchesInDocList( patternLower, DocumentedConsts, PrintConst ) |
479-
PrintMatchesInDocList( patternLower, DocumentedClasses, PrintClass ) |
480-
PrintMatchesInDocList( patternLower, DocumentedFuncs, PrintFunc ) |
481-
PrintMatchesInDocList( patternLower, DocumentedMembers, PrintMember ) |
482-
PrintMatchesInDocList( patternLower, DocumentedHooks, PrintHook )
485+
PrintMatches( patternLower, DocumentedEnums, PrintEnum ) |
486+
PrintMatches( patternLower, DocumentedConsts, PrintConst ) |
487+
PrintMatches( patternLower, DocumentedClasses, PrintClass ) |
488+
PrintMatches( patternLower, DocumentedFuncs, PrintFunc ) |
489+
PrintMatches( patternLower, DocumentedMembers, PrintMember ) |
490+
PrintMatches( patternLower, DocumentedHooks, PrintHook )
483491
))
484492
{
485493
printdocl("Pattern " + pattern + " not found");
@@ -503,7 +511,6 @@ else
503511

504512
if (developer)
505513
{
506-
// Vector documentation
507514
__Documentation.RegisterClassHelp( "Vector", "", "Basic 3-float Vector class." );
508515
__Documentation.RegisterHelp( "Vector::Length", "float Vector::Length()", "Return the vector's length." );
509516
__Documentation.RegisterHelp( "Vector::LengthSqr", "float Vector::LengthSqr()", "Return the vector's squared length." );

0 commit comments

Comments
 (0)