feat: implement list.add() with dynamic growth and add wrenPrintValue helper

Add the `list_add` primitive to support appending elements to lists with automatic capacity management using `LIST_MIN_CAPACITY` and `LIST_GROW_FACTOR` constants. Rename internal `valuesEqual` and `reallocate` functions to `wrenValuesEqual` and `wrenReallocate` for consistent naming, and introduce `wrenPrintValue` to handle formatted output of all value types including lists. Add a test file `test/list_add.wren` verifying basic add operations and return value behavior.
This commit is contained in:
Bob Nystrom
2013-11-27 02:02:10 +00:00
parent 6996f5a48d
commit cd1bd39ce1
6 changed files with 125 additions and 69 deletions
+10
View File
@@ -0,0 +1,10 @@
var a = []
a.add(1)
io.write(a) // expect: [1]
a.add(2)
io.write(a) // expect: [1, 2]
a.add(3)
io.write(a) // expect: [1, 2, 3]
// Returns added element.
io.write(a.add(4)) // expect: 4