feat: add toString method for numbers and strings with AS_NUM/AS_STRING macros

Introduce num_toString primitive that converts numeric values to string representation via sprintf with "%g" format, and add AS_NUM and AS_STRING accessor macros to vm.h for cleaner type extraction. Refactor existing numeric and string primitives to use these macros instead of direct struct member access. Include test files for number_toString and string_toString with basic equality checks (skipped due to unimplemented == operator).
This commit is contained in:
Bob Nystrom
2013-11-02 06:27:28 +00:00
parent 8ff3684cbd
commit ffc04e97f7
4 changed files with 50 additions and 15 deletions
+7
View File
@@ -0,0 +1,7 @@
// skip: == not implemented yet
io.write(123.toString == "123") // expect: true
io.write(-123.toString == "-123") // expect: true
io.write(-0.toString == "0") // expect: true
// TODO(bob): Floating point numbers.
+4
View File
@@ -0,0 +1,4 @@
// skip: == not implemented yet
io.write("".toString == "") // expect: true
io.write("blah".toString == "blah") // expect: true