ID:2910545
 
Not a bug
BYOND Version:515.1630
Operating System:Windows 10 Home
Web Browser:Firefox 115.0
Applies to:byondapi
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:

When writing to a list with Byond_WriteList, logically false values (null, 0, and the empty string) are not added to the list. Similarly, when writing an assoc value with Byond_WriteListIndex, the assoc value will be set to null if the passed in value is 0 or the empty string, even though those are not strictly null.

Numbered Steps to Reproduce Problem:

1. Have a list in byondapi, be it passed in or created.
2a. Create an array of logically false CByondValues, then pass it into Byond_WriteList.
AND/OR
2b1. Create or otherwise ensure the list contains a valid assoc key.
2b2. Write 0 or the empty string to the valid assoc key with Byond_WriteListIndex
FINALLY
3. If the list was created externally, return it to BYOND.

Code Snippet (if applicable) to Reproduce Problem:
CByondValue list;
ByondValue_CreateList(&list);

CByondValue newListEntries[4];
ByondValue_Clear(&newListEntries[0]);
ByondValue_SetNum(&newListEntries[1], 0.0);
ByondValue_SetStr(&newListEntries[2], "");
ByondValue_SetStr(&newListEntries[3], "foo");

CByondValue foo;
ByondValue_SetStr(&foo, "foo");

CByondValue zero;
ByondValue_SetNum(&zero, 0.0f);

Byond_WriteList(&list, newListEntries, 4);
Byond_WriteListIndex(&list, &foo, &zero);

return list;


Expected Results:
The returned list should be equivalent to list(null, 0, "", "foo" = 0)

Actual Results:
The returned list is equivalent to list("foo")

Does the problem occur:
Every time? Or how often?
Always
In other games?
Not game-specific
In other user accounts?
Not account-specific
On other computers?
Untested

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked?
Older versions that still have byondapi make no mention of changing the behavior of Byond_WriteList or Byond_WriteListIndex. As such, I have no reason to believe this is a regression.

Workarounds:
The inability to append logically false values to a list with Byond_WriteList can be worked around by calling the `Add` proc on lists from byondapi. The inability to assign 0 or the empty string to assoc values cannot be worked around.
Lummox JR changed status to 'Unverified'
I was unable to reproduce any issue. When I ran this code (with the correction to Byond_CreateList()), I got exactly the right list. I would suggest the way you're verifying the list's contents or looping through it is wrong.

json_encode() struggles with this because of the mix of valid associations and numerical values, but this is what I used for my debugging:

mob/verb/Bug2910545()
world.log << "calling bug2910545"
var/list/result = call_ext("dll", "byond:bug2910545_test")()
world.log << "List [length(result)] item\s"
for(var/a in result)
world.log << " [json_encode(a)] => [json_encode(isnum(a) ? null : result[a])]"

I get all the correct entries in the list.
I was able to confirm that this is not a bug with byondapi or with the rust library that wraps it, but rather something off in my own external library code.
Lummox JR resolved issue (Not a bug)