@@ -189,30 +189,40 @@ void export_concommandbase()
189189class ConVarExt
190190{
191191public:
192- static ConVar* Get1 ( const char * szName)
192+ static ConVar* New1 (PyObject* cls, const char * szName)
193193 {
194- return Get2 ( szName, NULL , 0 );
194+ return New2 (cls, szName, NULL , 0 );
195195 }
196196
197- static ConVar* Get2 ( const char * szName, const char * szDefaultValue, int flags)
197+ static ConVar* New2 (PyObject* cls, const char * szName, const char * szDefaultValue, int flags)
198198 {
199- return Get3 ( szName, szDefaultValue, flags, NULL );
199+ return New3 (cls, szName, szDefaultValue, flags, NULL );
200200 }
201201
202- static ConVar* Get3 ( const char * szName, const char * szDefaultValue, int flags,
202+ static ConVar* New3 (PyObject* cls, const char * szName, const char * szDefaultValue, int flags,
203203 const char * szHelpString)
204204 {
205- return Get4 ( szName, szDefaultValue, flags, szHelpString, false , 0 , false , 0 );
205+ return New4 (cls, szName, szDefaultValue, flags, szHelpString, false , 0 , false , 0 );
206206 }
207207
208- static ConVar* Get4 ( const char * szName, const char * szDefaultValue, int flags,
208+ static ConVar* New4 (PyObject* cls, const char * szName, const char * szDefaultValue, int flags,
209209 const char * szHelpString, bool bMin, float fMin , bool bMax, float fMax )
210210 {
211211 ConVar* pConVar = g_pCVar->FindVar (szName);
212212 return pConVar ? pConVar : new ConVar (szName, szDefaultValue, flags,
213213 strdup (szHelpString), bMin, fMin , bMax, fMax );
214214 }
215215
216+ static object __init__ (tuple args, dict kw)
217+ {
218+ // This method accepts unlimited arguments and keywords, because
219+ // I don't want to write a method for each constructor.
220+
221+ // We cannot use a "void" function here, because raw_function()
222+ // requires the method to return an object.
223+ return object ();
224+ }
225+
216226 static bool HasMin (ConVar* pConVar)
217227 {
218228 float fMin ;
@@ -249,30 +259,33 @@ void export_convar()
249259{
250260 // TODO: Rename it?
251261 class_<ConVar, bases<ConCommandBase, IConVar>, boost::noncopyable >(" CConVar" , no_init)
252- .def (" get" ,
253- &ConVarExt::Get1,
262+ // We have to overload __init__. Otherwise we would get an error because of "no_init"
263+ .def (" __init__" , raw_function (&ConVarExt::__init__))
264+
265+ // Add constructors
266+ .def (" __new__" ,
267+ &ConVarExt::New1,
254268 " Creates a new server variable. If it already exists, the existing one will be returned." ,
255269 reference_existing_object_policy ()
256270 )
257271
258- .def (" get " ,
259- &ConVarExt::Get2 ,
272+ .def (" __new__ " ,
273+ &ConVarExt::New2 ,
260274 " Creates a new server variable. If it already exists, the existing one will be returned." ,
261275 reference_existing_object_policy ()
262276 )
263277
264- .def (" get " ,
265- &ConVarExt::Get3 ,
278+ .def (" __new__ " ,
279+ &ConVarExt::New3 ,
266280 " Creates a new server variable. If it already exists, the existing one will be returned." ,
267281 reference_existing_object_policy ()
268282 )
269283
270- .def (" get " ,
271- &ConVarExt::Get4 ,
284+ .def (" __new__ " ,
285+ &ConVarExt::New4 ,
272286 " Creates a new server variable. If it already exists, the existing one will be returned." ,
273287 reference_existing_object_policy ()
274288 )
275- .staticmethod (" get" )
276289
277290 .def (" get_float" ,
278291 &ConVar::GetFloat,
0 commit comments