Skip to content

Commit 8068245

Browse files
committed
Added static method ConVar.get
- Fixed ConVar help text
1 parent 8e9064b commit 8068245

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

addons/source-python/packages/source-python/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@
4848
from _core.settings import _CoreSettingsInstance
4949

5050
# Set the logging level
51-
CConVar('sp_logging_level').set_int(
51+
CConVar.get('sp_logging_level').set_int(
5252
int(_CoreSettingsInstance['LOG_SETTINGS']['level']))
5353

5454
# Set the logging areas
55-
CConVar('sp_logging_areas').set_int(
55+
CConVar.get('sp_logging_areas').set_int(
5656
int(_CoreSettingsInstance['LOG_SETTINGS']['areas']))
5757

5858
# Was an exception raised?
5959
except (ValueError, ConfigObjError):
6060

6161
# Set the logging level to max (5)
62-
CConVar('sp_logging_level').set_int(5)
62+
CConVar.get('sp_logging_level').set_int(5)
6363

6464
# Set the logging area to include console, SP logs, and main log
65-
CConVar('sp_logging_areas').set_int(7)
65+
CConVar.get('sp_logging_areas').set_int(7)
6666

6767
# Import the _SPLogger
6868
from loggers import _SPLogger

addons/source-python/packages/source-python/loggers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ def areas(self):
243243
return self._areas.get_int()
244244

245245
# Set the core ConVars
246-
_level = CConVar(
246+
_level = CConVar.get(
247247
'sp_logging_level', '0', 0, 'The Source.Python base logging level')
248-
_areas = CConVar(
248+
_areas = CConVar.get(
249249
'sp_logging_areas', '1', 0, 'The Source.Python base logging areas')
250250

251251
# Get the Source.Python main LogManager instance

src/core/modules/cvar/cvar_wrap_python.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,28 @@ void export_concommandbase()
189189
class ConVarExt
190190
{
191191
public:
192-
static ConVar* CreateConVar( const char *pName )
192+
static ConVar* Get1(const char* szName)
193193
{
194-
return new ConVar(pName, "");
194+
return Get2(szName, NULL, 0);
195+
}
196+
197+
static ConVar* Get2(const char* szName, const char* szDefaultValue, int flags)
198+
{
199+
return Get3(szName, szDefaultValue, flags, NULL);
200+
}
201+
202+
static ConVar* Get3(const char* szName, const char* szDefaultValue, int flags,
203+
const char* szHelpString)
204+
{
205+
return Get4(szName, szDefaultValue, flags, szHelpString, false, 0, false, 0);
206+
}
207+
208+
static ConVar* Get4(const char* szName, const char* szDefaultValue, int flags,
209+
const char* szHelpString, bool bMin, float fMin, bool bMax, float fMax)
210+
{
211+
ConVar* pConVar = g_pCVar->FindVar(szName);
212+
return pConVar ? pConVar : new ConVar(szName, szDefaultValue, flags,
213+
strdup(szHelpString), bMin, fMin, bMax, fMax);
195214
}
196215

197216
static bool HasMin(ConVar* pConVar)
@@ -229,10 +248,31 @@ class ConVarExt
229248
void export_convar()
230249
{
231250
// TODO: Rename it?
232-
class_<ConVar, bases<ConCommandBase, IConVar>, boost::noncopyable >("CConVar", init<const char *, const char *, optional< int > >())
233-
.def(init<const char *, const char *, int, const char *>())
234-
.def(init<const char *, const char *, int, const char *, bool, float, bool , float>())
235-
.def("__init__", make_constructor(&ConVarExt::CreateConVar))
251+
class_<ConVar, bases<ConCommandBase, IConVar>, boost::noncopyable >("CConVar", no_init)
252+
.def("get",
253+
&ConVarExt::Get1,
254+
"Creates a new server variable. If it already exists, the existing one will be returned.",
255+
reference_existing_object_policy()
256+
)
257+
258+
.def("get",
259+
&ConVarExt::Get2,
260+
"Creates a new server variable. If it already exists, the existing one will be returned.",
261+
reference_existing_object_policy()
262+
)
263+
264+
.def("get",
265+
&ConVarExt::Get3,
266+
"Creates a new server variable. If it already exists, the existing one will be returned.",
267+
reference_existing_object_policy()
268+
)
269+
270+
.def("get",
271+
&ConVarExt::Get4,
272+
"Creates a new server variable. If it already exists, the existing one will be returned.",
273+
reference_existing_object_policy()
274+
)
275+
.staticmethod("get")
236276

237277
.def("get_float",
238278
&ConVar::GetFloat,

0 commit comments

Comments
 (0)