Added developer check on script documentation registration

This commit is contained in:
samisalreadytaken 2021-05-10 00:05:08 +03:00
parent 3b51405cac
commit c62d86e340
2 changed files with 71 additions and 6 deletions

View File

@ -33,11 +33,14 @@
#include "tier1/utlbuffer.h"
#include "tier1/mapbase_con_groups.h"
#include "tier1/convar.h"
#include "vscript_squirrel.nut"
#include <cstdarg>
extern ConVar developer;
struct WriteStateMap
{
CUtlMap<void*, int> cache;
@ -1752,6 +1755,9 @@ const char * ScriptDataTypeToName(ScriptDataType_t datatype)
void RegisterDocumentation(HSQUIRRELVM vm, const ScriptFuncDescriptor_t& pFuncDesc, ScriptClassDesc_t* pClassDesc = nullptr)
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
if (pFuncDesc.m_pszDescription && pFuncDesc.m_pszDescription[0] == SCRIPT_HIDE[0])
@ -1791,6 +1797,9 @@ void RegisterDocumentation(HSQUIRRELVM vm, const ScriptFuncDescriptor_t& pFuncDe
void RegisterClassDocumentation(HSQUIRRELVM vm, const ScriptClassDesc_t* pClassDesc)
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
const char *name = pClassDesc->m_pszScriptName;
@ -1823,6 +1832,9 @@ void RegisterClassDocumentation(HSQUIRRELVM vm, const ScriptClassDesc_t* pClassD
void RegisterEnumDocumentation(HSQUIRRELVM vm, const ScriptEnumDesc_t* pClassDesc)
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
if (pClassDesc->m_pszDescription && pClassDesc->m_pszDescription[0] == SCRIPT_HIDE[0])
@ -1840,6 +1852,9 @@ void RegisterEnumDocumentation(HSQUIRRELVM vm, const ScriptEnumDesc_t* pClassDes
void RegisterConstantDocumentation( HSQUIRRELVM vm, const ScriptConstantBinding_t* pConstDesc, const char *pszAsString, ScriptEnumDesc_t* pEnumDesc = nullptr )
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
if (pConstDesc->m_pszDescription && pConstDesc->m_pszDescription[0] == SCRIPT_HIDE[0])
@ -1868,6 +1883,9 @@ void RegisterConstantDocumentation( HSQUIRRELVM vm, const ScriptConstantBinding_
void RegisterHookDocumentation(HSQUIRRELVM vm, const ScriptHook_t* pHook, const ScriptFuncDescriptor_t& pFuncDesc, ScriptClassDesc_t* pClassDesc = nullptr)
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
if (pFuncDesc.m_pszDescription && pFuncDesc.m_pszDescription[0] == SCRIPT_HIDE[0])
@ -1910,6 +1928,9 @@ void RegisterHookDocumentation(HSQUIRRELVM vm, const ScriptHook_t* pHook, const
void RegisterMemberDocumentation(HSQUIRRELVM vm, const ScriptMemberDesc_t& pDesc, ScriptClassDesc_t* pClassDesc = nullptr)
{
if ( !developer.GetInt() )
return;
SquirrelSafeCheck safeCheck(vm);
if (pDesc.m_pszDescription && pDesc.m_pszDescription[0] == SCRIPT_HIDE[0])
@ -1937,6 +1958,12 @@ void RegisterMemberDocumentation(HSQUIRRELVM vm, const ScriptMemberDesc_t& pDesc
CallDocumentationRegisterFunction( 3 );
}
SQInteger GetDeveloperLevel(HSQUIRRELVM vm)
{
sq_pushinteger( vm, developer.GetInt() );
return 1;
}
bool SquirrelVM::Init()
{
@ -2004,6 +2031,11 @@ bool SquirrelVM::Init()
sq_pop(vm_, 1);
}
sq_pushstring( vm_, "developer", -1 );
sq_newclosure( vm_, &GetDeveloperLevel, 0 );
//sq_setnativeclosurename( vm_, -1, "developer" );
sq_newslot( vm_, -3, SQFalse );
sq_pop(vm_, 1);
}

View File

@ -122,14 +122,26 @@ class CSimpleCallChainer
chain = null;
}
local developer = (delete developer)()
__Documentation <- {}
local DocumentedFuncs = {}
local DocumentedClasses = {}
local DocumentedEnums = {}
local DocumentedConsts = {}
local DocumentedHooks = {}
local DocumentedMembers = {}
local DocumentedFuncs
local DocumentedClasses
local DocumentedEnums
local DocumentedConsts
local DocumentedHooks
local DocumentedMembers
if (developer)
{
DocumentedFuncs = {}
DocumentedClasses = {}
DocumentedEnums = {}
DocumentedConsts = {}
DocumentedHooks = {}
DocumentedMembers = {}
}
local function AddAliasedToTable(name, signature, description, table)
{
@ -149,6 +161,9 @@ local function AddAliasedToTable(name, signature, description, table)
function __Documentation::RegisterHelp(name, signature, description)
{
if ( !developer )
return
if (description.len() && description[0] == '#')
{
AddAliasedToTable(name, signature, description, DocumentedFuncs)
@ -161,16 +176,25 @@ function __Documentation::RegisterHelp(name, signature, description)
function __Documentation::RegisterClassHelp(name, baseclass, description)
{
if ( !developer )
return
DocumentedClasses[name] <- [baseclass, description];
}
function __Documentation::RegisterEnumHelp(name, num_elements, description)
{
if ( !developer )
return
DocumentedEnums[name] <- [num_elements, description];
}
function __Documentation::RegisterConstHelp(name, signature, description)
{
if ( !developer )
return
if (description.len() && description[0] == '#')
{
AddAliasedToTable(name, signature, description, DocumentedConsts)
@ -183,11 +207,17 @@ function __Documentation::RegisterConstHelp(name, signature, description)
function __Documentation::RegisterHookHelp(name, signature, description)
{
if ( !developer )
return
DocumentedHooks[name] <- [signature, description];
}
function __Documentation::RegisterMemberHelp(name, signature, description)
{
if ( !developer )
return
DocumentedMembers[name] <- [signature, description];
}
@ -317,6 +347,9 @@ local function PrintMatchesInDocList(pattern, list, printfunc)
function __Documentation::PrintHelp(pattern = "*")
{
if ( !developer )
return
local patternLower = pattern.tolower();
// Have a specific order