Skip to content

Commit

Permalink
Fixes towards bool types to make dynamic-test run without conversion …
Browse files Browse the repository at this point in the history
…errors
  • Loading branch information
ntoxin66 committed Mar 19, 2016
1 parent a7b7133 commit 02e2111
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
Binary file modified plugins/disabled/dynamic-example.smx
Binary file not shown.
Binary file modified plugins/disabled/dynamic-test.smx
Binary file not shown.
Binary file modified plugins/dynamic.smx
Binary file not shown.
11 changes: 8 additions & 3 deletions scripting/dynamic-example.sp
Expand Up @@ -97,6 +97,7 @@ public void OnPluginStart()
someobj.HookChanges(OnDynamicMemberChanged);
someobj.SetInt("someint", 256);
someobj.SetFloat("somefloat", -12.04);
someobj.SetBool("somebool", false);
someobj.SetString("somestring", "ye sure moite");

// You MUST! dispose your dynamic objects when your done.
Expand All @@ -114,7 +115,7 @@ public void OnPluginStart()
PrintToServer("myclass.SomeInt = %d;", myclass.SomeInt);
PrintToServer("myclass.SomeFloat = %f;", myclass.SomeFloat);
myclass.GetSomeString(somestring, sizeof(somestring));
PrintToServer("myclass.SomeFloat = %s;", somestring);
PrintToServer("myclass.SomeFloat = '%s';", somestring);
myclass.Dispose();
}

Expand All @@ -125,11 +126,15 @@ public void OnDynamicMemberChanged(Dynamic obj, int offset, const char[] member,
case DynamicType_Int:
{
PrintToServer("[%d] <int>obj.%s = %d", offset, member, obj.GetIntByOffset(offset));
}
}
case DynamicType_Float:
{
PrintToServer("[%d] <float>obj.%s = %f", offset, member, obj.GetFloatByOffset(offset));
}
}
case DynamicType_Bool:
{
PrintToServer("[%d] <bool>obj.%s = %d", offset, member, obj.GetBoolByOffset(offset));
}
case DynamicType_String:
{
char somestring[64];
Expand Down
13 changes: 6 additions & 7 deletions scripting/dynamic-test.sp
Expand Up @@ -158,8 +158,8 @@ stock void BenchmarkTest()
if (someoject.GetFloat(membernames[x]) != fval)
PrintToServer("!! Conversion error (Int2Float)");
if (someoject.GetBool(membernames[x]) != true)
PrintToServer("!! Conversion error (Int2Bool)");

PrintToServer("!! Conversion error (Int2Bool) - (%d != true) - (ival=%d)", someoject.GetBool(membernames[x]), ival);
someoject.GetString(membernames[x], buffer, sizeof(buffer));
IntToString(ival, sval, sizeof(sval));
if (!StrEqual(buffer, sval))
Expand All @@ -173,8 +173,8 @@ stock void BenchmarkTest()
if (someoject.GetInt(membernames[x]) != ival)
PrintToServer("!! Conversion error (FloatToInt)");
if (someoject.GetBool(membernames[x]) != true)
PrintToServer("!! Conversion error (FloatToBool)");

PrintToServer("!! Conversion error (FloatToBool) - (%d != true) - (fval: %f)", someoject.GetBool(membernames[x]), fval);
someoject.GetString(membernames[x], buffer, sizeof(buffer));
FloatToString(fval, sval, sizeof(sval));
if (!StrEqual(buffer, sval))
Expand All @@ -190,11 +190,10 @@ stock void BenchmarkTest()
if (someoject.GetInt(membernames[x]) != 1)
PrintToServer("!! Conversion error (BoolToInt)");


someoject.GetString(membernames[x], buffer, sizeof(buffer));
FloatToString(fval, sval, sizeof(sval));
if (!StrEqual(buffer, "True"))
PrintToServer("!! Conversion error (Bool2String)");
PrintToServer("!! Conversion error (Bool2String) - ('%s' != 'True')", buffer);
x++;
}
else if (p==4)
Expand Down Expand Up @@ -294,7 +293,7 @@ stock void BenchmarkTest()
someoject.GetStringByOffset(offset, buffer, sizeof(buffer));
FloatToString(fval, sval, sizeof(sval));
if (!StrEqual(buffer, "False"))
PrintToServer("!! Conversion error (Bool2String)");
PrintToServer("!! Conversion error (Bool2String) - ('%s' != 'False'", buffer);
x++;
}
else if (p==4)
Expand Down
24 changes: 14 additions & 10 deletions scripting/dynamic.sp
Expand Up @@ -802,9 +802,9 @@ public int Native_Dynamic_GetString(Handle plugin, int params)
else if (type == DynamicType_Bool)
{
if (GetMemberDataInt(data, position, offset, blocksize))
SetNativeString(3, "True", 4);
SetNativeString(3, "True", 5);
else
SetNativeString(3, "False", 5);
SetNativeString(3, "False", 6);
return 1;
}
else
Expand Down Expand Up @@ -938,9 +938,9 @@ public int Native_Dynamic_GetStringByOffset(Handle plugin, int params)
else if (type == DynamicType_Bool)
{
if (GetMemberDataInt(array, position, offset, blocksize))
SetNativeString(3, "True", 4);
SetNativeString(3, "True", 5);
else
SetNativeString(3, "False", 5);
SetNativeString(3, "False", 6);
return 1;
}
else
Expand Down Expand Up @@ -1186,14 +1186,16 @@ public int Native_Dynamic_GetBool(Handle plugin, int params)
int blocksize = GetArrayCell(s_Collection, index, Dynamic_Blocksize);

