mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-22 04:37:13 +01:00
Update the constructor binding to take into account new changes made to the overload binding for constructors.
This commit is contained in:
parent
bb73f0a8b5
commit
baee2d5c33
@ -717,37 +717,43 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// constructor binding
|
// constructor binding
|
||||||
Class& BindConstructor(SQFUNCTION method, SQInteger nParams, const SQChar *name = 0) {
|
Class& BindConstructor(SQFUNCTION constructor, SQInteger nParams, const SQChar *name = 0) {
|
||||||
SQFUNCTION overload = SqOverloadFunc(method);
|
SQFUNCTION overload = &OverloadConstructionForwarder;
|
||||||
|
// Decide whether to bind to a class or the root table
|
||||||
bool alternative_global = false;
|
bool alternative_global = false;
|
||||||
if (name == 0)
|
if (name == 0)
|
||||||
name = _SC("constructor");
|
name = _SC("constructor");
|
||||||
else alternative_global = true;
|
else alternative_global = true;
|
||||||
string overloadName = SqOverloadName::Get(name, nParams);
|
// Generate the overload mangled name
|
||||||
|
string overloadName;
|
||||||
|
overloadName.reserve(15);
|
||||||
|
SqOverloadName::Get(name, nParams, overloadName);
|
||||||
|
// Should we push a class object?
|
||||||
if (!alternative_global )
|
if (!alternative_global )
|
||||||
{
|
|
||||||
// push the class
|
|
||||||
sq_pushobject(vm, ClassType<C>::getClassData(vm)->classObj);
|
sq_pushobject(vm, ClassType<C>::getClassData(vm)->classObj);
|
||||||
}
|
// The containing environment is the root table??
|
||||||
else
|
else sq_pushroottable(vm);
|
||||||
{
|
|
||||||
// the containing environment is the root table??
|
|
||||||
sq_pushroottable(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind overload handler
|
// Bind overload handler
|
||||||
sq_pushstring(vm, name, -1);
|
sq_pushstring(vm, name, -1);
|
||||||
sq_pushstring(vm, name, -1); // function name is passed as a free variable
|
// function name is passed as a free variable
|
||||||
|
//sq_pushstring(vm, name, -1);
|
||||||
|
sq_push(vm, -1); // <- Let's cheat(?) by pushing the same object
|
||||||
sq_newclosure(vm, overload, 1);
|
sq_newclosure(vm, overload, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, name);
|
||||||
|
// Include it into the object
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
// Bind overloaded function
|
||||||
// Bind overloaded allocator function
|
sq_pushstring(vm, overloadName.c_str(), static_cast<SQInteger>(overloadName.size()));
|
||||||
sq_pushstring(vm, overloadName.c_str(), -1);
|
sq_newclosure(vm, constructor, 0);
|
||||||
sq_newclosure(vm, method, 0);
|
// Set the closure name (for debug purposes)
|
||||||
sq_setparamscheck(vm,nParams + 1,NULL);
|
sq_setnativeclosurename(vm, -1, overloadName.c_str());
|
||||||
|
// Include it into the object
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
// pop object/environment
|
||||||
sq_pop(vm, 1);
|
sq_pop(vm, 1);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,7 +559,7 @@ protected:
|
|||||||
string overloadName;
|
string overloadName;
|
||||||
overloadName.reserve(15);
|
overloadName.reserve(15);
|
||||||
SqOverloadName::Get(name, argCount, overloadName);
|
SqOverloadName::Get(name, argCount, overloadName);
|
||||||
|
// Push object/environment
|
||||||
sq_pushobject(vm, GetObject());
|
sq_pushobject(vm, GetObject());
|
||||||
|
|
||||||
// Bind overload handler
|
// Bind overload handler
|
||||||
@ -583,8 +583,8 @@ protected:
|
|||||||
sq_setnativeclosurename(vm, -1, overloadName.c_str());
|
sq_setnativeclosurename(vm, -1, overloadName.c_str());
|
||||||
// Include it into the object
|
// Include it into the object
|
||||||
sq_newslot(vm, -3, staticVar);
|
sq_newslot(vm, -3, staticVar);
|
||||||
|
// pop object/environment
|
||||||
sq_pop(vm,1); // pop object
|
sq_pop(vm, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the value of a variable on the object. Changes to values set this way are not reciprocated
|
// Set the value of a variable on the object. Changes to values set this way are not reciprocated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user