ByondValue_GetRef returns the ID of a valid ref, and 0 for an invalid ref. The world, and the first-ever object of a given ref type to be instantiated, both have an ID of 0. This results in ambiguity. Given how many reference-counted objects the typical BYOND game uses, this is an extremely niche edge case, but I believe it should be addressed nevertheless.
Numbered Steps to Reproduce Problem:
1. Pass a non-reference type (e.g. a number) to ByondValue_GetRef.
2. Pass the first-ever datum/area/turf/obj/mob to be created since world creation to ByondValue_GetRef.
3. Compare the two return values.
Code Snippet (if applicable) to Reproduce Problem:
DM:
world/New()
world.log << call_ext("external_lib", "byond:compare")(1, new/obj())
C++:
#include <byondapi.h>
#include <byondapi_cpp_wrappers.h>
extern "C" BYOND_EXPORT CByondValue compare(int n, ByondValue arg[])
{
ByondValue ret;
if(arg[0].get_ref() == arg[1].get_ref)
{
ret = 1.0f;
}
else
{
ret = 0.0f;
}
return ret;
}
Expected Results:
The two return values should not be equal
Actual Results:
The two return values are equal
Also the code snippet included is incorrect, since the C++ wrappers don't define any function called get_ref(); the actual function is ByondValue::GetRef(). This code won't compile as-is.