1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Improve debug message and value gen.

This commit is contained in:
Sandu Liviu Catalin 2021-01-31 14:55:49 +02:00
parent 13f5808442
commit 9dab72a2a7
2 changed files with 26 additions and 2 deletions

View File

@ -63,6 +63,7 @@ static void Register_Vector(HSQUIRRELVM vm, Table & ns, const SQChar * name)
.Func(_SC("Generate"), &Container::Generate)
.Func(_SC("GenerateSome"), &Container::GenerateSome)
.Func(_SC("GenerateFrom"), &Container::GenerateFrom)
.Func(_SC("GenerateBetween"), &Container::GenerateBetween)
.Func(_SC("Sort"), &Container::Sort)
.Func(_SC("Shuffle"), &Container::Shuffle)
);

View File

@ -204,7 +204,7 @@ template < class T > struct SqVector
{
if (static_cast< size_t >(i) >= mC->size())
{
STHROWF("Invalid vector container index");
STHROWF("Invalid vector container index(" PRINT_INT_FMT ")", i);
}
return *mC;
}
@ -580,7 +580,7 @@ template < class T > struct SqVector
Validate();
if (static_cast< size_t >(p) >= mC->size())
{
STHROWF("Invalid container index");
STHROWF("Invalid container index (" PRINT_INT_FMT ")", p);
}
for (auto i = static_cast< size_t >(p); n--; ++i)
{
@ -591,6 +591,29 @@ template < class T > struct SqVector
return *this;
}
/* --------------------------------------------------------------------------------------------
* Generate new elements at specified position.
*/
SqVector & GenerateBetween(SQInteger p, SQInteger n, LightObj & ctx, Function & fn)
{
Validate();
if (static_cast< size_t >(p) >= mC->size())
{
STHROWF("Invalid container index (" PRINT_INT_FMT ")", p);
}
else if (static_cast< size_t >(p + n) >= mC->size())
{
STHROWF("Invalid container index (" PRINT_INT_FMT ")", p + n);
}
for (n = (p + n); p <= n; ++p)
{
auto ret = fn.Eval(ctx);
// Extract the value from object and assign it
mC->at(static_cast< size_t >(p)) = ret.Cast< T >();
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Sort the elements from the container.
*/