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:
@@ -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
|
||||
Reference in New Issue
Block a user