int position; int offset;
if (!GetMemberOffset(array, index, membername, false, position, offset, blocksize, DynamicType_Int))
if (!GetMemberOffset(array, index, membername, false, position, offset, blocksize, DynamicType_Bool))
return GetNativeCell(3);

Dynamic_MemberType type = GetMemberType(array, position, offset, blocksize);
if (type == DynamicType_Bool || type == DynamicType_Int)
if (type == DynamicType_Bool)
return GetMemberDataInt(array, position, offset, blocksize);
else if (type == DynamicType_Int)
return (GetMemberDataInt(array, position, offset, blocksize) == 0 ? 0 : 1);
else if (type == DynamicType_Float)
return RoundToFloor(GetMemberDataFloat(array, position, offset, blocksize));
return (GetMemberDataFloat(array, position, offset, blocksize) == 0.0 ? 0 : 1);
else if (type == DynamicType_String)
{
int length = GetMemberStringLength(array, position, offset, blocksize);
Expand Down Expand Up @@ -1231,7 +1233,7 @@ public int Native_Dynamic_SetBool(Handle plugin, int params)
int blocksize = GetArrayCell(s_Collection, index, Dynamic_Blocksize);

int position; int offset;
if (!GetMemberOffset(array, index, membername, true, position, offset, blocksize, DynamicType_Int))
if (!GetMemberOffset(array, index, membername, true, position, offset, blocksize, DynamicType_Bool))
return INVALID_DYNAMIC_OFFSET;

Dynamic_MemberType type = GetMemberType(array, position, offset, blocksize);
Expand Down Expand Up @@ -1288,10 +1290,12 @@ public int Native_Dynamic_GetBoolByOffset(Handle plugin, int params)
return GetNativeCell(3);

Dynamic_MemberType type = GetMemberType(array, position, offset, blocksize);
if (type == DynamicType_Bool || type == DynamicType_Int)
if (type == DynamicType_Bool)
return GetMemberDataInt(array, position, offset, blocksize);
else if (type == DynamicType_Int)
return (GetMemberDataInt(array, position, offset, blocksize) == 0 ? 0 : 1);
else if (type == DynamicType_Float)
return RoundToFloor(GetMemberDataFloat(array, position, offset, blocksize));
return (GetMemberDataFloat(array, position, offset, blocksize) == 0.0 ? 0 : 1);
else if (type == DynamicType_String)
{
int length = GetMemberStringLength(array, position, offset, blocksize);
Expand Down

0 comments on commit 02e2111

Please sign in to comment.